Training Foundations

Knowledge Distillation

How a tiny model that runs on your phone can inherit the wisdom of a giant it could never hope to be — by learning from its teacher’s doubts, not just its answers.

Prerequisites: Softmax turns logits into probabilities + Cross-entropy is the classification loss. That’s it.
10
Chapters
9+
Simulations
0
Assumed Knowledge

Chapter 0: The Giant That Won’t Fit

You have trained a magnificent model. It is huge — hundreds of millions of parameters — and it is brilliant, topping every benchmark. Now you need to run it on a phone, or serve it to a million users at once, or fit it under a ten-millisecond latency budget. And it simply will not fit. The giant is too slow, too big, too hungry for memory.

The obvious move is to just train a small model from scratch instead. You try it. It's fast enough — and noticeably dumber. The small model, learning alone from the raw labels, lands well short of the giant's accuracy. There seems to be a hard tradeoff: small and fast, or large and smart. Pick one.

Knowledge distillation breaks that tradeoff. The idea, introduced by Geoffrey Hinton and colleagues in 2015, is disarmingly simple: don't train the small model on the raw labels. Train it to imitate the big model. Let the giant be a teacher and the small model be a student, and have the student learn not just the teacher's final answers but the full, nuanced distribution behind them. The student ends up far smarter than it could ever have become on its own.

The one-sentence version. A trained teacher's output probabilities contain far more information than a one-word label — they encode how the teacher thinks, including its doubts and the relationships it sees between classes. Distillation transfers that rich signal into a small student, so the student inherits the teacher's judgment without its size.

Hard labels vs. soft labels

Here is the crux, and it's worth slowing down for. Suppose the teacher looks at a handwritten digit that happens to be a 7. The true label is the one-hot vector: 100% on “7,” 0% on everything else. That is the hard label — it's all the raw dataset gives you.

But the teacher's actual output is richer. It might say: 90% “7,” 6% “1,” 3% “9,” and a sprinkle elsewhere. That is a soft label. And look at what it's telling you: this 7 looks a little like a 1 (they share a vertical stroke) and a little like a 9, but nothing at all like a 0 or a 5. The teacher has encoded the geometry of the classes — which digits resemble which — into those small non-zero numbers.

The hard label throws all of that away. The soft label keeps it. Training the student to match the soft label teaches it not just “this is a 7” but “this is a 7 that's a bit 1-ish” — a vastly more informative lesson. Hinton called this hidden signal dark knowledge.

See it: how much one label throws away

The widget shows the same digit two ways. Toggle between the hard one-hot label and the teacher's soft distribution. Notice how much structure the soft version carries — mass leaking onto the visually-similar digits — and how the hard label is a lonely single spike that says nothing about why.

Hard Label vs. Soft Label: What Gets Thrown Away

The same example, labeled two ways. Toggle to see the dark knowledge the one-hot label discards — the teacher's sense of which classes resemble this one.

Common misconception. “The student just needs the right answers, so hard labels should be enough.” Hard labels are impoverished: they say what, never how-similar-to-what. The soft label's tiny 6% on “1” is not noise — it is a lesson about the shape of the problem that a one-hot label can never deliver. That extra signal is precisely what lets a small student punch above its weight.
Why does a teacher's soft output distribution teach a student more than the dataset's hard one-hot label?

Chapter 1: Dark Knowledge — The Information in the Wrong Answers

Let's make “dark knowledge” precise, because it is the entire reason distillation works. The claim is that the relative probabilities the teacher assigns to the incorrect classes carry the most valuable signal — sometimes more than the correct class itself.

Consider a model trained to recognize vehicles. Shown a photo of a truck, a good teacher outputs something like: 88% truck, 11% bus, 0.9% car, 0.05% bicycle, 0.001% banana. Strip away the correct answer (truck) and look at what remains: the teacher is screaming that this thing is way more bus-like than car-like, and not remotely fruit-like. That ranking — bus > car > bicycle > banana — is a compressed encyclopedia of how the visual world is organized.

The wrong answers are a similarity map. Every soft label is implicitly a row of a giant similarity matrix between classes. The teacher spent enormous compute discovering that matrix. Distillation lets the student download it for free, one example at a time, instead of having to rediscover it from scratch with its limited capacity.

Why a small model can't find this alone

Trained on hard labels, the student only ever hears “truck” — a single bit of feedback per example. To learn that trucks resemble buses, it would have to infer that relationship indirectly, from many examples, using capacity it doesn't have to spare. The teacher, being huge, did have the capacity to discover these relationships. Distillation is a capacity transplant: the student borrows conclusions the teacher could afford to compute.

The problem dark knowledge creates

There is a catch, and it sets up the next chapter. A well-trained teacher is confident. On an easy truck image it might output 99.9% truck and split the remaining 0.1% among everything else. Those wrong-class probabilities are now so vanishingly small that the dark knowledge — the bus-vs-car ranking — is buried in numerical dust. The student, trained on this, sees essentially a hard label again. The very confidence that makes the teacher good has hidden its most useful signal.

So we need a way to amplify the small differences among the wrong-class probabilities — to turn up the contrast on the dark knowledge so the student can actually see it. That tool is temperature, and it's the subject of the next chapter.

See it: the hidden ranking

Pick a class. The widget shows the teacher's full soft distribution, then lets you zoom into just the wrong-class probabilities (the log-scale view reveals the ranking buried under the dominant correct class). The hidden structure — what resembles what — pops out.

Reveal the Dark Knowledge

Pick the true class. Toggle to a log-scale view of the wrong-class probabilities to see the similarity ranking the teacher has hidden in the small numbers.

True class truck
Common misconception. “A confident teacher is the best teacher.” For distillation, an over-confident teacher can be a worse teacher, because its soft labels collapse toward one-hot and the dark knowledge vanishes. The art is coaxing out the teacher's nuanced uncertainty — which is exactly what temperature does.
A teacher outputs 99.9% on the correct class. Why is this a problem for distillation?

Chapter 2: Temperature — Turning Up the Contrast on Dark Knowledge

We ended the last chapter with a problem: a confident teacher buries its dark knowledge under a near-one-hot peak. We need to soften the teacher's distribution — spread some probability off the winner and onto the runners-up — so the student can see the relationships. The tool is the same temperature knob from the softmax, but here it plays a completely different role than it did in contrastive learning.

Recall how softmax works: it exponentiates the logits (the raw pre-softmax scores) and normalizes. Temperature divides the logits before exponentiating. A temperature of 1 is the normal softmax. A higher temperature shrinks the gaps between logits, so the exponentials come out closer together, and the distribution softens — probability flows from the peak onto the smaller classes, lifting the dark knowledge into view.

Opposite job from contrastive temperature. In contrastive learning we used low temperature to sharpen and fixate on hard negatives. In distillation we use high temperature to soften and expose the teacher's full opinion. Same mechanism, opposite goal: there we wanted decisiveness, here we want the teacher to reveal its doubts so the student can learn from them.

Worked example: softening a teacher by hand

A teacher outputs these logits for a truck image: truck 6.0, bus 4.0, car 2.0, bike 0.0. Let's compute the softened distribution at two temperatures.

At temperature 1 (normal softmax): exponentiate the raw logits.

classlogitelogitprobability
truck6.0e6 = 403403/466 = 0.865
bus4.0e4 = 54.654.6/466 = 0.117
car2.0e2 = 7.397.39/466 = 0.016
bike0.0e0 = 1.01.0/466 = 0.002

The total is 403 + 54.6 + 7.39 + 1.0 = 466. The truck dominates at 86.5%, and car and bike are nearly invisible — their dark knowledge is buried.

At temperature 4: first divide every logit by 4, giving 1.5, 1.0, 0.5, 0.0.

classlogit / 4e(·)probability
truck1.50e1.5 = 4.484.48/9.85 = 0.455
bus1.00e1.0 = 2.722.72/9.85 = 0.276
car0.50e0.5 = 1.651.65/9.85 = 0.167
bike0.00e0.0 = 1.001.00/9.85 = 0.102

Total 9.85. Now look: the truck's lead has shrunk to 45.5%, and the ranking bus > car > bike is loud and clear — 27.6%, 16.7%, 10.2%. The dark knowledge that was buried at temperature 1 is fully exposed at temperature 4. That softened distribution is what we hand to the student as its target.

The matching-temperature trick

One crucial detail: during distillation, we soften both the teacher and the student with the same temperature before comparing them. The student's logits also get divided by the temperature, so it learns to reproduce the softened teacher distribution. At inference time, the student goes back to temperature 1 and makes normal, confident predictions. The high temperature is a teaching aid used only during training — like a teacher slowing down and over-explaining, then expecting normal-speed work on the exam.

See it: softening the teacher

Sweep the temperature. At 1 the distribution is peaked and the dark knowledge is hidden. Crank it up and watch probability flow off the winner onto the related classes, revealing the teacher's full opinion. Too high, and it flattens toward uniform — the dark knowledge drowns in noise. There is a sweet spot, usually between 2 and 10.

Temperature: Softening the Teacher's Distribution

The teacher's softened output as temperature rises. Low = peaked (dark knowledge hidden); high = soft (revealed); too high = flat (drowned). Find the sweet spot.

Temperature T 4.0

Common misconception. “Higher temperature is always better — more dark knowledge revealed.” Past the sweet spot, the distribution flattens toward uniform and the real ranking gets swamped by amplified noise from truly irrelevant classes. You're then teaching the student that a truck is somewhat banana-like. Temperature reveals structure up to a point, then destroys it.
In distillation we raise the temperature, but in contrastive learning we lowered it. Why the opposite?

Chapter 3: The Distillation Loss — Two Teachers in One

We have softened teacher targets. Now: what loss do we actually minimize? The student has two sources of truth, and the distillation loss blends them. The first is the teacher's softened distribution (the dark knowledge). The second is the real ground-truth label (the dataset's hard answer, which the teacher might occasionally get wrong). A good student listens to both.

The two terms

Soft term — match the teacher. We measure how far the student's softened distribution is from the teacher's softened distribution using the KL divergence — a standard measure of how different two probability distributions are, zero when identical, growing as they diverge. Minimizing it pulls the student's full distribution (including dark knowledge) toward the teacher's.

Hard term — match the truth. The ordinary cross-entropy between the student's normal (temperature-1) output and the real one-hot label. This anchors the student to the actual correct answers, so it doesn't blindly inherit the teacher's mistakes.

The total distillation loss is a weighted sum of the two, controlled by a mixing weight (call it alpha): alpha times the soft term, plus one-minus-alpha times the hard term. Alpha near 1 means “trust the teacher almost entirely”; alpha near 0 means “basically ignore the teacher and train normally.” Typical recipes lean heavily on the soft term — alpha around 0.9 — because the dark knowledge is the whole point.

The mysterious T-squared factor. There's one more piece. The soft term is multiplied by the temperature squared. Here's why, and it's a lovely detail: when you soften logits by dividing by temperature T, the gradients that flow back through that softmax shrink by a factor of roughly T-squared (the softening flattens the slope). If you didn't compensate, the soft term's gradient would be tiny at high temperature and the hard term would dominate. Multiplying the soft term by T-squared exactly cancels this shrinkage, keeping the two terms' gradients on the same scale regardless of the temperature you chose. It's a normalization so your alpha means the same thing at every temperature.

From scratch: the KD loss

python
import torch, torch.nn.functional as F

def kd_loss(student_logits, teacher_logits, labels, T=4.0, alpha=0.9):
    # soft term: match the teacher's SOFTENED distribution (the dark knowledge)
    s_soft = F.log_softmax(student_logits / T, dim=1)
    t_soft = F.softmax(teacher_logits / T, dim=1)
    soft = F.kl_div(s_soft, t_soft, reduction='batchmean') * (T * T)   # ← T² fix

    # hard term: match the real labels at normal temperature
    hard = F.cross_entropy(student_logits, labels)

    return alpha * soft + (1 - alpha) * hard

Trace the data flow: the student's logits are used twice — once divided by T for the soft term, once raw for the hard term. The teacher's logits appear only in the soft term, softened, and detached (no gradient flows into the frozen teacher). Two scalars, T and alpha, control the entire behavior: T sets how much dark knowledge is exposed, alpha sets how much the student trusts the teacher versus the ground truth.

See it: balancing teacher and truth

Slide alpha. The stacked bar shows the two loss components and how the mixing weight shifts emphasis between matching the teacher (soft, teal) and matching the true labels (hard, orange). The readout reminds you what each extreme means.

The KD Loss: Soft (Teacher) + Hard (Truth)

Total loss = alpha × soft (match teacher) + (1−alpha) × hard (match labels). Slide alpha to rebalance. Most recipes use alpha near 0.9.

Mixing weight alpha 0.90
Temperature T (sets T² weight) 4.0

Common misconception. “Just use the soft term — the teacher knows best.” The teacher is imperfect; it makes mistakes the hard label would catch. Dropping the hard term entirely (alpha = 1) means the student can never do better than the teacher and may amplify its errors. The hard term is a tether to reality. Conversely, alpha = 0 throws away the dark knowledge and you're back to plain training. The value lives in the blend.
Why is the soft (teacher-matching) term multiplied by the temperature squared?

Chapter 4: Beyond Logits — Matching Features and Attention

So far the student copies only the teacher's final output. But the teacher is deep, and along the way it builds up rich intermediate representations — edges, then textures, then parts, then objects. Why not have the student match those internal stages too, not just the last one? This is feature-based distillation, and it often transfers more than logits alone.

FitNets: hints from the middle

The pioneering method, FitNets, added hint connections. Pick a layer deep inside the teacher — its activation there is a “hint.” Pick a corresponding layer in the student, and add a loss term that pushes the student's activation at that layer toward the teacher's hint. Now the student is guided not just on the final answer but on how to build up its representation along the way.

The dimension-mismatch fix: a regressor. Here's the practical wrinkle. The teacher is wide (say 512 channels at that layer); the student is narrow (say 128). You can't directly compare a 512-vector to a 128-vector. So FitNets inserts a small trainable regressor — a single layer that maps the student's 128-dim activation up to 512-dim — purely so the comparison is well-defined. Like the projection head in contrastive learning, this regressor is a training-time adapter, discarded at inference. The student's real layer stays narrow.

Attention transfer: match where the model looks

A refinement, attention transfer, says: don't match the full high-dimensional feature maps (hard, and full of detail the student can't hold). Instead, match the attention maps — a compressed summary of where in the image each layer is focusing its energy. For a convolutional layer, you collapse the channels into a single spatial heatmap of activation magnitude: this is the “where is the model looking” map. Teaching the student to look in the same places as the teacher transfers the teacher's spatial priorities cheaply, without forcing an exact feature copy.

The pattern generalizes. People distill relations between examples (does the student preserve which pairs the teacher thinks are similar?), gradients, and more. The unifying idea: the teacher contains many kinds of knowledge — outputs, features, attention, relationships — and each can be a distillation target. Logit matching is just the simplest.

See it: choosing what to transfer

The diagram shows a deep teacher and a shallow student. Click the transfer modes to add matching targets: logits only, then add feature hints (with the regressor bridging the width gap), then add attention transfer. Watch the “knowledge transferred” meter rise as you give the student more of the teacher to imitate.

What Knowledge to Transfer?

Teacher (top, deep) and student (bottom, shallow). Toggle transfer targets and see the matching connections and the richness of transferred knowledge.

Common misconception. “More matching targets always help.” Forcing a small student to exactly reproduce a huge teacher's internal features can over-constrain it — the student lacks the capacity to represent what the teacher does, and chasing an impossible target wastes capacity it needs for the real task. Attention transfer works precisely because it matches a compressed summary, not the raw features. More transfer is better only if the student can actually absorb it.
Why does FitNets insert a small trainable regressor between the student's hint layer and the teacher's hint?

Chapter 5: Self-Distillation — When the Student Is the Teacher

Everything so far assumed the teacher is big and the student is small. So here is a result that should stop you cold: distill a model into another model of the exact same size and architecture, and the student often comes out better than the teacher. No compression, no bigger network — same capacity, higher accuracy. This is self-distillation, and its most famous form is the Born-Again Network.

The recipe: train a model normally. Now train a fresh, identical model using the first one as its teacher (soft labels plus hard labels, just like before). The “born-again” student matches or beats its parent. Repeat — distill the student into a third generation — and accuracy often keeps creeping up for a few rounds before plateauing. Ensemble the generations and you do even better. How can copying yourself make you smarter?

Why it works: soft labels are a smart regularizer

The leading explanation: the teacher's soft labels act as a superior form of regularization. Training on hard one-hot labels pushes the model to be infinitely confident — to drive the correct logit to plus infinity. That's an impossible, overfitting-prone target. The teacher's soft labels instead say “be about 88% sure, and here's how to distribute the rest.” That is a gentler, more achievable, information-rich target that prevents overconfidence and encodes real class structure.

Distillation as learned label smoothing. You may know label smoothing — replacing the one-hot target with, say, 90% on the true class and 10% spread uniformly over the rest. It regularizes and helps. Self-distillation is like label smoothing, except the “smoothing” is not uniform — it's the teacher's learned, example-specific distribution. Instead of spreading 10% blindly, it spreads it intelligently onto the classes that actually resemble this example. It's label smoothing that knows what it's doing.

Online distillation: learn together, no pre-trained teacher

Born-again networks need a fully-trained teacher first — two training runs. Online distillation (or deep mutual learning) skips that. Train two (or more) students simultaneously from scratch, and have each learn from the others' softened outputs as they go. There's no fixed teacher; each model is a peer-teacher for the others. They pool their differing mistakes, and the group converges to better solutions than any would alone — a study group instead of a lecture. This is also how some large-model training pipelines work, where a model distills from an exponential-moving-average copy of itself.

See it: the born-again chain

Press Add generation to distill the current model into a fresh same-size successor. Watch accuracy tick up generation over generation, with diminishing returns, then plateau — and see how an ensemble of all generations beats any single one. The first bar is the original model trained on hard labels alone.

Born-Again Networks: Each Generation Distills the Last

Each bar is a model of identical size, distilled from the one before it. Accuracy climbs with diminishing returns. The final bar is the ensemble of all generations.

Common misconception. “Self-distillation must be a measurement error — you can't beat a model with a copy of itself.” It's real and reproducible, and the reason is subtle: the second model isn't trained on the same targets as the first. It's trained on the first model's softened, structured outputs, which are a better optimization target than raw one-hot labels. Same capacity, better target, better result. The gains are modest and do plateau — but they're real.
A born-again network has the SAME size as its teacher yet often scores higher. What's the leading explanation?

Chapter 6: The Distillation Trainer — See the Knowledge Transfer

Time to watch it happen. A large teacher has already been trained (at full strength, on lots of clean data) and knows the smooth, correct boundary between the two moons. Now we train two identical small students on a tiny, noisy handful of training points — the kind of scarce data where small models struggle:

Press Train and watch the distilled student track the teacher's clean boundary while the from-scratch student thrashes. Then play with temperature and alpha to feel how much each matters.

From-Scratch vs. Distilled (teacher boundary shown faint)

Both small students train on the same few noisy points (large dots). Left: hard labels only. Right: the teacher's soft targets. The faint dashed curve is the teacher's boundary — the distilled student should hug it.

Temperature T 3.0
Trust teacher alpha 0.80

What to take away. The distilled student usually ends with higher test accuracy and a visibly smoother boundary — it borrowed the teacher's generalization. Now break it: set alpha to 0 and the distilled student becomes the from-scratch student (no teacher). Set temperature to 1 and you lose much of the dark knowledge, weakening the transfer. The smoothness you see being inherited is the dark knowledge doing its job.
Common misconception. “Distillation only helps when the student is much smaller.” Here the benefit comes from the quality of the targets, not the size gap — which is exactly why self-distillation (Chapter 5) works at equal size. The teacher's soft labels are simply a better thing to learn from than noisy hard labels, regardless of capacity.

No quiz — the simulator is the test. If you can predict how the distilled student's boundary changes as you drop alpha to zero, you understand distillation.

Chapter 7: DistilBERT & Distilling in Practice

The most famous real-world distillation is DistilBERT (2019). BERT is a large language model; DistilBERT is its distilled student, and the headline numbers became the poster child for the whole technique: roughly 40% smaller, 60% faster at inference, while retaining about 97% of BERT's language understanding. That is an enormous, nearly-free win for anyone deploying models.

The three tricks that made it work

Distilling generative models is different. For a classifier, you match the output distribution on each input. But a language model that generates sequences has a subtlety: matching the teacher's next-token distribution at each step (word-level distillation) is good, but sequence-level distillation — training the student on the teacher's actual generated outputs (beam-search results) — often works better, because it teaches the student the sequences the teacher would really produce, not just per-token probabilities. This is the foundation of modern LLM distillation, where a small model is trained on a large model's generated text.

Practical recipe

A working distillation setup: pick a temperature around 2 to 4, an alpha around 0.5 to 0.9 favoring the soft loss, initialize the student from the teacher when architectures allow, and add a feature/embedding-matching term if the student is deep enough to benefit. Freeze the teacher entirely — it only provides targets, never learns. And always keep a hard-label term as a tether to ground truth.

See it: the compression tradeoff

Drag the student's size. As it shrinks, inference gets faster and the model gets smaller — but retained performance eventually falls off a cliff when the student is too small to hold the teacher's knowledge. DistilBERT's actual operating point is marked: a sweet spot where you bank most of the speed and size wins while keeping nearly all the accuracy.

The Compression Tradeoff (DistilBERT's sweet spot marked)

Shrink the student and watch size, speed, and retained performance trade off. Too small, and performance collapses. The marker shows DistilBERT's choice.

Student size (fraction of teacher) 0.60

Common misconception. “Distillation gives you a free lunch — shrink as much as you want.” There's a capacity floor. Below it, the student simply cannot represent the teacher's function no matter how good the targets are, and performance craters. DistilBERT's 60%-size choice isn't arbitrary; it's near the knee of the curve, past which the accuracy cost outweighs the speed gain. The next chapter digs into exactly when the magic stops working.
How did DistilBERT initialize its student instead of starting from random weights?

Chapter 8: When It Works — and the Capacity-Gap Trap

Distillation is powerful but not unconditional. The honest version of the story has some surprising failure modes, and one of them is genuinely counterintuitive: a better teacher can produce a worse student.

The capacity gap

You would think the strongest possible teacher is the best teacher. Often it isn't. When the teacher is enormously more capable than the student, the gap between them becomes a problem. The teacher's softened distributions encode a function so complex and so sharply-drawn that the tiny student simply lacks the capacity to imitate it. Chasing an impossible target, the student does worse than it would have with a more modest teacher whose outputs it could actually match.

The Goldilocks teacher. Student accuracy, plotted against teacher size, is not monotonic. It rises as the teacher gets better — up to a point — then falls when the teacher becomes too strong for the student to follow. The best teacher for a given student is one whose capability is a comfortable step above the student's, not a galaxy beyond it. “Train the biggest teacher you can and distill from it” is, surprisingly, often wrong.

The fix: teacher assistants

If your teacher is too big for your student, insert a middleman. A teacher assistant is an intermediate-sized model: first distill the giant teacher into the assistant, then distill the assistant into the small student. Each hop crosses a manageable capacity gap. The chain delivers more of the giant's knowledge to the small student than a single impossible leap could. It's the same reason you don't teach a first-grader from a graduate textbook — you go through the grades.

The dark-knowledge debate

Why distillation works is still partly debated, and it's worth knowing the tension. The original story is dark knowledge: the student learns the class-similarity structure in the soft labels. But later work showed that much of the benefit comes from something simpler — the soft labels act as regularization (the label-smoothing view from Chapter 5), and from the soft labels effectively reweighting examples by how confident the teacher is. Both effects are real; their relative importance depends on the setting. The practical takeaway: distillation's gains are robust, but the “why” is a blend of knowledge-transfer and regularization, not one clean mechanism.

SituationDistillation verdict
Deploying a big model on constrained hardwareStrong win — the classic use case
Small / noisy training dataWin — soft labels regularize and denoise
Teacher vastly larger than studentCaution — capacity gap; use a teacher assistant
Generative LLM compressionWin — prefer sequence-level distillation
Teacher barely better than studentMarginal — little knowledge to transfer

See it: the non-monotonic teacher curve

Drag the teacher's size for a fixed small student. Watch the student's accuracy rise, peak, then fall as the teacher grows too powerful — the capacity gap. Toggle the teacher assistant to see how a middleman recovers the lost performance for very large teachers.

A Better Teacher Isn't Always Better

Student accuracy vs teacher size (student size fixed). Note the peak, then the drop. Toggle the teacher assistant to bridge large gaps.

Teacher size 0.50

Common misconception. “The bigger and more accurate the teacher, the better the student.” The capacity gap breaks this. Past a point, a stronger teacher gives the small student a target it cannot represent, and accuracy drops. Matching teacher and student capacities — or bridging them with assistants — matters more than maximizing the teacher.
Why can an extremely large, accurate teacher produce a worse small student than a moderately-sized teacher would?

Chapter 9: Connections & Cheat Sheet

You can now explain the whole arc: why a one-hot label wastes the teacher's wisdom, what dark knowledge is, how temperature exposes it, how the KD loss blends teacher and truth, how to transfer features and attention, why a model can teach a copy of itself, how DistilBERT banked a near-free win, and when the capacity gap makes a better teacher a worse choice. The thread: a trained model's soft outputs are a richer teacher than any label, and learning to imitate them transfers judgment that raw labels cannot.

The variants at a glance

VariantWhat's transferredKey idea
Logit / response (Hinton)softened output distributiondark knowledge via temperature
Feature (FitNets)intermediate activationshint layers + regressor for dim mismatch
Attention transferwhere the model looksmatch compressed attention maps
Self / born-againsame-size soft labelssoft labels as learned regularization
Online / mutualpeers' outputs, liveno pre-trained teacher; learn together
Sequence-levelgenerated sequencesfor generative LLMs; train on teacher's outputs

The cheat sheet

Soft label:  teacher's full probability distribution, not just the argmax
Dark knowledge:  the relative probabilities on the WRONG classes (a similarity map)
Temperature T:  divide logits by T before softmax; HIGH T softens, reveals dark knowledge
KD loss:  alpha · T² · KL(softened teacher ‖ softened student) + (1−alpha) · CE(student, true label)
T² factor:  cancels the ~1/T² gradient shrinkage from softening, keeping terms balanced
Capacity gap:  too-strong teacher → student can't imitate → use a teacher assistant
Typical recipe:  T ≈ 2–4, alpha ≈ 0.5–0.9, freeze teacher, keep a hard-label term

A decision guide

Need a small/fast model from a big one?
Yes → response distillation; init student from teacher if you can.
Teacher vastly bigger than student?
Insert a teacher assistant to bridge the capacity gap.
Distilling a generative LLM?
Prefer sequence-level distillation on the teacher's generated text.
No bigger model, just want a boost?
Self-distillation / born-again — same size, free accuracy.

Where this connects

The one thing to remember. A label tells the student what. A teacher's softened distribution tells it what, and how-much-like-everything-else — and that extra structure is worth more than parameters. Distillation is the art of packaging a giant's judgment into a target a small model can learn from. Get the temperature and the blend right, mind the capacity gap, and a model that fits in your pocket can think almost like the giant it learned from.
You must ship a 10×-smaller model that keeps most of a huge LLM's quality. Which combination is the soundest plan?

“The best teachers are those who show you where to look, but don’t tell you what to see.” — and a soft label, full of doubt and structure, shows a small student exactly where to look.