arXiv(opens in a new tab)Computer ScienceAug 2019Cited by 1 paper on PaperVantage

Manuscript Offprint

arXiv:1908.09355

Patient Knowledge Distillation for BERT Model Compression

S. Sun, Yu Cheng, Zhe Gan, Jingjing Liu

Abstract

Pre-trained language models such as BERT have proven to be highly effective for natural language processing (NLP) tasks. However, the high demand for computing resources in training such models hinders their application in practice. In order to alleviate this resource hunger in large-scale model training, we propose a Patient Knowledge Distillation approach to compress an original large model (teacher) into an equally-effective lightweight shallow network (student). Different from previous knowledge distillation methods, which only use the output from the last layer of the teacher network for distillation, our student model patiently learns from multiple intermediate layers of the teacher model for incremental knowledge extraction, following two strategies: (ii) PKD-Last: learning from the last kk layers; and (iiii) PKD-Skip: learning from every kk layers. These two patient distillation schemes enable the exploitation of rich information in the teacher’s hidden layers, and encourage the student model to patiently learn from and imitate the teacher through a multi-layer distillation process. Empirically, this translates into improved results on multiple NLP tasks with significant gain in training efficiency, without sacrificing model accuracy.

1 Introduction

Language model pre-training has proven to be highly effective in learning universal language representations from large-scale unlabeled data. ELMo Peters et al. (2018), GPT Radford et al. (2018) and BERT Devlin et al. (2018) have achieved great success in many NLP tasks, such as sentiment classification Socher et al. (2013), natural language inference Williams et al. (2017), and question answering Lai et al. (2017).

Despite its empirical success, BERT’s computational efficiency is a widely recognized issue because of its large number of parameters. For example, the original BERT-Base model has 12 layers and 110 million parameters. Training from scratch typically takes four days on 4 to 16 Cloud TPUs. Even fine-tuning the pre-trained model with task-specific dataset may take several hours to finish one epoch. Thus, reducing computational costs for such models is crucial for their application in practice, where computational resources are limited.

Motivated by this, we investigate the redundancy issue of learned parameters in large-scale pre-trained models, and propose a new model compression approach, Patient Knowledge Distillation (Patient-KD), to compress original teacher (e.g., BERT) into a lightweight student model without performance sacrifice. In our approach, the teacher model outputs probability logits and predicts labels for the training samples (extendable to additional unannotated samples), and the student model learns from the teacher network to mimic the teacher’s prediction.

Different from previous knowledge distillation methods Hinton et al. (2015); Sau and Balasubramanian (2016); Lu et al. (2017), we adopt a patient learning mechanism: instead of learning parameters from only the last layer of the teacher, we encourage the student model to extract knowledge also from previous layers of the teacher network. We call this ‘Patient Knowledge Distillation’. This patient learner has the advantage of distilling rich information through the deep structure of the teacher network for multi-layer knowledge distillation.

We also propose two different strategies for the distillation process: (ii) PKD-Last: the student learns from the last kk layers of the teacher, under the assumption that the top layers of the original network contain the most informative knowledge to teach the student; and (iiii) PKD-Skip: the student learns from every kk layers of the teacher, suggesting that the lower layers of the teacher network also contain important information and should be passed along for incremental distillation.

We evaluate the proposed approach on several NLP tasks, including Sentiment Classification, Paraphrase Similarity Matching, Natural Language Inference, and Machine Reading Comprehension. Experiments on seven datasets across these four tasks demonstrate that the proposed Patient-KD approach achieves superior performance and better generalization than standard knowledge distillation methods Hinton et al. (2015), with significant gain in training efficiency and storage reduction while maintaining comparable model accuracy to original large models. To the authors’ best knowledge, this is the first known effort for BERT model compression.

References (14)