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
.
Este exercício faz parte do curso
Deep Learning for Text with PyTorch
Instruções do exercício
- 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 theGenerator
class. - Define a
Discriminator
class with the same layers and activation function, taking care when defining the dimensions.
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
# Define the generator class
class Generator(nn.Module):
def __init__(self):
super().__init__()
self.model = nn.____(nn.____(____), nn.____())
def forward(self, x):
return self.____(x)
# Define the discriminator networks
class Discriminator(nn.Module):
def __init__(self):
super().__init__()
self.model = nn.____(nn.____(____), nn.____())
def forward(self, x):
return self.model(x)