Negative log-likelihood (NLL) is a classification loss that penalizes assigning low probability to the correct class. It takes the negative logarithm of that probability and sums across samples. section 7.2.4
For each supervised sample:
- Run the model forward, convert output scores into probabilities, select the probability assigned to the ground-truth class, take its logarithm, negate it, and add it to the loss. section 7.2.4
- Low assigned probabilities produce sharply increasing loss, while probabilities above 0.5 reduce the loss more gradually. section 7.2.4
- PyTorch's nn.NLLLoss expects log probabilities rather than probabilities, typically produced with nn.LogSoftmax. section 7.2.4
PyTorch image classification
A two-class CIFAR model can end with nn.LogSoftmax(dim=1), then use loss = nn.NLLLoss(). Passing the model output and the ground-truth label returns the sample loss.






