I noticed a strange thing with the following input tensor (the 1 is at position 62
) :
tensor([[0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 1., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0., 0.,
0., 0., 0., 0., 0., 0., 0., 0., 0.]])
and target :
tensor([62])
the following commands gives the following output :
crit = nn.NLLLoss()
soft = nn.Softmax(dim = 1)
crit(input[0,:].unsqueeze(0),target[0].unsqueeze(0))
Out[120]: tensor(-1.)
crit(soft(input[0].unsqueeze(0)),target[0].unsqueeze(0))
Out[135]: tensor(-0.0270)
This is not zero but it should be… why is that so ? The unsqueeze are here so that NLLLoss is satisfied by input dimensions,