Analyzing the sentiment in specific sentences
Now, let's take a look at some predicted samples from the test set:
import tensorflow as tf tf.get_logger().setLevel('ERROR') def get_sentiment(val): Â Â Â Â return "Positive" if val == 1 else "Negative" for i in range(10): Â Â Â Â print(x_test[i]) Â Â Â Â print("label: %s, prediction: %s" % (get_sentiment(y_test[i][0]), get_sentiment(clf.predict(x_test[i:i+1])[0][0])))
Here is the output of the preceding code:
Figure 7.6 – Some predictions based on the first 10 sentences of the test dataset
As you can see, the model predictions match every label for the first 10 samples in the test dataset.