Same output for entire batch

Unity05: <pre><code class="lang-auto">class FinalDecoder(nn.Module):
    def __init__(self, input_size, hidden_size, output_size):
        super(FinalDecoder, self).__init__()

        self.hidden_size = hidden_size

        self.gru = nn.GRU(input_size=input_size, hidden_size=hidden_size, batch_first=False)
        self.fc_0 = nn.Linear(in_features=hidden_size, out_features=output_size, bias=True)
        self.relu = nn.ReLU()
        self.log_softmax = nn.LogSoftmax(dim=2)

    def forward(self, x, hidden):
        output, hidden = self.gru(x, hidden)
        output = output.transpose(1, 0)

        output = hidden

        output = self.fc_0(output)
        output = self.relu(output)
        output = self.log_softmax(output)

        return output, hidden

    def init_hidden(self, n_words):
        return torch.zeros(1, n_words, self.hidden_size)
</code></pre>
<p><strong>Input</strong><br>
A ‘word tensor’ of shape <code>(n_max_chars, n_words, 29)</code>, what is actually the padded output of my previous model.</p>
<pre><code class="lang-auto">hidden = self.decoder.init_hidden(n_words=word_tensors.shape[1]).to(self.device)
output, hidden = self.decoder(x=word_tensors, hidden=hidden)
</code></pre>
<p><strong>Output</strong><br>
Another ‘word tensor’ of shape <code>(n_words, 1, |vocabulary|)</code>, which is supposed to return the word index given the char probability sequence as the input.<br>
The predictions tend to converge to one value, except for the two upper ones, they somehow almost always assume another value.</p>
<pre><code class="lang-auto">Predicted indices: tensor([[9895],
        [9895],
        [9895],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191],
        [8191]], device='cuda:0')
</code></pre>
<p><strong>Additional Information</strong><br>
As the <code>n_words</code> basically represents the batch size, the batch size is pretty big (around 100). Therefore I tend do use a slightly high learning rate. I have, however; also tried multiple different values as this seems to be a ‘mean prediction’, but even a very small one (e.g. 1.0e-5) or a even bigger one produced the same result.<br>
I use the Adam optimizer.<br>
I’ve tried different loss functions. First I tried CTCLoss, as it is pretty dynamic. Therefore perfect for my use case, where predictions and targets almost never have the same length (at least at the beginning). I have some concerns about this, as it is meant to be used for kind of word wise classification, and my predictions won’t ever contain the blank label, but in my understanding of the CTCLoss, this should not be a problem. However, I have also tried CrossEntropy / LogSigmoid + NLLLoss.<br>
Thanks for help in advance.</p>
<p>EDIT: the loss decreases while the output stays the same. Looks like the model likes to cheat.</p>
<p>[<strong>Padding (Nope)</strong><br>
After looking at some more logs, I’m pretty convinced that the problem is somehow caused by the padding. Padding is done by pad_sequence, padding the different ‘word tensors’ together. so that they all have the same ‘char probability length’.]</p>
<p>Regards,<br>
Unity05</p>