Negative log-likelihood (NLL) measures a model’s probabilistic prediction loss: minimizing it rewards assigning higher likelihood to the correct outcome. In PyTorch, NLLLoss appears in the optimization loop. Because logarithms are natural logs here, exponentiating a log-loss recovers the corresponding likelihood and makes model confidence easier to communicate. section 8.2.3
Reading model confidence
For the name Khalid, a log-loss of −1.17 becomes a likelihood of 0.31 after applying exp; the model therefore assigns Algerian as its top prediction with 31% confidence, followed by Moroccan at 26%. section 8.2.3
>>> predictions = topk_predictions(model, 'Khalid', topk=4)
>>> predictions['likelihood'] = np.exp(predictions['log_loss'])
>>> predictions
text log_loss nationality likelihood
rank
0 Khalid -1.17 Algerian 0.31
1 Khalid -1.35 Moroccan 0.26
2 Khalid -1.80 Malaysian 0.17
3 Khalid -2.40 Arabic 0.09
Inspect ranked predictions, their log-loss values, and the exponentiated likelihoods side by side. section 8.2.3






