Skip to content
mlmentorship

Label smoothing

Replace one-hot targets with a softened distribution that puts ε mass on the wrong classes. Improves calibration, sometimes hurts retrieval.

Published · 4 min read ·Core ·Foundation

Visual quick review

Visual first · depth when needed

Explain why one-hot cross-entropy keeps rewarding larger correct-class logit gaps while label-smoothed cross-entropy has a finite optimum at the smoothed target probability.

Preparing the visual…

Summary

Label smoothing (Szegedy et al., 2016) replaces the hard one-hot target with , where is the number of classes and is a small smoothing constant (typically 0.1). The cross-entropy loss is computed against .

With one-hot targets, cross-entropy approaches its lower bound of zero as the model becomes confident. It can always reduce loss further by making the correct logit larger; reaching the boundary would require an infinite gap between the correct and incorrect logits. This pushes the model toward arbitrarily large logit gaps and overconfident predictions, which are poorly calibrated.

Label smoothing instead creates a finite optimum and forces the model to maintain non-zero probability on incorrect classes. The effects:

  • Better calibration: predicted probabilities track empirical accuracy more closely.
  • Slightly better generalization on most classification benchmarks.
  • Standard in transformer training: original “Attention Is All You Need” used ; LLM pretraining occasionally uses it.

The mechanism

For a classification problem with classes and true class :

  • Hard target: if , else 0.
  • Smoothed target: if , else .

Cross-entropy with smoothed targets:

The first term is the standard cross-entropy; the second is an entropy-like penalty that pulls the predicted distribution toward uniform.

Equivalent view: the optimal for label smoothing is , not 1. The model has no incentive to push the correct logit beyond what produces this target probability.

Learning objective

Why does smoothing stop the correct logit from growing forever?

One-hot and label-smoothed cross-entropy near complete confidence An original loss plot for five classes and epsilon 0.1. The horizontal axis shows predicted probability for the correct class from 0.80 to 0.999; the remaining probability is divided equally among four wrong classes. One-hot cross-entropy is a solid curve that keeps falling toward zero as correct-class probability approaches one. Label-smoothed cross-entropy is a dashed curve with a diamond minimum at correct-class probability 0.92, matching the target probabilities 0.92, 0.02, 0.02, 0.02, and 0.02. Beyond 0.92 the smoothed loss rises; at probability 0.99, one-hot loss is 0.010 and smoothed loss is 0.489. one-hot loss (solid) smoothed loss (dashed) minimum: pc = 0.92 target = prediction at 0.99: 0.010 vs 0.489 0.700.350 0.800.900.920.99 cross-entropy loss predicted probability for correct class pc K = 5 · ε = 0.1 · wrong-class mass split equally
Read it this way: follow the solid curve right: a one-hot target keeps rewarding higher confidence, and its zero-loss boundary requires an unbounded correct-versus-incorrect logit gap. The dashed curve stops at p_c = 0.92, where the prediction matches the smoothed target [0.92, 0.02, 0.02, 0.02, 0.02]. Push farther right and the loss rises because the wrong classes fall below their non-zero targets. This is an original calculation from the formulation in Szegedy et al. (2016).

When to use

  • Language modeling (transformer training): standard .
  • Image classification with hard labels: standard, .
  • Distillation: not needed; the teacher’s soft targets already provide the regularization.
  • Retrieval / contrastive learning: usually skipped; sharp distributions are sometimes needed for good top-1.

Side effects

  • Calibration improves: temperature 1 softmax becomes closer to actual confidence.
  • Top-1 accuracy roughly unchanged or marginally improved.
  • Worse for retrieval / nearest-neighbor: the embeddings cluster less tightly because the model is penalized for confidence (Müller et al., 2019).
  • Worse for distillation as teacher: a label-smoothed teacher provides less informative soft targets.

Common pitfalls

  • Stacking with mixup / cutmix. These already softening targets; adding label smoothing on top double-counts.
  • Using on a regression problem. Label smoothing is for categorical cross-entropy; it has no meaning for MSE.
  • Choosing too large. destroys signal; is the universal default.
  • Forgetting to disable for eval-only metrics. Loss numbers with label smoothing are not directly comparable to one-hot loss numbers.