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

Exercise

Building a generator and discriminator

At PyBooks, you're tasked with working on an automatic text generator to help writers overcome writer's block. By using GANs, or Generative Adversarial Networks, you believe you can create a system where one network, the generator, creates new text while the other network, the discriminator, evaluates its authenticity. To do this, you need to initialize both a generator and discriminator network. These networks will then be trained against each other to create new, believable text.

The following has been imported for you: torch, torch.nn as nn.

Instructions

100 XP
  • Define the Generator class with a linear layer for sequential data and a sigmoid activation function.
  • Pass the input through the defined model in the forward() method of the Generator class.
  • Define a Discriminator class with the same layers and activation function, taking care when defining the dimensions.