I realise there is a number of posts about this error already, but none of the proposed solutions worked for me.
The predictions from my Linear model are in the shape [98,20,1] and my ground-truth values are in the shape [98,20,1].
From this response, I know that the output should be [batch_size, nb_classes] so [98, 20] in my case and the target should be [batch_size] or [98] in my case.
Now my question is, how do I make it so that I can use CrossEntropyLoss without transforming my ground-truth values to [98]? Is this even possible?
Edit: if I transform the ground-truth values to be [98,1] with y = y[:,1], I get the following error:
Ok if they are supposed to be the softmax score then one thing you could do is try just getting the argmax of them using torch.argmax. That would give it the correct shape and it would provide the loss function with the correct label.