I have an error on Pytorch and in particular with nllloss
I want to appply the criterion, where
criterion = nn.NLLLoss()
I apply it on output and labels
loss = criterion(output.view(-1,1), labels.long())

where:
*the shape of the labels
labels
tensor([ 1,  4,  1,  1,  4,  1,  2,  3,  2,  4,  2,  3,  3,  4,
         0,  4])
output
tensor([ 0.1829,  0.1959,  0.1909,  0.1895,  0.1914,  0.1883,  0.1895,
         0.1884,  0.1865,  0.1931,  0.1883,  0.1917,  0.1942,  0.1937,
         0.1897,  0.1934])

the shape of the output
torch.Size([16])
On the following line:
loss = criterion(output.view(-1,1), labels.long())
I get this error:
The error is:

RuntimeError: Assertion `cur_target &gt;= 0 &amp;&amp; cur_target &lt; n_classes' failed.  at /opt/conda/conda-bld/pytorch_1524584710464/work/aten/src/THNN/generic/ClassNLLCriterion.c:97

Any ideas?

Your label and output shapes must be [batch_size] and [batch_size, n_classes] respectively.
