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.

published · difficulty 3/5 · 16 min read

Reading map and next steps

Intuition

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

PredictName the object in plain language, then predict what should change.Leave with one reusable mental picture before notation appears.

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.

Section prompt

Copy-only prompts — each action copies a page-grounded prompt to your clipboard. Nothing is sent by this site.

Math

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

InspectTrack the same object through the notation and check each symbol.Leave with the invariant the equations preserve.

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(τ)(y∣x)=softmax(zT(x)/τ),pS(τ)(y∣x)=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=τ2 KL ⁣(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(p∥q)=∑yp(y)log⁡p(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.

Section prompt

Copy-only prompts — each action copies a page-grounded prompt to your clipboard. Nothing is sent by this site.

Code

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

TraceMatch variables to symbols before reading the implementation.Leave with a runnable witness for the math.
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))
Section prompt

Copy-only prompts — each action copies a page-grounded prompt to your clipboard. Nothing is sent by this site.

Interactive Demo

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

ManipulateChange one control and predict the visible response before reveal.Leave with the observed invariant or a repaired model.

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 inquiry checkpoint

Manipulate one control and predict the visible change.

01Choose lensTrace a quantity
02ObserveDemo state pending
03GroundName the equation, invariant, or control that explains it.
04CarryNext: Speculative Decoding: Lossless Multi-Token Generation

Choose what to inspect in Knowledge Distillation: Learning from Teachers. This shared fallback is an observation guide, not evidence of learning.

Loading interactive demo...

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.

Section prompt

Copy-only prompts — each action copies a page-grounded prompt to your clipboard. Nothing is sent by this site.

4/4 sections ready

Concept: Knowledge Distillation: Learning from Teachers

What is the smallest example that makes Knowledge Distillation: Learning from Teachers click without losing the math?

BeforeMaximum LikelihoodNow4/4 sections readyTryManipulate one control and predict the visible change.NextSpeculative Decoding: Lossless Multi-Token Generation
Object contextEfficiency
ConceptLearner lens

Knowledge Distillation: Learning from Teachers

What is the smallest example that makes Knowledge Distillation: Learning from Teachers click without losing the math?

Mode questionCan I say the mechanism back in one sentence before I reveal anything?

Start with the prediction checkpoint, then compare the reveal to the mental model.

Take this move

Study modes

Keep the object fixed; change the lens.

Route back through the notebook

Carry the same object through intuition, math, code, and demo.

4/4 sections ready
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.

After The First Pass

Turn the concept into an inspected object.

The lower panels are one second act: keep the object fixed, inspect it visually, check source boundaries, practice transfer, then attach the research question.
ConceptKnowledge Distillation: Learning from TeachersEfficiency

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.

Demo notes 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 readyDemo notes 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.

Object - ConceptKnowledge Distillation: Learning from TeachersQuestion

What is the smallest example that makes Knowledge Distillation: Learning from Teachers click without losing the math?

concept:efficiency/knowledge-distillation
Boundary

sources: hinton-2015-distillation

Check

Open the closest source note before trusting the local explanation.

Evidence

1 selected-object source shown first; 1 reference total.

Next move

Audit the claim boundary, then ask from the same selected object.

selected object source · paper · 2015Distilling the Knowledge in a Neural NetworkHinton, Vinyals, and Dean
Located CF editorial boundary

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

Used here as

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...

Caveat

This checks Hinton-style finite-class soft-target distillation. It does not check sequence-level LLM distillation recipes, speculative-decoding correctness, teacher quality, capacity matc...

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.

Object - ConceptKnowledge Distillation: Learning from TeachersQuestion

What is the smallest example that makes Knowledge Distillation: Learning from Teachers click without losing the math?

concept:efficiency/knowledge-distillation
Boundary

sources: hinton-2015-distillation

Check

Treat every claim as provisional until source support and a local witness agree.

Evidence

1 structured claim check on this concept.

Next move

Run the prediction or practice transfer before asking for a grounded review.

1 CF editorial source-scope review recorded

Publisher-side editorial review is not independent replication. Claims without it still need exact source-support review. 1 reference and 3 local witnesses are available for inspection.

Knowledge 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.
Used here as

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...

Local witness
Equation 1
pT(τ)(y∣x)=softmax(zT(x)/τ),pS(τ)(y∣x)=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).
Equation 2
LKD=τ2 KL ⁣(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}}.
Caveat

This 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...

Review stateCF editorial source-scope reviewClaim metadata: source checkedPublisher-side editorial review only; not independent replication. 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 · Knowledge Distillation: Learning from Teachers

Try the idea in your own words

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

Concept · Current object

Knowledge Distillation: Learning from Teachers

Source boundary: sources: hinton-2015-distillation

Object context and links

Efficiency

concept:efficiency/knowledge-distillation
Choose a task

Explain the mechanism

For Knowledge Distillation: Learning from Teachers: What is the smallest example that makes Knowledge Distillation: Learning from Teachers click without losing the math? Explain your answer, including what changes, why, and which assumption matters.

No answer yet

A rough first thought is enough. Your draft stays when you change tasks.

Local to this page session. Not saved after leaving or reloading.

A little help · Explain

Open one hint at a time. These are suggestions, not your answer or a grade.

0 of 3 hints shown for this question.

    Clearing your answer does not erase help history. Outside help cannot be verified here.

    Where am I stuck? (optional)
    Your own description, not an automatic diagnosis

    Choose one, or leave this unspecified. Select it again to clear it.

    Take your draft to a feedback conversation

    No AI feedback runs here. You can copy a prompt to use elsewhere; nothing is sent automatically. Review the text before sharing, and leave out private information.

    Write an attempt before copying a feedback prompt.

    This draft and any AI response do not establish mastery. Try a different case later without help; this page has not measured that learning.

    Grounded object roomClose
    Selected object routeAsk from this object; carry one invariant back.sources: hinton-2015-distillation
    1. ObjectConceptKnowledge Distillation: Learning from Teachers
    2. PredictBefore revealKnowledge Distillation: Learning from Teachers prediction
    3. WitnessCompare codeKnowledge Distillation: Learning from Teachers code witness 1
    4. RoomAsk groundedChecking local snapshot
    ConceptKnowledge Distillation: Learning from TeachersEfficiency
    Code witness comparisonKnowledge Distillation: Learning from Teachers code witness 1z = z / tauPrediction before revealKnowledge Distillation: Learning from Teachers predictionManipulate 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?Checking local snapshot

    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?

    Source boundaryInspect source ids: hinton-2015-distillationStable content-object key attached
    Role lenses for this object

    These are fixed, deterministic perspectives derived from the selected object. They do not represent people, community contributions, or independent review.

    Learner evidence requestAsk what would make "Knowledge Distillation: Learning from Teachers" feel predictable rather than familiar.
    Assumption

    Source ids hinton-2015-distillation must support the exact object, not just the surrounding topic.

    Source-checking summary

    Treat this as a mechanism object: connect the definition to one equation, code witness, or demo before broadening the discussion.

    Proposed experiment

    Ask the learner to perturb one representation, then check whether the same invariant survives in math, code, and demo.

    Next action

    The learner can state the mechanism in their own words

    Evidence4 checks
    PredictionChecking carried observation
    ActionReady for one action
    AILearner handoff ready
    Open source object
    01PredictionChecking browser-local route memory
    02EvidenceChecking for a carried observation
    03BoundaryInspect source ids: hinton-2015-distillation
    04Next moveSave one next action
    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
    Object-attached 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 Deterministic role lenses for this object: - Boundary: fixed perspectives, not people, community contributions, or independent review - Source-checking summary: Treat this as a mechanism object: connect the definition to one equation, code witness, or demo before broadening the discussion. - Proposed experiment: Ask the learner to perturb one representation, then check whether the same invariant survives in math, code, and demo. - Teach/transfer move: Turn the mechanism into one sentence that predicts a neighboring concept. - Assumptions: - Source ids hinton-2015-distillation must support the exact object, not just the surrounding topic. - The stable content-object key lets local drafts, prompts, and route memory attach without changing the source page. - The concept explanation is local atlas prose until checked against its math, code, and source support. - Prerequisite gaps should become a repair route, not a reason to leave the object vague. - Role-lens requests: - Learner: ask for "Ask what would make "Knowledge Distillation: Learning from Teachers" feel predictable rather than familiar." | assumption: Source ids hinton-2015-distillation must support the exact object, not just the surrounding topic. | next action: The learner can state the mechanism in their own words - Researcher: ask for "Source ids to inspect: hinton-2015-distillation" | assumption: The stable content-object key lets local drafts, prompts, and route memory attach without changing the source page. | next action: The learner can name the prerequisite that would repair confusion - Experimenter: ask for "Choose one variable or condition to perturb before asking for an explanation." | assumption: The concept explanation is local atlas prose until checked against its math, code, and source support. | next action: The learner can predict how the mechanism changes under one perturbation - Professor: ask for "Find the smallest transferable rule a learner could reuse without the AI." | assumption: Prerequisite gaps should become a repair route, not a reason to leave the object vague. | next action: Teach or transfer: Turn the mechanism into one sentence that predicts a neighboring concept. 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. Current deterministic role lens for this object: - Role lens: Learner - Evidence request: Ask what would make "Knowledge Distillation: Learning from Teachers" feel predictable rather than familiar. - Assumption to keep visible: Source ids hinton-2015-distillation must support the exact object, not just the surrounding topic. - Proposed experiment: Ask the learner to perturb one representation, then check whether the same invariant survives in math, code, and demo. - Next action: The learner can state the mechanism in their own words

    concept/concept-notebook/efficiency/knowledge-distillation concept:efficiency/knowledge-distillation