Skip to content
AI & Machine Learning Medium #distillation#compression

Knowledge Distillation

A small student learns from a big teacher's soft logits. Compression without crashing accuracy.

A free, animated knowledge distillation you can read here or embed on any website, from Scrollchart.

Knowledge Distillation

Knowledge DistillationSoft logits from a large teacher train a small student to near-teacher accuracyinput ximage / tokenTeacher340M params, frozenlogits z_tStudent14 to 66M paramslogits z_ssoftmax(z / T)temperature T = 4softmax(z / T)student soft predsTeacher distribution shapinghard one-hot vs T=1 sharp vs T=4 softcatdogfoxwolfbearhard labelT = 1T = 4 (dark knowledge)Combined lossL = alpha * T^2 * KL(soft_t || soft_s) + (1 - alpha) * CE(y, z_s)alpha ~ 0.7 typicalAccuracy vs parameters0M50M100M200M340Mmodel parameters80%85%90%95%top-1 accuracyteacher 92.4%Teacher 340MDistilled 66MScratch 66MDistilled 14MScratch 14M+6.6 ptsteacherdistilled studenttrained from scratch

Teacher (large model) and student (small) on the same input. Loss combines hard-label cross-entropy with KL divergence on softened logits (temperature T). Trained student approaches teacher accuracy with a fraction of the parameters.

Good for

  • Model compression articles for LLM serving cost reduction
  • Edge deployment guides for mobile and embedded inference
  • ML curriculum on transfer learning and dark knowledge

Source & accuracy

This knowledge distillation is an editorial illustration built to represent the concept accurately. Where it shows figures, they are typical or representative values chosen to make the relationship clear, not a single underlying dataset. The diagram and its explainer are reviewed and maintained centrally, and updated over time as understanding improves.

Learning soft targets from a teacher model

Knowledge distillation trains a small student model to mimic a large teacher model. Rather than matching only the hard labels (dog, cat, bird), the student is trained to match the teacher's probability distributions (soft targets). A teacher might output 0.8 for dog, 0.1 for cat, 0.1 for bird; the student learns to reproduce this softer distribution, not just the winner.

Soft targets carry more information than hard labels. Even incorrect predictions from the teacher carry signal: if the teacher confidently says 'wolf' for a husky, the student learns that huskies are wolf-like, which is useful generalization.

Achieving compression without accuracy loss

A naive small model trained from scratch often loses 5-15% accuracy compared to the teacher. With distillation, that gap shrinks to 1-3%. The student model, though much smaller (1-10x fewer parameters), maintains nearly teacher-level accuracy because the soft targets provide a richer training signal than the original labels alone.

This makes distillation practical for deployment: a 10x smaller model runs faster and uses less memory, with minimal quality loss.

Temperature scaling and loss weighting

The temperature parameter controls softness: high temperature (e.g., 20) makes the teacher's distribution smoother; low temperature (e.g., 1) keeps it sharper. Mixing distillation loss with the original classification loss is also crucial: pure distillation can overfit to the teacher's quirks.

Embed this diagram

Add this animated knowledge distillation to your own site. Copy one line of HTML, or use the embed builder for theme and sizing options.

Reference

What this is
A free, embeddable, animated knowledge distillation for any website.
Who uses it
AI/ML blogs.
How to embed
Copy one line of HTML. No signup. No watermark. Works in WordPress, Webflow, Ghost, Substack, plain HTML.
File size
iframe embed, ~80 KB gzipped (loads on demand, does not block your page paint).
License
Free forever. Editorial explainer text included; updated centrally over time.

Embed format options

Copy the universal HTML snippet, the WordPress shortcode, or an iframe fallback - see the WordPress plugin page for details. Any format keeps the same Core Web Vitals profile and the same explainer text.

Embed snippet
<div data-scrollchart="distillation" data-scrollchart-v="1"></div>
<script src="https://scrollchart.com/embed.js" async></script>

Frequently asked questions

Where can I get a free animated "Knowledge Distillation" for my website?
Scrollchart provides "Knowledge Distillation" as a free, embeddable animated diagram you can add to any website with one line of HTML. No signup is required and there is no watermark. The diagram and its explainer text are served from scrollchart.com, so the embed stays current without any maintenance on your end.
How do I embed a knowledge distillation in a developer or tech blog?
Copy the one-line snippet from the Scrollchart diagram page and paste it into your post HTML. It works in any static site generator, CMS, or hand-coded HTML page. The embed is a thin loader, not an iframe, so the content is fully in your DOM.