Hi! I am trying to use CrossEntropyLoss as the loss function for a Linear model but I am getting the following error:
Expected target size (98, 1), got torch.Size([98, 20, 1])

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:
image847×331 11.7 KB
Thank you!