Introduction
Pretrained Language Models (PLMs) like BERT and ERNIE have set new benchmarks across natural language processing (NLP) tasks. However, their massive parameter counts and high computational costs pose significant challenges for deployment on resource-constrained devices. Knowledge Distillation (KD) has emerged as a popular technique to compress these large "teacher" models into smaller "student" models.
Despite its success, traditional KD often suffers from distillation discrepancy. This occurs when there is an abrupt shift from general pretraining (using general data and a pretrained teacher) to task-specific finetuning (using specific data and a finetuned teacher). Such sudden changes in data distribution and learning objectives can hinder the student's ability to effectively inherit the teacher's knowledge. ERNIE-Tiny addresses this by introducing a four-stage progressive distillation framework.
Methodology: Progressive Distillation
The core of ERNIE-Tiny is a "progressive" approach that ensures only one component—teacher, data, or objective—changes at each step. This smoothing of the learning path prevents optimization hurdles and catastrophic forgetting.
The framework consists of four distinct stages:
- General Distillation (GD): The student learns latent representations (hidden states and attention) from a pretrained teacher using a large-scale general corpus.
- General-Enhanced Distillation (GED): In this novel stage, the teacher is swapped for a task-specific finetuned version, but the data remains general. This allows the student to learn task-specific nuances from a massive, diverse dataset, acting as a powerful form of data augmentation.
- Task-Adaptive Distillation (TAD): The teacher remains finetuned, but the data shifts from general to task-specific. This bridges the gap between general knowledge and the target task.
- Task-Specific Distillation (TSD): The final stage adds soft-label and hard-label losses to maximize accuracy on the target task using specific data.
Key Results and Performance
ERNIE-Tiny demonstrates exceptional efficiency and performance. A 4-layer ERNIE-Tiny student model achieves 98.0% of the performance of a 12-layer BERT-base on the GLUE benchmark while being 7.5x smaller and 9.4x faster.
As shown in the comparison above, ERNIE-Tiny outperforms other popular compressed models like TinyBERT and MobileBERT. On Chinese NLP tasks, it even surpassed the full-sized BERT-base by 0.4% in accuracy while maintaining its significant speed advantage.
A critical insight from the ablation studies is the impact of the GED stage. By leveraging a finetuned teacher on general data, the model generalizes better to out-of-domain data. For instance, models trained with GED showed significant performance gains when tested on datasets they hadn't seen during training (e.g., testing an MNLI-trained model on SNLI).
Conclusion
ERNIE-Tiny provides a robust solution for deploying high-performance Transformers on edge devices. By mitigating distillation discrepancy through a progressive four-stage framework, it allows small models to retain the vast majority of their larger counterparts' capabilities. Future work may explore scaling this framework with even larger unlabeled datasets and applying it to diverse neural architectures beyond the standard Transformer.
Summary updated