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

Connected

Exercise

Training a GAN model

Your team at PyBooks has made good progress in building the text generator using a Generative Adversarial Network (GAN). You have successfully defined the generator and discriminator networks. Now, it's time to train them. The final step is to generate some fake data and compare it with the real data to see how well your GAN has learned. We have used tensors as an input and the output would try to resemble the input tensors. The team at PyBooks can then use this synthetic data for text analysis as the features will have same relationship as text data.

The generator and discriminator have been initialized and saved to generator and discriminator, respectively.

The following variables have been initialized in the exercise:

  • seq_length = 5: Length of each synthetic data sequence
  • num_sequences = 100: Total number of sequences generated
  • num_epochs = 50: Number of complete passes through the dataset
  • print_every = 10: Output display frequency, showing results every 10 epochs

Instructions 1/3

undefined XP
    1
    2
    3
  • Define the loss function for binary classification and the Adam optimizer.
  • Train the discriminator by unsqueezing real_data and preventing gradient recalculations.