Loss Functions › Label Smoothing
Language AI HandbookAll chapters Loss Functions › Label SmoothingOne section · Sections in this chapter5 / 17 ↓
Reading tools Definitions & inline links
Choose your expertise level to adjust how many terms are explained. Beginners see more tooltips, experts see fewer to maintain reading flow. Hover over underlined terms for instant definitions.
Article links
Make inline references clickable
Standard cross-entropy trains the model to push probabilities toward 0 or 1 for the correct and incorrect classes. This works well, but it can cause overconfidence: the model may assign extremely high probability to one class even for ambiguous examples, becoming poorly calibrated.
Label smoothing addresses this by replacing the hard one-hot labels with soft labels that reserve a small probability mass for all classes:
where:
- : the smoothing parameter, typically 0.1
- : the total number of classes
- : the index of the true class
- : the smoothed probability for the correct class (slightly less than 1)
- : the smoothed probability for each incorrect class (slightly above 0)
The cross-entropy loss with smoothed labels becomes:
where:
- : the predicted probability for the true class
- : the sum of log probabilities across all classes
Label smoothing has two effects. It discourages the model from assigning zero probability to any class, which improves calibration. It also reduces the gap in logits between the correct class and incorrect classes, making the model's representations more spread out. The original Transformer paper used , and label smoothing has since become standard in many NLP models.
To see why label smoothing improves calibration, consider what happens during training without it. The optimal model under standard cross-entropy would assign probability 1 to the true class and probability 0 to all other classes, for every training example. This means the logits for the true class would need to go to infinity, which is impossible in finite training but the model tries to approach. This drives the logit gap (difference between the top logit and the second-highest) to be very large, leading to overconfident predictions. Label smoothing provides a finite target: the optimal model assigns to the true class, which requires a finite logit gap. Training naturally converges to this finite optimal, producing better-calibrated confidence scores.
A model is well-calibrated if its predicted probabilities match the actual frequency of outcomes. A perfectly calibrated model that says "I'm 70% confident" should be correct 70% of the time. Overconfident models (assigning 99% probability to answers they get wrong) have poor calibration. Label smoothing tends to improve calibration by preventing extreme probability assignments.