human
I am working on the file "DEEP LEARNING/Pytorch from scratch/TODO/GAN/gan-mnist/MNIST_GAN_Solution.ipynb".
The first task is:
Generator
The generator network will be almost exactly the same as the discriminator network, except that we're applying a tanh activation function to our output layer.
tanh Output
The generator has been found to perform the best with $tanh$ for the generator output, which scales the output to be between -1 and 1, instead of 0 and 1. 
<img src='assets/tanh_fn.png' width=40% />
Recall that we also want these outputs to be comparable to the real input pixel values, which are read in as normalized values between 0 and 1. 

So, we'll also have to scale our real input images to have pixel values between -1 and 1 when we train the discriminator. 

I'll do this in the training loop, later on.
Can you write Python code for it?
assistant
#Here is the Python code you requested.

class Generator(nn.Module):

    def __init__(self, input_size, hidden_dim, output_size):
        super(Generator, self).__init__()
        
        # define hidden linear layers
        self.fc1 = nn.Linear(input_size, hidden_dim)
        self.fc2 = nn.Linear(hidden_dim, hidden_dim*2)
        self.fc3 = nn.Linear(hidden_dim*2, hidden_dim*4)
        
        # final fully-connected layer
        self.fc4 = nn.Linear(hidden_dim*4, output_size)
        
        # dropout layer 
        self.dropout = nn.Dropout(0.3)

    def forward(self, x):
        # all hidden layers
        x = F.leaky_relu(self.fc1(x), 0.2) # (input, negative_slope=0.2)
        x = self.dropout(x)
        x = F.leaky_relu(self.fc2(x), 0.2)
        x = self.dropout(x)
        x = F.leaky_relu(self.fc3(x), 0.2)
        x = self.dropout(x)
        # final layer with tanh applied
        out = F.tanh(self.fc4(x))

        return out