I am trying to get a LSTM autoencoder to recreate its inputs. So far I have:
class getSequence(nn.Module):
def forward(self, x):
out, _ = x
return out
class getLast(nn.Module):
def forward(self, x):
out, states = x
states = states[len(states) - 1]
return states
class AEncoder(nn.Module):
def __init__(self, input_size, first_layer, second_layer, n_layers):
super(AEncoder, self).__init__()
self.n_layers = n_layers
self.encode = nn.Sequential(nn.LSTM(input_size, first_layer, batch_first=True),
getSequence(),
nn.ReLU(True),
nn.LSTM(first_layer, second_layer),
getLast())
self.decode = nn.Sequential(nn.LSTM(second_layer, first_layer),
getSequence(),
nn.ReLU(True),
nn.LSTM(first_layer, input_size),
getSequence())
def forward(self, x):
x = x.float()
x = self.encode(x)
x = x.repeat(32, 1, 1) # repeating last hidden state of self.encode
x = self.decode(x)
return x
While researching I have been seeing some people adding a time-distributed dense layer at the end of the self.decode. I am confused if that final layer is specific to other tasks autoencoders are used for, if so, can I ignore that layer if I am only trying to recreate inputs?
