Efficiency

Knowledge Distillation: Learning from Teachers

Train a smaller student to mimic a stronger teacher by matching soft probability distributions (often with temperature), transferring 'dark knowledge' beyond hard labels.

status: publishedimportance: importantdifficulty 3/5math: undergraduateread: 16mlive demo
Editorial efficiency illustration of a larger teacher model transferring softened probability structure into a smaller student model.

Concept Structure

Knowledge Distillation: Learning from Teachers

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.

2prerequisites
1next concepts
2related links

Learning map

Knowledge Distillation: Learning from Teachers
BeforeMaximum LikelihoodNow4/4 sections readyTryManipulate one control and predict the visible change.NextSpeculative Decoding: Lossless Multi-Token Generation

Object flow

4/4 sections readyAsk about thisResearch room
ConceptKnowledge Distillation: Learning from TeachersEfficiency
1 source attachedLocal snapshot ready
concept:efficiency/knowledge-distillation

Conceptual Bridge

What should feel connected as you move through this page.

Carry inMaximum Likelihood

Bring the mental model from Maximum Likelihood; this page will reuse it instead of restarting from zero.

Work hereKnowledge Distillation: Learning from Teachers

Train a smaller student to mimic a stronger teacher by matching soft probability distributions (often with temperature), transferring 'dark knowledge' beyond hard labels.

Carry outSpeculative Decoding: Lossless Multi-Token Generation

The next edge should feel earned: use the demo prediction here before following Speculative Decoding: Lossless Multi-Token Generation.

Test the linkManipulate one control and predict the visible change.Then continue to Speculative Decoding: Lossless Multi-Token Generation
01

01

Intuition

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

Section prompt

If you train a model on hard labels, every example is treated like a one-bit fact: "this is a cat."

A good teacher model knows more than that. It might say:

  • 0.84 cat
  • 0.12 dog
  • 0.04 fox

Those "almost" probabilities carry what is often called dark knowledge: relative non-target probabilities can encode similarity structure learned from data. Distillation trains a student to match the teacher's distribution, so the student can inherit the teacher's behavior even with fewer parameters or a different architecture.

In LLMs, distillation often extends the same intuition to next-token distributions: a smaller model is trained to approximate a larger model's token probabilities. Speculative decoding uses a fast draft model as an approximation to the final model; the draft may be distilled, but speculative decoding's correctness comes from verification rather than distillation itself.

02

02

Math

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

Section prompt

Let the teacher and student produce logits zT(x)z_T(x) and zS(x)z_S(x) over a discrete output space.

With temperature τ>0\tau>0, define softened probabilities:

pT(τ)(yx)=softmax(zT(x)/τ),pS(τ)(yx)=softmax(zS(x)/τ).p_T^{(\tau)}(y\mid x)=\mathrm{softmax}(z_T(x)/\tau),\qquad p_S^{(\tau)}(y\mid x)=\mathrm{softmax}(z_S(x)/\tau).

A standard modern way to write the soft-target distillation term is teacher-student KL divergence; with a fixed teacher distribution, this is equivalent to soft-target cross-entropy up to a teacher-only constant:

LKD=τ2KL ⁣(pT(τ)(x)  pS(τ)(x)),L=(1α)Lhard+αLKD.\mathcal L_{\text{KD}} = \tau^2\,\mathrm{KL}\!\left(p_T^{(\tau)}(\cdot\mid x)\ \|\ p_S^{(\tau)}(\cdot\mid x)\right), \qquad \mathcal L = (1-\alpha)\,\mathcal L_{\text{hard}} + \alpha\,\mathcal L_{\text{KD}}.

where:

KL(pq)=yp(y)logp(y)q(y).\mathrm{KL}(p\|q)=\sum_y p(y)\log\frac{p(y)}{q(y)}.

The second term can be a hard-label loss for classification or a standard next-token loss in an LLM setting.

Rule of thumb: increasing τ\tau makes the teacher distribution softer (more informative about non-top classes), but if τ\tau is too large it becomes nearly uniform and carries little signal.

03

03

Code

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

Section prompt
import numpy as np

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

def kl(p, q):
    eps = 1e-12
    return float(np.sum(p * (np.log(p + eps) - np.log(q + eps))))

teacher_logits = np.array([4.0, 2.0, 0.0])
student_logits = np.array([3.0, 0.5, -0.5])

for tau in [1.0, 2.0, 4.0]:
    pT = softmax(teacher_logits, tau)
    pS = softmax(student_logits, tau)
    print("tau=", tau, "pT=", np.round(pT, 3), "pS=", np.round(pS, 3), "KL=", round(kl(pT, pS), 3))
04

04

Interactive Demo

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

Section prompt

The demo below asks you to predict the largest non-label pull before revealing the softened teacher distribution. The key invariant is that distillation transfers structure in the teacher's non-argmax probabilities, not only the hard top label.

Live Concept Demo

Explore Knowledge Distillation: Learning from Teachers

The stage is code-native and interactive. Use it to test the explanation against the mechanism.

difficulty 3/5undergraduatecode-aligned
Demo Prediction Checkpoint

Manipulate one control and predict the visible change.

Commit to what Knowledge Distillation: Learning from Teachers should make visible before reading the result.

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

Train a smaller student to mimic a stronger teacher by matching soft probability distributions (often with temperature), transferring 'dark knowledge' beyond hard labels.

Prediction open01 / Intuition
Editorial efficiency illustration of a larger teacher model transferring softened probability structure into a smaller student model.
Prediction lens

Start with the picture, metaphor, or geometric mechanism.

Commit first

Before reading further, choose the kind of change Knowledge Distillation: Learning from Teachers should make visible.

Visual Inquiry

Make the image answer a mathematical question

Train a smaller student to mimic a stronger teacher by matching soft probability distributions (often with temperature), transferring 'dark knowledge' beyond hard labels.

4/4 stages readyLive demo connected
Prediction

Which visible object should carry the first intuition?

Commit first

Pick the cue that should make Knowledge Distillation: Learning from Teachers easier to reason about before the page gives the answer.

Source Grounding

Canonical references for the mechanism on this page.

paper · 2015Distilling the Knowledge in a Neural NetworkHinton, Vinyals, and Dean

Grounds temperature-softened soft targets and the incorrect-class probability-ratio/similarity-structure intuition used by the page.

Open source

Claim Review

Train a smaller student to mimic a stronger teacher by matching soft probability distributions (often with temperature), transferring 'dark knowledge' beyond hard labels.

Status1 substantive review recorded

Claims without a substantive review badge still need exact source-support review.

Sources1 reference

hinton-2015-distillation

Witnesses4 local objects

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

Substantively reviewedKnowledge distillation trains a student to match a teacher's temperature-softened soft targets, not just hard labels: non-target probability ratios carry similarity structure, and a KL-equivalent soft-target loss can be mixed with supervised loss.Claim metadata: source checked

Hinton et al. define softened class probabilities with temperature, train the distilled model to match teacher soft targets, say incorrect-answer probability ratios encode rich similarity structure, and mix soft-target cross-entropy with label cross-entropy. The page instantiates the equivalent teacher-student KL term plus temperature, gaps, and hard/KD mixing.

Sources: Distilling the Knowledge in a Neural NetworkThis checks Hinton-style finite-class soft-target distillation. It does not check sequence-level LLM distillation recipes, speculative-decoding correctness, teacher quality, capacity matching, data filtering, or universal compression gains.A bounded review summary is present; still check caveats and exact source scope.

Hinton et al. support high-temperature soft targets, matching the teacher at the same temperature, incorrect-class probability ratios as similarity structure, and weighted soft-target plus hard-label cross-entropy with T^2 scaling. Oracle accepted the page's fixed-teacher KL form as cross-entropy-equivalent and the toy math/code/demo as witnesses for tau-softmax, tau^2 KL, non-label pull, and hard/KD mixing.

Reviewer: codex+oracle; reviewed 2026-05-07

Practice Loop

Try the idea before it explains itself

Train a smaller student to mimic a stronger teacher by matching soft probability distributions (often with temperature), transferring 'dark knowledge' beyond hard labels.

Readiness0/3 checks ready
Predict

Before touching the demo, predict one visible change that should happen in Knowledge Distillation: Learning from Teachers.

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
ConceptKnowledge Distillation: Learning from TeachersEfficiency
Code witness comparisonKnowledge Distillation: Learning from Teachers code witness 1z = z / tauPrediction before revealKnowledge Distillation: Learning from Teachers interactive demoManipulate one control and predict the visible change.
Grounded room questionWhat is the smallest example that makes Knowledge Distillation: Learning from Teachers 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.

conceptEfficiency

Knowledge Distillation: Learning from Teachers

Anchored question

What is the smallest example that makes Knowledge Distillation: Learning from Teachers 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:efficiency/knowledge-distillation.

No local draft saved.
Evidence to inspect
  • Source ids to inspect: hinton-2015-distillation
  • 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 - Knowledge Distillation: Learning from Teachers Object key: concept:efficiency/knowledge-distillation Context: Efficiency Anchor id: concept/concept-notebook/efficiency/knowledge-distillation Open question: What is the smallest example that makes Knowledge Distillation: Learning from Teachers click without losing the math? Evidence to inspect: - Source ids to inspect: hinton-2015-distillation - 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/efficiency/knowledge-distillation concept:efficiency/knowledge-distillation