Profile

Settings

Loading…

← Papers

Help

FAQ

Which features require signing in?

You can read the commentary, paper info, Model Structure and related papers of public papers without signing in. Sign in to manage your account or contact us about your inquiries.

Can I upload a PDF file?

Upload papers with an arXiv or DOI link; the commentary is public to everyone. Papers whose source and terms of use can't be verified, so the commentary can't be made public, can't be uploaded. Uploading PDF files and keeping papers private are for subscribers only, and a paper uploaded as a file is saved as private only. Searching for official info by title runs only when you press the button.

Are the figures and AI commentary accurate?

Figures come only from the original paper, and only those whose terms of use are verified are shown. The commentary is written by AI and may be wrong. Check important claims, numbers and figure context against the evidence in the original paper.

I want to report a copyright issue.

Terms of use and the source of the original paper are on the Paper info tab. If there's a problem, choose "Paper content, figures and copyright" under Contact us and send the paper link, the part in question, and evidence that you hold the rights. Receiving your report doesn't confirm any rights or remove anything right away. You can see the result of the review under My inquiries.

I forgot my password.

If you signed up with email, use Forgot password in the sign-in window to reset it with your verified email. If you signed up with Google, Naver or Kakao, change your password with that service.

What should I include in an inquiry?

Tell us which screen you were on and what you were doing when the problem happened, along with the paper link. Don't include personal information such as passwords, API keys, verification codes or phone numbers. Inquiries and replies are stored in Refivu and you can see them under My inquiries.

How do I delete my account?

In Settings, under My account, press Delete account. Review what will be deleted and complete identity verification to delete your account. For other requests, choose "Account" under Contact us.

Paper commentary

DistilBERT, a distilled version of BERT: smaller, faster, cheaper and lighter

  • Problem Large pre-trained Transformer language models are costly to train, store and run, which makes on-device use difficult.
  • Method Pre-trains a smaller student with a triple loss that combines masked language modeling, a distillation term over teacher soft targets and a cosine term on hidden states, and initializes the student from alternating teacher layers.

Why shrink a pre-trained language model

Pre-trained language models with several hundred million parameters have become a default starting point for many NLP tasks, and larger models tend to keep improving downstream results. The figure of parameter counts across recently released pretrained language models makes the growth in model size visible at a glance. Two costs follow from this growth: the energy needed to train ever-larger models, and the memory and computation that prevent running them on a device in real time.

The study asks whether a much smaller general-purpose model can be pre-trained so that it stays useful after fine-tuning. Most earlier distillation work targeted individual downstream tasks, whereas here distillation is applied while the model itself is pre-trained. The resulting model, DistilBERT, is reported as 40% smaller than BERT, keeping 97% of its language understanding and running 60% faster.

The later sections test the same model on benchmark accuracy, on speed and size, and on a mobile question answering application.

Learning from a teacher's full output distribution

A standard supervised objective pushes the predicted distribution toward one-hot gold labels, but the small probabilities that the model assigns to the wrong classes carry information about how well it generalizes.

The distillation term is written as \( L_{ce} = \sum_i t_i \log(s_i) \), where \( t_i \) is the probability the teacher assigns to class i and \( s_i \) the probability the student assigns to it. Both probabilities come from a softmax with temperature, \[ p_i = \frac{\exp(z_i/T)}{\sum_j \exp(z_j/T)} \] where \( z_i \) is the model score for class i and a larger T smooths the distribution.

The same temperature is used for teacher and student during training, and T is set to 1 at inference, which gives a standard softmax again.

The final objective is a linear combination of the distillation term with the masked language modeling loss, \( L_{mlm} \), which is the supervised part. A cosine embedding loss, \( L_{cos} \), is added because it pulls the directions of the student and teacher hidden-state vectors toward each other. Together these three terms form the triple loss used for pre-training.

Halving the depth and starting from the teacher

Linear layers and layer normalisation are heavily optimized in current linear algebra frameworks, so changing the hidden size costs less computation time than changing the number of layers at a fixed parameter budget, according to the authors' investigation. Reducing depth is therefore the lever chosen to shrink the model.

Initialization matters for the sub-network to converge, and the student shares its dimensionality with the teacher. The assumption behind this step is the common dimensionality of the two networks.

Pre-training data and compute

Training follows recent best practices for BERT pre-training: very large batches formed by gradient accumulation, up to 4K examples per batch, dynamic masking, and no next sentence prediction objective.

Pre-training ran on 8 16GB V100 GPUs for approximately 90 hours. The authors set this against RoBERTa, which they report required 1 day of training on 1024 32GB V100 GPUs, but the two runs use different hardware and budgets, so this is a reference point rather than a controlled comparison.

GLUE development set results

The evaluation uses the GLUE development sets, with each task fine-tuned without ensembling or multi-task fine-tuning. The ELMo baseline is an ELMo encoder followed by two BiLSTMs, with scores reported by the GLUE authors, whereas BERT-base and DistilBERT are medians of 5 runs with different seeds.

DistilBERT reaches a macro-score of 77.0 on the nine tasks, against 79.5 for BERT-base and 68.7 for ELMo. Table 1 lists the per-task scores behind these macro-scores.

Against ELMo, DistilBERT scores higher on seven of the nine tasks and ties on WNLI at 56.3. It is slightly lower on SST-2, at 91.3 against 91.5, and the largest margin is on STS-B, where the text puts the gap at up to 19 points of accuracy. Because the ELMo numbers are the GLUE authors' reported values rather than re-runs under the same seeds, the ELMo comparison is less controlled than the BERT-base one.

IMDb and SQuAD after fine-tuning

Table 2 reports IMDb test accuracy: DistilBERT reaches 92.82, against 93.46 for BERT-base.

On SQuAD 1.1 dev EM/F1, DistilBERT reaches 77.7/85.8, against 81.2/88.5 for BERT-base. The text places DistilBERT within 3.9 points of the full BERT model.

A second distillation step is added during fine-tuning, in which a BERT model already fine-tuned on SQuAD acts as an extra teacher term in the loss. This variant is reported as DistilBERT (D) at 79.1/86.9 EM/F1 in Table 2, while the text gives 79.8 F1 and 70.4 EM for the same setting, so the two reports do not agree.

Inference speed, size and on-device latency

Parameter counts are 180 million for ELMo, 110 million for BERT-base and 66 million for DistilBERT. The corresponding times are 895 seconds for ELMo, 668 seconds for BERT-base and 410 seconds for DistilBERT.

The timing runs on an Intel Xeon E5-2690 v3 Haswell CPU at 2.9GHz. DistilBERT has 40% fewer parameters than BERT and is 60% faster at inference under this protocol.

For on-device use, the authors built a question answering application for an iPhone 7 Plus and compared it with their previously trained BERT-base question answering model. The authors note that the size could be reduced further with quantization, which they did not apply in this comparison.

Which loss terms and initialization matter

Table 4 reports changes relative to the full triple loss with teacher weights initialization, measured as the GLUE macro-score. Removing the distillation loss changes the macro-score by -2.96, removing the cosine embedding loss changes it by -1.46, and removing the masked language modeling loss changes it by -0.31. Because a higher macro-score is better, each of these numbers is a decline when the component is removed.

The authors describe the masked language modeling term as having little impact, while the two distillation terms account for a large part of the performance. Replacing the teacher-based initialization with random weights changes the macro-score by -3.69 relative to the full triple loss. Each axis is reported only as a single macro-score change, so the table says nothing about individual GLUE tasks.

Position against other distillation work

Several earlier studies distill a fine-tuned BERT into a task-specific network, for example into an LSTM-based classifier or a smaller Transformer for reading comprehension. The authors found it beneficial to use general-purpose pre-training distillation instead, and to let the student learn from the teacher during pre-training.

Multi-distillation work combines an ensemble of teachers through multi-task learning, and a multilingual model has been pre-trained solely through distillation. The authors report that, in their ablation, using the teacher through initialization and additional losses gives substantial gains. Pruning attention heads and quantization are treated as orthogonal to this work.

Limitations

The GLUE comparison uses development sets, and BERT-base and DistilBERT scores are medians of 5 runs with different seeds, while ELMo scores are taken from the GLUE authors. Downstream results are single tables of IMDb test accuracy and SQuAD dev EM/F1 without per-run spread.

Speed is measured on one CPU setting with batch size 1 and on one iPhone 7 Plus question answering comparison. Quantization and pruning are not combined with DistilBERT in these experiments.

The SQuAD second-distillation result has two values in the paper, 79.1/86.9 EM/F1 in Table 2 and 79.8 F1 and 70.4 EM in the text. The RoBERTa training cost is a reference from another hardware setup and is not measured against DistilBERT under the same conditions.

Paper info

Authors
Victor Sanh, Lysandre Debut, Julien Chaumond, Thomas Wolf
Venue
arXiv · Preprint
First published
2019-10-2
Added
2026-10-20
Updated
2020-3-1
Version
v4
arXiv
1910.01108
Category
cs.CL
Original paper terms
arXiv non-exclusive 1.0
What we show
Paper info and commentary

AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.

Quote from the paper

Victor Sanh, Lysandre Debut, Julien Chaumond, Thomas Wolf (2019). DistilBERT, a distilled version of BERT: smaller, faster, cheaper and lighter. arXiv:1910.01108v4. https://arxiv.org/abs/1910.01108v4

BibTeX
@misc{sanh2019distilbert,
  title = {{DistilBERT, a distilled version of BERT: smaller, faster, cheaper and lighter}},
  author = {Victor Sanh and Lysandre Debut and Julien Chaumond and Thomas Wolf},
  year = {2019},
  eprint = {1910.01108},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1910.01108v4}
}

See related papersBrowse other papers

Paper preview
Account security

Connect Google account

If you connect a Google account, you can sign in with it too.

Refivu

Delete account

Refivu
Refivu

Sign up