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

Connected

Exercise

Train a CNN model for text

Well done defining the TextClassificationCNN class. PyBooks now needs to train the model to optimize it for accurate sentiment analysis of book reviews.

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
  • Define a loss function used for binary classification and save as criterion.
  • Zero the gradients at the start of the training loop.
  • Update the parameters at the end of the loop.