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

Connected

Exercise

Text generation using RNN - Training and Generation

The team at PyBooks now wants you to train and test the RNN model, which is designed to predict the next character in the sequence based on the provided input for auto-completion of book names. This project will help the team further develop models for text completion.

The model instance for the RNNmodel class is preloaded for you. The data variable has been preprocessed and encoded as a sequence.

The inputs and targets variable are preloaded for you.

Instructions

100 XP
  • Instantiate the loss function which will be used to compute the error of our model.
  • Instantiate the optimizer from PyTorch's optimization module.
  • Run the model training process by setting the model to the train mode and zeroing the gradients before performing an optimization step.
  • After the training process, switch the model to evaluation mode to test it on a sample input.