1. Learn
  2. /
  3. Courses
  4. /
  5. Deep Learning for Text with PyTorch

Exercise

Testing the Sentiment Analysis CNN Model

Now that model is trained, PyBooks wants to check its performance on some new book reviews.

You need to check if the sentiment in a review is positive or negative.

The following packages have been imported for you: torch, torch.nn as nn, torch.nn.functional as F, torch.optim as optim.

An instance of TextClassificationCNN() with arguments vocab_size and embed_dim has also been loaded and saved as model.

Instructions

100 XP
  • Iterate over the book_reviews list, converting the words in each review into a tensor.
  • Get the model's output for each input_tensor.
  • Find the index of the most likely sentiment category from the outputs.data.
  • Extract and convert the predicted_label item into a sentiment string where 1 is a "Positive" label.