DistilBERT
BERT works, and then you try to serve it. A 110-million-parameter encoder scoring every keystroke in a search box becomes a hosting bill and a latency problem. DistilBERT is Hugging Face's answer: a smaller BERT trained to imitate the original rather than trained from scratch.
Learning from a teacher
The method is knowledge distillation. A student with half the layers — six instead of twelve, initialised from every second layer of the teacher — is pre-trained on the same corpus against a three-part loss:
- Distillation loss — match the teacher's full output distribution, not just the correct token. The teacher's near-misses say which other words were plausible, and that signal is richer than the label alone.
- Masked language modeling loss — the standard objective, kept.
- Cosine embedding loss — align the student's hidden states with the teacher's, direction by direction.
Next-sentence prediction and the token-type embeddings are dropped entirely.
What you get, what you give up
The result is roughly 40% smaller and about 60% faster at inference while retaining some 97% of BERT's GLUE score. Fine-tuning behaves exactly as it does for BERT, and distilbert-base-uncased is a one-line substitution in Hugging Face Transformers. The lost accuracy shows up on tasks needing deeper reasoning over longer inputs rather than on sentence classification — span prediction on SQuAD degrades more than sentiment labelling does. When a couple of points are worth a halved latency budget, this is the default starting point; when they are not, start from RoBERTa.
DistilBERT is a compressed BERT produced by knowledge distillation: a six-layer student is pre-trained to match the full model's output distribution and hidden states, giving roughly 40% fewer parameters and about 60% faster inference while keeping some 97% of BERT's GLUE performance. It matters wherever latency or memory binds — on-device and high-traffic serving — and it fine-tunes as a drop-in replacement.
Imagine a long-winded professor, and a student who sits through every lecture and boils it down to a tight set of revision notes. The notes are shorter, quicker to read, and still get almost every answer right.
DistilBERT is that student. It was trained to copy the answers of a larger language model, BERT, and ended up around 40% smaller and nearly twice as fast while keeping most of the accuracy. That matters because the big model is costly to run — too slow for a phone, or for a site sorting thousands of customer messages a minute. DistilBERT gives you most of the understanding for a fraction of the computing power.