Answer the question
In order to leave comments, you need to log in
How does nn.NLLLoss work in pyTorch?
loss_object = torch.nn.NLLLoss()
lsoftmax = torch.nn.LogSoftmax(dim=-1)
loss = loss_object(lsoftmax(outputs), targets)
Traceback (most recent call last):
File "source.py", line 60, in <module>
loss = loss_object(lsoftmax(outputs), targets)
File "/home/m/.local/lib/python3.6/site-packages/torch/nn/modules/module.py", line 541, in __call__
result = self.forward(*input, **kwargs)
File "/home/m/.local/lib/python3.6/site-packages/torch/nn/modules/loss.py", line 204, in forward
return F.nll_loss(input, target, weight=self.weight, ignore_index=self.ignore_index, reduction=self.reduction)
File "/home/m/.local/lib/python3.6/site-packages/torch/nn/functional.py", line 1848, in nll_loss
out_size, target.size()))
ValueError: Expected target size (64, 768), got torch.Size([64, 20])
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question