$ attention.sh

knowledge base · entry 06

Teaching a small model to think like a big one

A read-through of the paper that started model compression — how a small model can inherit a big one's judgment, and why the wrong answers turn out to be the part worth copying.

paper Distilling the Knowledge in a Neural Network
authors Geoffrey Hinton, Oriol Vinyals, Jeff Dean — Google (2015)
source arXiv:1503.02531
why we read it distillation is how a sovereign specialist inherits a big model's judgment on a fraction of the hardware

every figure zooms — click it, scroll to magnify, drag to pan

part one

The idea, before any jargon

figure 1 · the whole idea

The wrong answers are the lesson

You have a big, accurate model and you wish it were small — cheaper to run, able to live on a phone or inside a firewall. The obvious plan is to train a small model on the same labelled data. It never works as well: the small model doesn't have the capacity to rediscover everything the big one learned.

Distillation's move is unexpected. Don't train the small model on the labels — train it on the big model's full answer. When the big model looks at a handwritten 2, it doesn't just say "2". It says: almost certainly a 2, a little bit like a 3, a faint touch like a 7, nothing like a 4. That shape — which wrong answers it finds tempting — is knowledge the one-hot label throws away.

click any figure to zoom · scroll to magnify · drag to pan

The paper's own example: shown a photo of a BMW, the big model gives a tiny probability to "garbage truck" — but many times more than it gives to "carrot". Those minuscule numbers encode how the model sees the world. Hinton calls it the dark knowledge: most of what a trained network knows is hiding in the probabilities it assigns to answers that are wrong.

part two · the mechanism

How you make the whispers audible

Two ideas do all the work: a temperature knob that reveals the small probabilities, and a training signal that blends the teacher's opinion with the ground truth.

figure 2 · temperature

Temperature turns up the whispers

There's a catch. The interesting probabilities — the "a bit like a 3" — are often tiny, so tiny the student barely feels them during training. The fix is a single knob called temperature, applied inside the softmax that turns the model's raw scores into probabilities.

At temperature 1 you get the model's normal, confident answer. Turn the temperature up and the distribution softens: the tall bar shrinks, the small bars rise, and the hidden structure becomes loud enough to learn from. Turn it up too far and everything blurs toward equal — so the useful setting is warm, not boiling.

Crucially, temperature never changes which answer is most likely. It only changes how much the student is told about the runners-up. The teacher and the student are heated to the same temperature during training; the student is cooled back to 1 when it's time to actually use it.

figure 3 · the training signal

Two signals, one student

If you only copied the teacher, the student would faithfully reproduce the teacher's mistakes and have no anchor to the truth. So the student learns from two losses at once.

The two are added in a weighted sum. The one fiddly detail, the factor: softening at temperature T shrinks the distillation gradients by roughly 1/T², so you multiply that loss back up by to keep the two signals comparable in strength. That's the entire training recipe.

part three · the one bit of arithmetic

Temperature, with actual numbers

Skippable — nothing later depends on it. But it's small enough to follow completely, and it makes "dark knowledge" concrete.

figure 4 · the toy example

The same scores, two temperatures

Softmax with temperature is just exp(zᵢ / T) for each score, divided by the sum so it adds to one. Raising T shrinks every score before the exponential, which flattens the result. Watch what that does to one digit.

Same four scores throughout. At T = 1 the "2" takes 64% and the "7" is 0.03 — so small its gradient is negligible and the student effectively never hears about it. At T = 4 the "7" rises to 0.17: now it's a real target the student is forced to fit. Nothing about the teacher changed — you just turned up the part of its answer worth copying.

the payoff At high temperature, matching the teacher's softened probabilities is almost the same as matching its raw scores directly. That's why it works: the student isn't just told the answer, it's told how far the teacher leaned toward every alternative — the full geometry of the teacher's judgment, not a single point.

part four · does it work

The result, and the surprise

figure 5 · results

It works — and it leaks knowledge you never handed over

On MNIST, a small network trained from scratch makes 146 test errors. The big network makes 67. Distilled from the big one, the same small network drops to 74 — closing almost the entire gap without gaining a single parameter.

The striking part is the second panel. The authors built a transfer set that contained no examples of the digit 3 at all, and distilled a student on it. The student still recognised 3s at test time — 98.6% correct — because the soft targets for other digits (a 5 that leans toward 3, an 8 that does too) had quietly encoded what a 3 looks like.

Think about what that means. The knowledge of a class the student was never shown transferred through the similarity structure of the other classes. The soft targets carry the teacher's whole map of how things resemble each other — far more than any set of labels could.

the math · in the paper's notation

Three equations from section 2

The tempered softmax, the two-part loss, and the gradient that explains why any of it works — each read aloud, every symbol named, and the softmax checked by hand. This is the whole mathematical content of the paper.

the equations · worked

Soften, blend, and the gradient underneath

§2, eq. (1) · softmax with temperature

pi  =  exp( zi / T )Σj exp( zj / T )

read aloud: divide every raw score by T before exponentiating, then normalize. Big T shrinks the differences between scores, so the exponentials come out closer together — the tall bar falls, the whispers rise. T = 1 is the ordinary softmax.

  • zithe logit — the model's raw, pre-probability score for class i
  • Tthe temperature — training uses the same warm T for teacher and student; serving resets to 1
  • pithe resulting probability for class i
plug in → logits z = (6, 3, 0). at T=1: p ≈ (0.950, 0.047, 0.002) — the runner-up is nearly invisible. at T=4: z/T = (1.5, 0.75, 0) → p ≈ (0.590, 0.279, 0.132). same knowledge, now loud enough to teach; the winner never changes.

§2 · the two-part training loss

ℒ  =  α · T2 · H( pteacher(T), pstudent(T) )  +  (1−α) · H( y, pstudent(1) )

read aloud: a weighted sum of "match the teacher's softened distribution" and "match the true label at normal temperature". The first term copies the dark knowledge; the second keeps the student anchored to ground truth.

  • H(a, b)cross-entropy: how badly distribution b predicts distribution a
  • αthe blend — how much teacher vs. how much truth
  • T2the compensation factor: softening at T shrinks the soft-target gradients by ~1/T², so the loss is scaled back up by T² to keep the two signals comparable
  • ythe one-hot ground-truth label

§2.1 · the gradient, and the high-temperature limit

∂C∂zi  =  1T ( qi − pi )    →   1T2 ( zivi )   as T grows large

read aloud: the student's gradient on each logit is simply "teacher's probability minus mine" — and when T is large, that reduces to "teacher's raw logit minus mine". High-temperature distillation is, in the limit, plain regression on the teacher's logits: the student is fitted to the full geometry of the teacher's scores, not to a single winning answer.

  • qi, vithe teacher's softened probability and raw logit for class i
  • pi, zithe student's — the quantities being trained
  • Nthe number of classes
plug in → teacher says q = 0.28 for the "3", student says p = 0.05: gradient ∝ 0.28 − 0.05 = +0.23 — a real push toward an answer the one-hot label calls simply "wrong". that push is the dark knowledge flowing.

part five · what we take from it

Distillation in a sovereign system

applied · our reading

A specialist you can own

This 2015 paper is the root of every "small model, big-model quality" result since — and it's directly load-bearing for the work we do. A frontier model has judgment about tax law that a small model can't learn from scratch. Distillation is the bridge: let the big model answer your own questions, and train a small, on-premise student on the full shape of those answers.

The student ends up small enough to run inside your boundary, cheap enough to serve at scale, and carrying much of the teacher's judgment — the precondition for a sovereign specialist that never phones home.

the caveat we would flag Distillation copies the teacher's judgment including its mistakes, and a confident-but-wrong soft target is a very persuasive teacher. In a regulated domain, distil on curated, verified questions and keep the hard-label loss anchored to ground truth — so the teacher's errors can't launder themselves into the student as fact.

next in the arc

Where this goes

Distillation copies a model into a smaller one. The next two entries in making models smaller come at the same goal from other directions: the Lottery Ticket Hypothesis finds the small network already hiding inside the big one, and LoRA fine-tunes by adding a thin adapter instead of moving the weights at all. All three are answers to the same question: how little is actually necessary?

source

Geoffrey Hinton, Oriol Vinyals, Jeff Dean — Google (2015). Distilling the Knowledge in a Neural Network. arXiv:1503.02531. The MNIST and "omitted 3s" results are the paper's; the toy digit distributions and the temperature arithmetic are our own illustration.

← back to the knowledge base  ·  ⚙ the illustrated decoder  ·  ▶ run the forward pass

attention.sh — a division of Jinacode Systems. Transformers, fine-tuning, and sovereign LLMs.
we're hiring the curious — hello@attention.sh