Foundation Lab

Knowledge Distillation: Learning from Teachers

How you get small models from large ones—DistilBERT is 40% smaller, 60% faster, 97% of performance

Concept 62 of 100EfficiencyPhase 6
#62DistillationEfficiency
key equation
L=αLKL(S(x),T(x))+(1−α)LCE(S(x),y)\mathcal{L} = \alpha \mathcal{L}_{KL}(S(x), T(x)) + (1-\alpha) \mathcal{L}_{CE}(S(x), y)
Reading map and next steps

Selected Foundation Object

Keep the equation fixed; move through the evidence.

Concept 62 of 100DistillationEfficiency / Phase 6: Modern efficiency & inference
Current question

Hard labels say "cat, not dog"; soft labels say "mostly cat, a bit dog, definitely not car"

L=αLKL(S(x),T(x))+(1−α)LCE(S(x),y)\mathcal{L} = \alpha \mathcal{L}_{KL}(S(x), T(x)) + (1-\alpha) \mathcal{L}_{CE}(S(x), y)
PredictionCommit before the demo.

Ask what should change when the equation is manipulated, then use the linked notebook demo to test that expectation.

EvidenceCompare the linked witness and source.

Use the linked notebook demo, this key equation, and canonical papers as separate witnesses for the same object.

InvariantName what survives notation changes.

The useful learning product is the reusable mechanism you can carry into another model, paper, or engineering tradeoff.

Next moveContinue in the newer notebook.

This atlas page has no local demo; the domain notebook carries the interactive witness and the fuller Intuition -> Math -> Code -> Demo sequence.

Why It Matters for Modern Models

  • How you get small models from large ones—DistilBERT is 40% smaller, 60% faster, 97% of performance
  • Soft targets contain "dark knowledge": teacher's uncertainty about similar classes
  • Modern LLM training uses distillation: smaller models trained on larger model outputs

What Tutorials Skip

What is still poorly explained in textbooks and papers:

  • Hard labels say "cat, not dog"; soft labels say "mostly cat, a bit dog, definitely not car"
  • Temperature τ controls how much dark knowledge transfers: τ→∞ means uniform (no info)
  • Distillation works even when student has different architecture than teacher

Visualization Status

Core Math (Optional Deep Dive)

If you want intuition first, start with the key equation here and the linked notebook demo. Come back here for the full walkthrough.

Key Equation
L=αLKL(S(x),T(x))+(1−α)LCE(S(x),y)\mathcal{L} = \alpha \mathcal{L}_{KL}(S(x), T(x)) + (1-\alpha) \mathcal{L}_{CE}(S(x), y)

Train a student SS to match a teacher TT's soft predictions:

L=(1−α)LCE(S(x),y)+αLKL(S(x),T(x))\mathcal{L} = (1-\alpha) \mathcal{L}_{CE}(S(x), y) + \alpha \mathcal{L}_{KL}(S(x), T(x))

Use temperature τ\tau to soften teacher outputs:

piT=exp⁡(ziT/τ)∑jexp⁡(zjT/τ)p_i^T = \frac{\exp(z_i^T / \tau)}{\sum_j \exp(z_j^T / \tau)}

Higher τ\tau → more uniform → more information about relative similarities.

Canonical Papers

Distilling the Knowledge in a Neural Network

Hinton, Vinyals, Dean2015NIPS Workshop
Read paper →

DistilBERT, a distilled version of BERT

Sanh et al.2019arXiv
Read paper →

Connections

Next Moves

Choose the next question to carry this object forward.