I’ve built a very simple RNN.  I found an issue where outputs is generating nonsense. I was debugging it and found that my rnn output is generating the same exact output for each item in the minibatch.  Can anyone tell me if Im doing something wrong with my code? I have looked at this code over a few times and I cant find where the error is being introduced. can anyone give me an idea of how to debug this?


class MyRNN(nn.Module):
def init(self, embed_size, hidden_size, vocab_size, num_layers):
super(MyRNN, self).init()
self.embed = nn.Embedding(vocab_size, embed_size)
self.lstm = nn.LSTM(embed_size, hidden_size, num_layers, batch_first=True)
self.linear = nn.Linear(hidden_size,4800)
self.init_weights()
def init_weights(self):
""“Initialize weights.”""
self.embed.weight.data.uniform_(-0.1, 0.1)
self.linear.weight.data.uniform_(-0.1, 0.1)
self.linear.bias.data.fill_(0)
def forward(self,captions, lengths):
embeddings = self.embed(captions)
packed = pack_padded_sequence(embeddings, lengths, batch_first=True)
rnn_features, (hidden,_) = self.lstm(packed)
outputs = self.classifier(rnn_features[0])
return outputs