I have a similar error I am posting it here because it is similar and
I tried this method and its not working.
I was trying to do cross entropy loss and I got this error “Expected target size (1, 5), got torch.Size([1, 17451])”
My cls_preds.size()= torch.Size([1, 17451, 5]) and cls_targets.size()= torch.Size([1, 17451])
and I was trying to calculate Loss by following code
loss = nn.CrossEntropyLoss()
output = loss(cls_preds, cls_targets)
Please provide some explanation, thank you.