I’m not familiar with your use case and thus don’t know what the dimensions mean in your output.
However, nn.NLLLoss (and nn.CrossEntropyLoss) expect a model output in the shape [batch_size, nb_classes, *] and a target in [batch_size, *] containing class indices in the range [0, nb_classes-1].
Note that the * stands for additional dimensions.
In your case it seems that you are using [batch_size=60, nb_classes=1000, seq_len=3] in your output.
If that’s the case, the target should have the shape [60, 3] and contain values in [0, 999].



 Bill_Ye:

and using the softmax activation


nn.NLLLoss expects log probabilities, so use F.log_softmax instead.