Topic 25 of 62 · Generalizing and measuring it
Label smoothing: regularizing cross-entropy targets
MediumWhy smooth a one-hot label, and when should a Transformer use hard targets instead?
Practice choosing loss functions · 10 scenarios ↓1 · Start with the intuition
A one-hot target keeps rewarding greater confidence in the observed answer. Label smoothing says: keep most of that signal, but reserve a small amount for uncertainty. It changes what distribution the model is asked to match, not the softmax temperature used at generation time.
2 · How the mechanism works
Mechanism step 1 of 3 · no question to answer
Mix the target with uniform mass
With C classes, use q=(1−ε)·one_hot(y)+ε/C. This convention includes the correct class in the uniform component.
Next, we will look at: Compute ordinary soft-target CE. Move on when this operation makes sense.
Visualizing the behavior
Same true class, less extreme supervision
DerivedHard target
ε=0.1 uniform mixture
3 · The governing equation
q_c = (1−ε)·1[c=y] + ε/C L = −Σ_c q_c log p_c L = (1−ε) CE(one_hot(y),p) + ε CE(uniform,p) ∂L/∂z_c = p_c − q_c
Notation: ε is the label-smoothing coefficient, not the numerical-stability ε in normalization. Some formulations distribute ε over incorrect classes only; state the convention. PyTorch uses the uniform mixture shown here.
The hard target optimum is p_y→1. With smoothing, the optimum matches q, so predicting the correct class with almost absolute certainty is no longer ideal. This can reduce overconfidence in supervised tasks, but it also weakens the exact-label learning signal. It is not a cure for incorrect labels, and the smoothed objective is not the ordinary token NLL used to report perplexity.
4 · Put concrete numbers on it
Worked numbers (from stated assumptions)5 · Common misconception to avoid
Adding smoothing does not make the correct target 0.9 under every convention. With PyTorch’s uniform mixture and four classes it is 0.925. Also, exp(smoothed loss) is not standard perplexity.
Scenario practice · Choose the loss for the scenario
10 scenarios, ordered Easy → Medium → Hard. Choose the best option, then rate your confidence. A first miss gives a nudge and one retry; a second miss or reveal gives an explanation and zero credit.
Session-only practice. Changing level, leaving, or reloading resets this set.
6 · Self-check & interview synthesis
Explain it in your own words first
Before revealing the reference answer, try answering the opening question aloud in four beats: what it is → how the math works → what trade-off it makes → a concrete number or failure mode.
Follow-up question interviewers often ask next
MediumIs label smoothing the same as distillation?
Show follow-up reasoning
No. Uniform smoothing gives every alternative the same target mass. A teacher supplies structured, input-dependent probabilities, which can express that one alternative is much more plausible than another.