Home Knowledge Base Label Smoothing

Label Smoothing is the regularization technique that replaces hard one-hot target labels with soft labels that distribute a small amount of probability mass to non-target classes — preventing the model from becoming overconfident in its predictions, improving calibration, and acting as an implicit regularizer that encourages the model to learn more generalizable representations rather than memorizing the exact training labels.

How Label Smoothing Works

Implementation

def label_smoothing_loss(logits, targets, epsilon=0.1):
    K = logits.size(-1)  # number of classes
    log_probs = F.log_softmax(logits, dim=-1)
    # NLL loss for true class
    nll = -log_probs.gather(dim=-1, index=targets.unsqueeze(1)).squeeze(1)
    # Uniform loss (smooth part)
    smooth = -log_probs.mean(dim=-1)
    loss = (1 - epsilon) * nll + epsilon * smooth
    return loss.mean()

Why Label Smoothing Helps

EffectWithout SmoothingWith Smoothing
Logit magnitudeGrows unbounded (push toward ±∞)Bounded (no need for extreme confidence)
CalibrationOverconfident (99%+ on everything)Better calibrated probabilities
GeneralizationMay memorize noisy labelsMore robust to label noise
RepresentationClusters collapse to single pointClusters have finite spread

Typical ε Values

TaskεNotes
ImageNet classification0.1Standard since Inception v2
Machine translation0.1Default in Transformer paper
Speech recognition0.1-0.2Common in ASR systems
Fine-tuning0.0-0.05Lower to preserve pre-trained knowledge
Knowledge distillation0.0Soft targets from teacher serve similar purpose

Relationship to Other Techniques

When NOT to Use Label Smoothing

Label smoothing is one of the simplest and most effective regularization techniques available — adding just one hyperparameter (ε) that consistently improves generalization and calibration across vision, language, and speech models, making it a default inclusion in most modern training recipes.

label smoothingsoft labelslabel smoothing regularizationlabel noise trainingsmoothed targets

Explore 500+ Semiconductor & AI Topics

From EUV lithography to CUDA optimization — search the full knowledge base or chat with our AI assistant.