Introduction
Pre-trained language models like BERT have set new benchmarks in NLP, yet their massive scale—often exceeding 110 million parameters—presents significant barriers to deployment on resource-constrained devices. Knowledge Distillation (KD) has emerged as a primary solution, where a compact "student" model is trained to replicate the behavior of a larger "teacher." However, traditional KD methods like TinyBERT or BERT-PKD typically rely on rigid, human-defined one-to-one layer mapping. This approach assumes that specific student layers must correspond to specific teacher layers, ignoring the possibility that linguistic knowledge may be distributed across the teacher network in ways that vary by task.
Methodology: Many-to-Many Distillation via EMD
To overcome the limitations of fixed mapping, the authors introduce BERT-EMD. This framework utilizes a "many-to-many" strategy, allowing any student layer to aggregate knowledge from any combination of teacher layers.
The core of this approach is the application of Earth Mover’s Distance (EMD), also known as the Wasserstein metric. By treating layers as distributions of knowledge, EMD identifies the optimal "flow" of information that minimizes the cost of transforming teacher representations into student representations. Complementing this is a Cost Attention Mechanism, which dynamically weights teacher layers based on their learnability; layers with lower transformation costs are prioritized, while redundant or overly complex layers are down-weighted. This optimization occurs across four key components: embeddings, prediction logits, attention maps, and hidden states.
Experimental Evaluation
The effectiveness of BERT-EMD was evaluated using the General Language Understanding Evaluation (GLUE) benchmark, encompassing tasks ranging from sentiment analysis (SST-2) to logical entailment (MNLI, RTE) and linguistic similarity (STS-B).
As shown in the results, BERT-EMD consistently outperforms existing compression baselines:
- BERT-EMD$_4$: With only 14.5M parameters, this 4-layer model achieved an average GLUE score of 74.66, surpassing TinyBERT$_4$ (73.51) and providing a 9.4x inference speedup over the original BERT-base.
- BERT-EMD$_6$: This 6-layer variant achieved an average score of 80.00, remarkably outperforming the 12-layer BERT-base (79.60) on 7 out of 9 tasks while being nearly twice as fast.
Insights and Discussion
The success of BERT-EMD stems from its task-specific flexibility. Visualization of the flow matrices reveals that for simpler tasks, the mapping tends toward a traditional diagonal structure. However, for complex tasks like RTE, the student draws from a much broader range of teacher layers. By framing distillation as a transportation problem, the model moves beyond empirical heuristics toward a mathematically grounded optimization.
While BERT-EMD offers superior performance and inference speed, it does introduce higher computational overhead during the training phase due to the EMD flow calculations. Future work may explore applying this many-to-many EMD approach to other architectures, such as RoBERTa or vision transformers, where layer-to-layer correspondence is similarly non-trivial.
Summary updated