Machine Learning
Label Smoothing Regularization: Softening One-Hot Targets to Calibrate Neural Networks
Change a single number from 1.0 to 0.9 in your training targets and a classifier that used to scream "99.99% cat" starts saying a more honest "92% cat" — and its top-1 accuracy often improves in the bargain. That one-line change is label smoothing: instead of training a network to match a hard one-hot target (all probability mass on the correct class, zero everywhere else), you train it against a softened target that reserves a small slice of probability, ε, for every other class.
Formally, for K classes and smoothing strength ε, the smoothed target replaces the one-hot vector y with y' = (1 − ε)·y + ε/K. The correct class gets 1 − ε + ε/K and each wrong class gets ε/K. Introduced by Szegedy et al. in the 2016 Inception-v3 paper as a cheap regularizer, it is now standard in image classifiers, Transformers, and speech models — and is the canonical fix for overconfidence and poor calibration.
- TypeOutput-target regularization for classifiers
- InventedSzegedy et al., Inception-v3, 2016
- Key formulay' = (1 − ε)·y + ε/K
- Typical ε0.1 (0.05–0.2 range)
- OverheadO(K) per example; effectively free
- Used inResNet/EfficientNet, Transformers (NMT), ASR, ImageNet SOTA recipes
Interactive visualization
Press play, or step through manually. The visualization is yours to drive — try it before reading on.
Watch the 60-second explainer
A condensed visual walkthrough — narrated, captioned, under a minute.
The Problem: Overconfident, Miscalibrated Networks
Train a deep classifier with ordinary cross-entropy against one-hot targets and you are, implicitly, asking for the impossible. The softmax probability of the correct class can only reach exactly 1 if its logit is infinitely larger than all others. Gradient descent chases that asymptote: it keeps inflating the winning logit, widening the gap between the correct class and everything else without bound.
The consequences are two-fold:
- Overfitting / poor generalization. The model memorizes training labels with razor-sharp certainty, leaving little margin and hurting test accuracy.
- Miscalibration. A well-calibrated model's confidence should match its accuracy — of all predictions made at 80% confidence, ~80% should be right. Hard-target networks instead report 99%+ confidence while being right far less often. This breaks any downstream system that trusts the probabilities (medical triage, beam search in translation, active learning, selective prediction).
Label smoothing attacks the root cause: it removes the incentive to push logits to infinity by giving the network a finite, reachable target.
How It Works, Step by Step
Let K be the number of classes, ε the smoothing strength (commonly 0.1), and y the one-hot label. The mechanism is a three-line change to the loss computation:
1. Build the smoothed target:
y'[correct] = 1 - ε + ε/K
y'[other] = ε/K (for all K-1 other classes)
Equivalently: y' = (1 - ε)·y + ε·u, where u = uniform(1/K)
2. Forward pass as usual → logits z → p = softmax(z)
3. Loss = cross-entropy(y', p)
= -Σ_k y'[k]·log p[k]
The gradient tells the story. For standard cross-entropy the gradient w.r.t. logit k is p[k] − y[k]. With smoothing it becomes p[k] − y'[k]. The correct-class gradient now vanishes not at p=1 but at p = 1 − ε + ε/K ≈ 0.9, and wrong classes are pulled toward ε/K instead of 0. This creates a stable equilibrium at a finite logit gap. Equivalently, the loss equals ordinary cross-entropy plus ε·KL(u ‖ p) — a term that penalizes divergence from the uniform distribution, i.e. penalizes overconfidence.
Complexity and a Worked Example
Cost. Building the smoothed target and computing the loss is O(K) extra work per example — the same order as the softmax you already compute. There is no extra forward/backward pass, no teacher, no memory beyond one K-vector. In practice the overhead is unmeasurable; frameworks fold it into the loss (PyTorch's CrossEntropyLoss(label_smoothing=0.1)). Training time and model size are unchanged; only the loss target moves.
Worked example — K = 5 classes, ε = 0.1, true class = 2:
One-hot target y = [0, 0, 1, 0, 0 ]
Smoothing: ε/K = 0.1/5 = 0.02
y'[correct] = 1 - 0.1 + 0.02 = 0.92
y'[other] = 0.02
Smoothed y' = [0.02, 0.02, 0.92, 0.02, 0.02] (sums to 1.0)
Say logits z = [1.0, 0.5, 3.0, 0.2, 0.8]
p = softmax(z) ≈ [0.09, 0.05, 0.72, 0.04, 0.07]
Gradient dL/dz = p - y' ≈ [0.07, 0.03, -0.20, 0.02, 0.05]
Notice the correct-class gradient (−0.20) stops pulling once p reaches 0.92 rather than 1.0. The model is never rewarded for exceeding ~92% confidence, which caps the logit gap and yields tighter, better-calibrated probabilities.
Where It's Used in Real Systems
Label smoothing is baked into many production and benchmark recipes:
- Computer vision. Its debut was Inception-v3 on ImageNet, where ε=0.1 gave ~0.2% top-1 improvement. Modern high-accuracy recipes for ResNet, ResNeXt, and EfficientNet routinely include it alongside mixup and RandAugment.
- Neural machine translation & Transformers. The original Transformer ("Attention Is All You Need", 2017) trains with ε=0.1. It slightly hurts perplexity but improves BLEU and calibration, which helps beam search select better sequences.
- Automatic speech recognition. Sequence-to-sequence and CTC-adjacent ASR models use it to avoid overconfident, brittle decoding.
- Frameworks. First-class support in PyTorch (
label_smoothingarg), TensorFlow/Keras (CategoricalCrossentropy(label_smoothing=…)), and JAX/Flax loss utilities — so adoption is a one-argument change.
Because it costs nothing and rarely hurts accuracy, it is a common default in strong image-classification and translation baselines.
Comparison to Alternatives and the Tradeoff
Label smoothing sits among several ways to soften targets, each with a distinct tradeoff:
- vs. hard one-hot: LS trades a tiny bit of training-set fit for better calibration and usually equal-or-better test accuracy. Nearly free lunch.
- vs. knowledge distillation: Distillation uses a teacher's soft outputs, which encode which wrong classes are plausible (a horse resembles a deer more than a truck). LS spreads probability uniformly across wrong classes, discarding that inter-class structure. This is the famous Müller–Kornblith–Hinton (NeurIPS 2019) result: a teacher trained with label smoothing distills worse, because smoothing collapses the penultimate-layer representations into tight clusters and erases the class-similarity information a student needs.
- vs. confidence penalty (Pereyra et al., 2017): Adding
−β·H(p)to the loss is the near-dual of LS; LS penalizes KL from uniform, the confidence penalty rewards output entropy directly. Similar effect, slightly different geometry. - vs. temperature scaling: Temperature scaling fixes calibration after training and does not touch accuracy; LS changes the learned representation itself.
Pitfalls, Failure Modes, and Significance
Pitfalls to watch:
- Don't stack it under a distillation teacher. If this model will be a teacher, LS degrades the dark knowledge you want to transfer. Train teachers with hard targets (or a well-tuned temperature) instead.
- Over-smoothing. Large ε (>0.2) or large K can push wrong-class targets high enough to muddy learning and hurt accuracy. ε=0.1 is the near-universal default.
- Interpreting probabilities on the training set. The reported confidence is deliberately capped near
1−ε; the max softmax will never reach 1, which can confuse thresholding logic that assumed hard-target dynamics. - Metric mismatch. In NMT and language modeling, LS can raise (worsen) perplexity/negative-log-likelihood while improving the metric you actually care about (BLEU, calibration). Judge by the right metric.
- Not a data-noise cure. LS is a fixed uniform prior, not a model of true label noise; with heavy asymmetric label noise, noise-robust losses do better.
Significance. Label smoothing is one of the highest return-on-effort tricks in deep learning: a single hyperparameter that reliably improves calibration and often generalization at zero compute cost. Its main lasting lesson — that the target distribution is itself a design choice — reframed how the field thinks about soft targets, distillation, and confidence.
| Technique | What it modifies | Extra compute | Primary effect |
|---|---|---|---|
| Label smoothing (ε=0.1) | The target distribution: (1−ε)y + ε/K | O(K) per example, ~0 cost | Calibration + mild accuracy gain; caps logit gap |
| Hard one-hot cross-entropy | Nothing (baseline) | None | Drives max-logit to ∞; overconfident, miscalibrated |
| Knowledge distillation | Target = soft teacher outputs | Full teacher forward pass | Transfers dark knowledge; class similarity preserved |
| Confidence penalty (Pereyra 2017) | Adds −β·H(pθ) to the loss | O(K), negligible | Penalizes low entropy directly (dual view of LS) |
| Mixup (Zhang 2018) | Blends both inputs and labels | Cheap data mixing | Regularizes via convex combinations of examples |
| Temperature scaling | Post-hoc: divide logits by T | Trivial, post-training | Calibration only; does not change accuracy |
Frequently asked questions
What is the exact label smoothing formula?
For K classes, one-hot label y, and smoothing strength ε, the smoothed target is y' = (1 − ε)·y + ε/K. The correct class gets probability 1 − ε + ε/K and every other class gets ε/K. These sum to 1, so y' is still a valid distribution. You then compute standard cross-entropy against y'.
What value of epsilon should I use?
ε = 0.1 is the near-universal default, established by the Inception and Transformer papers and rarely worth changing. Values from 0.05 to 0.2 are reasonable; going above ~0.2 risks over-smoothing that dilutes the signal and can reduce accuracy, especially when K is small.
Does label smoothing improve accuracy or just calibration?
Both, usually. Its most reliable benefit is calibration — confidences that better match empirical accuracy. On top of that it often yields a small top-1 accuracy gain (Inception-v3 saw about +0.2% on ImageNet). Occasionally it trades a hair of a proper-scoring metric like perplexity for a better task metric like BLEU.
Why does label smoothing hurt knowledge distillation?
Müller, Kornblith, and Hinton (NeurIPS 2019) showed that smoothing squeezes each class's penultimate-layer representations into a tight cluster, equalizing the logits of all incorrect classes. That erases the inter-class similarity structure — the 'dark knowledge' — that a student learns from. So a teacher trained with label smoothing distills into a student less effectively than a hard-target teacher, even if the teacher's own accuracy is higher.
How is label smoothing different from mixup?
Both soften labels, but mixup also blends the inputs: it takes convex combinations λ·x_i + (1−λ)·x_j of two examples and the same combination of their labels. Label smoothing leaves inputs untouched and adds a fixed uniform prior to every target. Mixup regularizes the input-space geometry; label smoothing only adjusts the target distribution and costs essentially nothing.
Is label smoothing the same as adding a confidence penalty?
They are closely related duals. Label smoothing is equivalent to ordinary cross-entropy plus ε·KL(uniform ‖ p), which penalizes divergence from the uniform distribution. The confidence penalty of Pereyra et al. (2017) instead subtracts β·H(p), directly rewarding output entropy. Both discourage overconfident, peaked softmax outputs; they differ mainly in the exact geometry of the penalty.