JA EN
LearnLarge Language Models
·★ MEMBER·PAPER·9 min read

Knowledge Distillation from Scratch — Copying a Big Model into a Small One

No label ever says "dogs look a bit like cats." A trained model's output does — and that gap is what knowledge distillation harvests. Soft labels, temperature-scaled softmax, where the T² factor comes from, sequence-level and synthetic-data distillation, and how DeepSeek-R1 copied an entire reasoning procedure into smaller models.

ModalitytextTasktraining

Distilling the Knowledge in a Neural Network

Primary source — what this article is built on

undefined2026-08-27

Distilling the Knowledge in a Neural NetworkarXiv:1503.02531Paper page·PDF
Sequence-Level Knowledge DistillationarXiv:1606.07947Paper page·PDF
DistilBERT"arXiv:1910.01108Paper page·PDF
a distilled version of BERT: smallera distilled version of BERT: smaller
fasterfaster
https://arxiv.org/abs/1910.01108"cheaper and lighter
The False Promise of Imitating Proprietary LLMsarXiv:2305.15717Paper page·PDF
DeepSeek-R1: Incentivizing Reasoning Capability in LLMs via Reinforcement LearningarXiv:2501.12948Paper page·PDF

The label doesn't carry what the teacher knows

Picture a four-way image classifier: dog, cat, truck, airplane. A photo of a dog carries the label "dog" — as numbers, (1,0,0,0)(1, 0, 0, 0). That is the entire contents of the dataset for that image.

Now show the same photo to a large, well-trained model. The output might be (0.90, 0.09, 0.005, 0.005)(0.90,\ 0.09,\ 0.005,\ 0.005): it's a dog, though a cat isn't out of the question, and it's certainly not a vehicle. The ratios buried in there — dog:cat at roughly 10:1, dog:truck at 180:1 — appear nowhere in the label. Yet they encode something real that the model absorbed from millions of examples: which categories resemble each other and which don't.

Hinton and colleagues called this dark knowledge. Knowledge distillation is the business of transferring it from a large model (the teacher) into a small one (the student).

The analogy: copying answers vs. copying hesitation

Two students work through the same problem set.

The first looks only at the answer key: question 3 is C. Nothing more. The second also reads the grader's note: the answer is C; a lot of people were torn between B and C; A and D are nowhere close.

The second student extracts far more from the identical set of problems, because "B and C are easy to confuse" is information that exists independently of the correct answer. That is the whole intuition, and it cashes out in two practical ways.

More information per example. A one-hot label transmits a single class index; a teacher's output transmits a number for every class. Training converges on less data, and unlabeled data becomes usable — just run the teacher over it and you have soft labels.

It acts as a regularizer. Teaching "definitely dog, everything else exactly zero" pushes the student toward overconfidence. "Probably dog, cat is plausible" doesn't. It's label smoothing, except the smoothing comes from the teacher's judgment rather than a constant.

The mechanism: blurring the distribution with temperature

There's a catch in using the teacher's output directly. A well-trained model tends to output something like (0.99, 0.009, 0.0009, )(0.99,\ 0.009,\ 0.0009,\ \dots), and the very thing we wanted — whether cat or truck is more dog-like — sits in digits so small that they barely register in the gradient.

The fix is a temperature-scaled softmax: divide the logits (the raw scores that go into the softmax) by TT before normalizing.

pi(T)=exp(zi/T)jexp(zj/T)p_i(T) = \frac{\exp(z_i / T)}{\sum_j \exp(z_j / T)}
(1)

Here ziz_i is the logit for class ii, TT is a positive number called the temperature, and pi(T)p_i(T) is the resulting probability. At T=1T = 1 this is the ordinary softmax. Raising TT shrinks the gaps between the exponentiated terms, flattening the distribution; pushing TT toward zero collapses it into a one-hot vector where only the argmax survives.

Temperature, then, is a dial for how much uncertainty you make the teacher admit. Turn it up to around T=4T = 4 and (0.99,0.009,)(0.99, 0.009, \dots) relaxes into something like (0.6,0.2,0.13,0.07)(0.6, 0.2, 0.13, 0.07) — the buried ranking becomes a training signal with real magnitude.

FIG 1Drag the temperature slider right and the spiky bars flatten out. The point of the move is to make the teacher's second, third and fourth place visible; push it too far and every bar matches, which means the information is gone

The loss: mixing two objectives

The student is told two things at once: match the ground-truth label, and match the teacher's distribution.

L=(1α)LCE(y, pS(1))  +  αT2KL(pT(T)pS(T))\mathcal{L} = (1-\alpha)\,\mathcal{L}_{\mathrm{CE}}\big(y,\ p^{S}(1)\big) \;+\; \alpha\, T^{2}\, \mathrm{KL}\big(p^{T}(T)\,\|\,p^{S}(T)\big)
(2)

The first term is ordinary supervised learning: yy is the true label, pS(1)p^S(1) is the student's output at temperature 1, and LCE\mathcal{L}_{\mathrm{CE}} is cross-entropy. The second is the distillation term, where pT(T)p^T(T) and pS(T)p^S(T) are the teacher's and student's distributions at temperature TT, and KL\mathrm{KL} measures how far apart two distributions are (covered in KL Divergence from Scratch). The mixing weight α\alpha is often set high — 0.9 is common — to lean on the teacher.

In plain words: keep checking your answers, but at the same time keep closing the distance to the teacher's blurred distribution.

This is the most commonly botched line in a distillation implementation. Differentiate the soft loss with respect to a student logit and you get

What's behind this

§

Members-only from here

371 walkthroughs, 26 textbook chapters, 48 student units and 6 close readings — all included for $4.99/mo, with three new explainers every day. Cancel any time; access runs to the end of the period.

Already a member? Sign in to keep reading

References

  1. Distilling the Knowledge in a Neural Network. arXiv:1503.02531Paper page·PDF
  2. Sequence-Level Knowledge Distillation. arXiv:1606.07947Paper page·PDF
  3. DistilBERT. "arXiv:1910.01108Paper page·PDF
  4. a distilled version of BERT: smaller. a distilled version of BERT: smaller
  5. faster. faster
  6. https://arxiv.org/abs/1910.01108". cheaper and lighter
  7. The False Promise of Imitating Proprietary LLMs. arXiv:2305.15717Paper page·PDF
  8. DeepSeek-R1: Incentivizing Reasoning Capability in LLMs via Reinforcement Learning. arXiv:2501.12948Paper page·PDF

This article is written from the source paper above. Where they differ, the original is authoritative.

Comments

Sign in to comment