Optimization

Label Smoothing & Soft Targets

Replace one-hot labels with soft targets to reduce overconfidence, improve calibration, and sometimes boost generalization.

status: reviewimportance: importantdifficulty 2/5math: undergraduateread: 12mdemo planned

Concept Structure

Label Smoothing & Soft Targets

01Intuition

Start with the picture, metaphor, or geometric mechanism.

02Math

Make the objects explicit and connect them with notation.

03Code

Mirror the equations with runnable implementation details.

04Interactive Demo

Manipulate the mechanism and watch the idea respond.

1prerequisites
1next concepts
2related links

Learning map

Label Smoothing & Soft Targets
BeforeCross-EntropyNow3/4 sections readyTryUse the demo notes to predict the mechanism before moving on.NextKnowledge Distillation: Learning from Teachers

Object flow

3/4 sections readyAsk about thisResearch room
ConceptLabel Smoothing & Soft TargetsOptimization
Local snapshot ready
concept:optimization/label-smoothing

Conceptual Bridge

What should feel connected as you move through this page.

Carry inCross-Entropy

Bring the mental model from Cross-Entropy; this page will reuse it instead of restarting from zero.

Work hereLabel Smoothing & Soft Targets

Replace one-hot labels with soft targets to reduce overconfidence, improve calibration, and sometimes boost generalization.

Carry outKnowledge Distillation: Learning from Teachers

The next edge should feel earned: use the demo prediction here before following Knowledge Distillation: Learning from Teachers.

Test the linkUse the demo notes to predict the mechanism before moving on.Then continue to Knowledge Distillation: Learning from Teachers
01

01

Intuition

Build the mental picture first so the rest of the page has something to attach to.

Section prompt

One-hot labels say: "the correct class is 100% class k, 0% everything else."

In the real world, that level of certainty is often wrong:

  • labels can be noisy,
  • classes can overlap,
  • a training set might not capture all variations.

If we train a model to match one-hot labels perfectly, we also train it to become overconfident. Overconfidence hurts calibration (probabilities stop meaning what they claim), and it can make models brittle under distribution shift.

Label smoothing is the simplest fix: keep the correct class highest, but allocate a small amount of probability mass to other classes.

02

02

Math

Translate the story into symbols, assumptions, and a derivation you can inspect.

Section prompt

Let y{0,1}Ky\in\{0,1\}^K be a one-hot target and α[0,1]\alpha\in[0,1] a smoothing strength. Define a smoothed target:

ysmooth=(1α)y+αK1.y_{\mathrm{smooth}} = (1-\alpha)\,y + \frac{\alpha}{K}\,\mathbf 1.

If p=softmax(z)p = \mathrm{softmax}(z) are the predicted probabilities, cross-entropy becomes:

L=k=1Kysmooth,klogpk.\mathcal L = -\sum_{k=1}^K y_{\mathrm{smooth},k}\,\log p_k.

The gradient w.r.t. logits is:

Lz=pysmooth.\frac{\partial \mathcal L}{\partial z} = p - y_{\mathrm{smooth}}.

So compared to one-hot training (where the gradient is pyp-y), label smoothing:

  • reduces the incentive to push logits to ±\pm\infty,
  • acts like a small regularizer against extreme confidence.
03

03

Code

Keep the implementation aligned with the notation so the algorithm is legible.

Section prompt
import numpy as np

def softmax(z):
    z = z - z.max()
    e = np.exp(z)
    return e / e.sum()

z = np.array([3.0, 1.0, -0.5, -1.0])  # logits
p = softmax(z)
K, y = 4, np.array([1.0, 0.0, 0.0, 0.0])

for alpha in [0.0, 0.1]:
    y_s = (1 - alpha) * y + alpha * np.ones(K) / K
    grad = p - y_s
    loss = -float(np.sum(y_s * np.log(p + 1e-12)))
    print("alpha =", alpha, "loss =", round(loss, 4), "grad =", np.round(grad, 3))
04

04

Interactive Demo

Use direct manipulation to connect the explanation to a moving system.

Section prompt

No interactive demo yet for this concept. A good next step is a small "logit slider" demo that shows how smoothing changes gradients and calibration.

No live visualization is registered for this concept yet.

The page still supports explanatory demo notes above; when a viz.tsx exists, it will render here without changing the route.

After The First Pass

Turn the concept into an inspected object.

Once the invariant is visible in the intuition, math, code, and demo, use these panels to inspect the mechanism visually, check source support, practice the idea, and attach a grounded research question.

Mechanism Storyboard

See the idea move before the page explains it

Replace one-hot labels with soft targets to reduce overconfidence, improve calibration, and sometimes boost generalization.

Demo notes open01 / Intuition
Prediction lens

Start with the picture, metaphor, or geometric mechanism.

Commit first

Before reading further, choose the kind of change Label Smoothing & Soft Targets should make visible.

Visual Inquiry

Make the image answer a mathematical question

Replace one-hot labels with soft targets to reduce overconfidence, improve calibration, and sometimes boost generalization.

3/4 stages readyDemo notes connected
Prediction

Which visible object should carry the first intuition?

Commit first

Pick the cue that should make Label Smoothing & Soft Targets easier to reason about before the page gives the answer.

Claim Review

Replace one-hot labels with soft targets to reduce overconfidence, improve calibration, and sometimes boost generalization.

StatusSubstantive claim review pending

Source IDs and witness objects are attached for review; they are not proof by themselves.

SourcesNo references

Add source metadata before claiming support.

Witnesses3 local objects

Use equation, code, and demo objects to check whether the source support is operational.

Practice Loop

Try the idea before it explains itself

Replace one-hot labels with soft targets to reduce overconfidence, improve calibration, and sometimes boost generalization.

Readiness0/3 checks ready
Predict

Before touching the demo, predict one visible change that should happen in Label Smoothing & Soft Targets.

Hint 1

Reveal when your model needs a nudge.

Hint 2

Reveal when your model needs a nudge.

Hint 3

Reveal when your model needs a nudge.

Object research drawerClose
ConceptLabel Smoothing & Soft TargetsOptimization
Code witness comparisonLabel Smoothing & Soft Targets code witness 1z = z - z.max()Prediction before revealLabel Smoothing & Soft Targets predictionUse the demo notes to predict the mechanism before moving on.
Grounded room questionWhat is the smallest example that makes Label Smoothing & Soft Targets click without losing the math?Local snapshot ready

Research Room

Attach the question to an exact object

Pick the concept, equation, source, code witness, claim, misconception, or demo state before asking for help. The handoff stays grounded to that object.
Next local actionNo local draft saved yet

Open the draft below to save one note and next action in this browser.

conceptOptimization

Label Smoothing & Soft Targets

Anchored question

What is the smallest example that makes Label Smoothing & Soft Targets click without losing the math?

Local action draftNo local draft saved yetExpand only when ready to capture one local next action
Local action draft

This draft stays locally in this browser for concept:optimization/label-smoothing.

No local draft saved.
Evidence to inspect
  • Definition, prerequisite, and contrast concept links
  • The equation or code witness that makes the concept operational
  • One demo state that shows the invariant instead of a slogan
What would resolve this
  • The learner can state the mechanism in their own words
  • The learner can name the prerequisite that would repair confusion
  • The learner can predict how the mechanism changes under one perturbation
Grounded AI handoff

I am working in Continuous Function's research reading room. Object: concept - Label Smoothing & Soft Targets Object key: concept:optimization/label-smoothing Context: Optimization Anchor id: concept/concept-notebook/optimization/label-smoothing Open question: What is the smallest example that makes Label Smoothing & Soft Targets click without losing the math? Evidence to inspect: - Definition, prerequisite, and contrast concept links - The equation or code witness that makes the concept operational - One demo state that shows the invariant instead of a slogan What would resolve this: - The learner can state the mechanism in their own words - The learner can name the prerequisite that would repair confusion - The learner can predict how the mechanism changes under one perturbation Answer as a careful research tutor: stay source-grounded, separate verified evidence from assumptions, name the relevant math objects, and end with one next action.

Open source object
concept/concept-notebook/optimization/label-smoothing concept:optimization/label-smoothing