NLLoss() doesn’t know about seq_length, and the following would cause an error:
hidden = model.initial_hidden()
output, hidden = model(input, hidden)
loss = loss_function(output, y)

output.size() -> (batch_size, seq_length, n_label); and
y.size -> (batch_size, seq_length)
The error: ValueError: Expected target size (batch_size, n_label), got torch.Size([batch_size, seq_length])
So in order to calculate losses for each time-step and add them up, I came up with setting one and two.