TinyBERT is a method that, when compressing BERT with knowledge distillation, matches the teacher not only at the final output but also at the embedding layer and at each layer's attention and hidden states, so that even a small 4-layer model reaches accuracy close to BERT-base. It was proposed in 2019 by Jiao, Yin, and colleagues at Huawei Noah's Ark Lab and Huazhong University of Science and Technology (Findings of EMNLP 2020).
Pre-trained language models such as BERT have many parameters and slow inference, which makes them hard to run on devices such as smartphones. Earlier work had already used knowledge distillation to build small students, but because BERT is built in two stages, "pre-training β fine-tuning," the open question was at which stage, and how, to distill.
TinyBERT introduces two ideas.
- Transformer distillation: The layers of the teacher and the student are paired, and the student is trained to match the teacher's embedding-layer output, the attention matrices of multi-head attention, the hidden states of each layer, and the logits of the prediction layer.
- Two-stage learning: General-purpose distillation is performed at the pre-training stage, and at the fine-tuning stage the data are augmented and a second, task-specific distillation is performed.
According to the paper, the 4-layer TinyBERTβ is 7.5x smaller and 9.4x faster than the teacher BERT-base and retains more than 96.8% of the teacher's performance on GLUE. The 6-layer TinyBERTβ performs almost on par with the teacher.

