Hello Calin!



 Calin_Serban:

tensor([[-1.1722, -0.3706],
        [-0.5150, -0.9100]], grad_fn=<LogSoftmaxBackward>)
tensor([1, 0])
tensor(0.4428, grad_fn=<NllLossBackward>)

So which is the formula involved in this example for getting the value 0.4428


0.4428 = -(-0.3706 + -0.5150) /  2.
That is, the value of your output is the average of the losses for each
of the two samples in you batch.


it’s not really clear for me how l1,…,ln from the l(x, y) formula (official NLLLoss documentation) are calculated since the loss weight is None?


Quoting from the NLLLoss 49 documentation:
weight ( Tensor  , optional ) – a manual rescaling weight given to each class. If given, it has to be a Tensor of size C. Otherwise, it is treated as if having all ones.
Optional means that the argument is allowed to be None, i.e, absent.
In such a case there is no reweighting (or, equivalently, the reweighting
factors are all equal to 1).
Best.
K. Frank