Abstract
TinyBERT introduces a specialized "Transformer distillation" method and a two-stage learning framework to compress the massive BERT model into a lightweight version. The resulting 4-layer model is 7.5x smaller and 9.4x faster than BERT$_{BASE}$ while retaining over 96% of its performance on the GLUE benchmark.
Introduction
Large-scale pre-trained language models like BERT have revolutionized Natural Language Processing (NLP), but they come with a massive "computational tax." With hundreds of millions of parameters, these models are too slow and memory-intensive to run on resource-constrained edge devices like smartphones or IoT hardware.
While techniques like pruning and quantization exist, Knowledge Distillation (KD)—where a large "teacher" model trains a small "student" model—is particularly promising. However, previous KD attempts for BERT often focused only on the final outputs (logits). The authors of TinyBERT argue that to truly capture BERT's power, the student needs to learn from the rich internal structures of the Transformer layers themselves.
Methodology
The authors propose a novel Transformer Distillation method that targets three specific parts of the model: embedding layer distillation, transformer-layer distillation (mimicking attention matrices and hidden states), and prediction-layer distillation.
To implement this, they introduce a Two-Stage Learning Framework:
- General Distillation: The student learns from a "raw" BERT on a massive general-domain corpus (like Wikipedia) to gain a broad understanding of language.
- Task-Specific Distillation: The student learns from a fine-tuned BERT on a specific task. To assist the small model, a Data Augmentation technique is used, creating more training examples by replacing words with synonyms suggested by BERT and GloVe.
Experimental Results
TinyBERT was evaluated on the GLUE benchmark and the SQuAD datasets. The results demonstrate that TinyBERT achieves significant efficiency gains without sacrificing substantial accuracy.
As shown in the results table, TinyBERT$_4$ (4 layers) has only 14.5M parameters and achieves a 9.4x speedup in inference time. On the GLUE benchmark, it achieved an average score of 77.0, significantly outperforming other 4-layer competitors like DistilBERT (71.9) and BERT-PKD (72.6). Furthermore, the 6-layer version, TinyBERT$_6$, performed on-par with the full BERT$_{BASE}$ teacher (79.4 vs 79.5 average score).
Analysis and Discussion
Several key insights emerged from the study:
- Attention is the Key: Distilling the attention matrices is more effective than distilling hidden states alone, suggesting that the linguistic relationships captured by attention are BERT's most valuable knowledge.
- The Two-Step Process is Essential: Skipping general distillation significantly hurts performance; a general foundation is required before task specialization.
- Data Augmentation as a Bridge: By expanding the task-specific dataset, the authors provide the student with more training signal to reach the teacher's level of accuracy despite lower capacity.
Conclusion
TinyBERT represents a major step in making powerful NLP models accessible for mobile devices. Future work may involve distilling even larger models like RoBERTa, combining distillation with other compression techniques like quantization, or exploring automated layer mapping strategies to further optimize performance.
Summary updated