human
I am working on the file "Sessions/Session14/Day3/AutoencodersBlank.ipynb".
The first task is:
Problem 1b.
Split the training and test set with a 66/33 split.
Problem 2: Understanding the Autoencoder
Below is sample of an autoencoder, built in Pytorch. Describe the code line-by-line with a partner. Add another hidden layer before and after the encoded (latent) layer (this will be a total of 2 new layers). Choose the appropriate activation function for this regression problem. Make all of the activation functions the same.
Can you write Python code for it?
assistant
#Here is the Python code you requested.

class Autoencoder(torch.nn.Module):
      # this defines the model
        def __init__(self, input_size, hidden_size, hidden_inner, encoded_size):
            super(Autoencoder, self).__init__()
            print(input_size,hidden_size,encoded_size)
            self.input_size = input_size
            self.hidden_size  = hidden_size
            self.encoded_size = encoded_size
            self.hidden_inner = hidden_inner
            self.hiddenlayer1 = torch.nn.Linear(self.input_size, self.hidden_size)
            # ADD A LAYER HERE
            self.encodedlayer = torch.nn.Linear(self.hidden_inner, self.encoded_size)
            self.hiddenlayer3 = torch.nn.Linear(self.encoded_size, self.hidden_inner)
            # ADD A LAYER HERE
            self.outputlayer = torch.nn.Linear(self.hidden_size, self.input_size)
            # some nonlinear options
            self.sigmoid = torch.nn.Sigmoid()
            self.softmax = torch.nn.Softmax()
            self.relu = torch.nn.ReLU()
        def forward(self, x):
            layer1 = self.hiddenlayer1(x)
            activation1 = self.ACTIVATION?(layer1)
            layer2 = self.hiddenlayer2(activation1)
            activation2 = self.ACTIVATION?(layer2)
            layer3 = self.encodedlayer(activation2)
            activation3 = self.ACTIVATION?(layer3)
            layer4 = self.hiddenlayer3(activation3)
            activation4 = self.ACTIVATION?(layer4)
            layer5 = self.hiddenlayer4(activation4)
            activation5 = self.ACTIVATION?(layer5)
            layer6 = self.outputlayer(activation5)
            output = self.ACTIVATION?(layer6)

            # Why do I have two outputs?
            return output, layer3