arXiv(opens in a new tab)Computer ScienceOct 2019Cited by 123 papers on PaperVantageClassic Paper

Manuscript Offprint

arXiv:1910.01108

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

Victor Sanh, Lysandre Debut, Julien Chaumond, Thomas Wolf

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.

1 Introduction

Figure

Figure 1: Parameter counts of several recently released pretrained language models.

The last two years have seen the rise of Transfer Learning approaches in Natural Language Processing (NLP) with large-scale pre-trained language models becoming a basic tool in many NLP tasks (Devlin et al., 2018; Radford et al., 2019; Liu et al., 2019). While these models lead to significant improvement, they often have several hundred million parameters and current research on pre-trained models indicates that training even larger models still leads to better performances on downstream tasks.

The trend toward bigger models raises several concerns. First is the environmental cost of exponentially scaling these models’ computational requirements as mentioned in Schwartz et al. (2019); Strubell et al. (2019). Second, while operating these models on-device in real-time has the potential to enable novel and interesting language processing applications, the growing computational and memory requirements of these models may hamper wide adoption.

In this paper, we show that it is possible to reach similar performances on many downstream-tasks using much smaller language models pre-trained with knowledge distillation, resulting in models that are lighter and faster at inference time, while also requiring a smaller computational training budget. Our general-purpose pre-trained models can be fine-tuned with good performances on several downstream tasks, keeping the flexibility of larger models. We also show that our compressed models are small enough to run on the edge, e.g. on mobile devices.

Using a triple loss, we show that a 40% smaller Transformer (Vaswani et al. (2017)) pre-trained through distillation via the supervision of a bigger Transformer language model can achieve similar performance on a variety of downstream tasks, while being 60% faster at inference time. Further ablation studies indicate that all the components of the triple loss are important for best performances.

We have made the trained weights available along with the training code in the Transformers library from HuggingFace (Wolf et al., 2019).

References (20)

  • Bert: Pre-training of deep bidirectional transformers for language understanding
  • Language models are unsupervised multitask learners
  • Roberta: A robustly optimized bert pretraining approach
  • Energy and policy considerations for deep learning in nlp
  • Attention is all you need
  • Transformers: State-of-the-art natural language processing, 2019
  • Model compression
  • Distilling the knowledge in a neural network
  • Aligning books and movies: Towards story-like visual explanations by watching movies and reading books
  • Glue: A multi-task benchmark and analysis platform for natural language understanding
  • Deep contextualized word representations
  • jiant 1.1: A software toolkit for research on general-purpose text understanding models
  • Learning word vectors for sentiment analysis
  • Squad: 100, 000+ questions for machine comprehension of text
  • Distilling task-specific knowledge from bert into simple neural networks
  • Well-read students learn better: The impact of student initialization on knowledge distillation
  • Model compression with multi-task knowledge distillation for web-scale question answering system
  • Small and practical bert models for sequence labeling
  • Are sixteen heads really better than one? In NeurIPS, 2019
  • Deep learning with limited numerical precision

Cited by (123)