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

Victor Sanh, Lysandre Debut, Julien Chaumond, Thomas Wolf
10/2/2019
cs.CL

Official code: huggingface/transformers (162,097 stars, Apache-2.0, PyTorch, last commit 2026-04-30). 1 more implementation below.

Abstract

As Transfer Learning from large-scale pre-trained models becomes more prevalent in Natural Language Processing (NLP), operating these large models in on-the-edge and/or under constrained computational training or inference budgets remains challenging. In this work, we propose a method to pre-train a smaller general-purpose language representation model, called DistilBERT, which can then be fine-tuned with good performances on a wide range of tasks like its larger counterparts. While most prior work investigated the use of distillation for building task-specific models, we leverage knowledge distillation during the pre-training phase and show that it is possible to reduce the size of a BERT model by 40%, while retaining 97% of its language understanding capabilities and being 60% faster. To leverage the inductive biases learned by larger models during pre-training, we introduce a triple loss combining language modeling, distillation and cosine-distance losses. Our smaller, faster and lighter model is cheaper to pre-train and we demonstrate its capabilities for on-device computations in a proof-of-concept experiment and a comparative on-device study.

View on arXivView PDF

Code Implementations(2)

PyTorchApache-2.0

🤗 Transformers: the model-definition framework for state-of-the-art machine learning models in text, vision, audio, and multimodal models, for both inference and training.

162,09733,718Shell, PythonOct 29, 20185 months agoApache-2.0
audiodeep-learningdeepseekgemmaglm+14 more
Apache-2.0

Swift Core ML 3 implementations of GPT-2, DistilGPT-2, BERT, and DistilBERT for Question answering. Other Transformers coming soon!

1,682173Swift, PythonJun 27, 20192 years agoApache-2.0

Similar Papers

Cite this paper

@article{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.01108}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/1910.01108.svg)](https://codeofpaper.com/paper/1910.01108)

Discussion