Using a trained model

Alternatively, and perhaps more interestingly, we can use a trained model to predict sentiment. We can train our model in a larger corpus and then simply apply it online to the new examples that come.

First, let's load our model and the vector embedding that we trained before for the movie reviews:

wv <- read.csv("./data/wv.csv")
model <- load_model_hdf5("glove_nn.hdf5")

As before, we join the vector representations with the data in tidy form:

df <- wv%>% inner_join(text_df)

And take the average of those vectors per Tweet as the embedded representation of our Tweet:

df <- df %>% group_by(tweet_id) %>% summarize_all(mean) %>% select(1:51) 
preds <- model %>% predict(as.matrix(df[,2:51]))
hist(preds[,1])

As we structured our model, we will get predicted probabilities for each class. This is shown in the histogram as follows:

Distribution of predicted class (i.e. sentiment) probabilities

So, this is roughly the same distribution as before (recall that before we had no probabilities, but we inferred the sentiment directly). This is a good sign that the model might be doing the right things, but as always, it is better to take a look directly at the data. 

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset