Session Ready
Exercise

Sentiment analysis

In the video exercise, you were exposed to the various applications of sequence to sequence models. In this exercise you will see how to use a pre-trained model for sentiment analysis.

The model is pre-loaded in the environment on variable model. Also, the tokenized test set variables X_test and y_test and the pre-processed original text data sentences from IMDb are also available.You will learn how to pre-process the text data and how to create and train the model using Keras later in the course.

You will use the pre-trained model to obtain predictions of sentiment. The model returns a number between zero and one representing the probability of the sentence to have a positive sentiment. So, you will create a decision rule to set the prediction to positive or negative.

Instructions
100 XP
  • Use the .predict() method to make predictions on the test data.
  • Make the prediction equal to "positive" if its value is greater than 0.5 and "negative" otherwise and store the result in the pred_sentiment variable.
  • Create a pd.DataFrame containing the pre-processed text, the prediction obtained in the previous step and their true values contained in the y_test variable.
  • Print the first rows using the .head() method.