Introduction
Transformer-based language models like BERT have achieved remarkable success but are often too large for deployment on resource-constrained devices. Knowledge Distillation (KD) aims to compress these models by training a smaller "student" to mimic a "teacher." However, standard KD methods typically focus on matching individual token representations, which ignores the structural relationships between words and forces the student to share architectural traits with the teacher. This paper proposes Contextual Knowledge Distillation (CKD), a novel approach that distills the geometric relationships between words and across layers, providing both better performance and greater architectural flexibility.
Methodology
CKD shifts the distillation objective from raw feature matching to the preservation of linguistic context through two primary relational mechanisms:
Word Relation (WR)
CKD-WR captures the "horizontal" relationships between words within a single layer. It calculates pair-wise distances and triple-wise angles to model the local geometry of the embedding space. To optimize computation and focus on relevant context, a "locality window" ($\delta$) is used to restrict relations to nearby tokens.
Layer Transforming Relation (LTR)
CKD-LTR captures the "vertical" evolution of word representations as they pass through successive layers. This teaches the student how the teacher transforms specific concepts into more abstract representations.
Because CKD matches relational statistics (scalars) rather than high-dimensional tensors, it is architecture-agnostic. The student model can be designed with any hidden size or number of attention heads, decoupling its design from the teacher's structure.
Experimental Results
The effectiveness of CKD was evaluated on the GLUE benchmark and the SQuAD 1.1 dataset.
Performance Benchmarks
In task-agnostic distillation, a 6-layer CKD student achieved an average GLUE score of 82.4, outperforming TinyBERT (81.3). For task-specific distillation on SQuAD 1.1, CKD reached an F1 score of 88.7, compared to TinyBERT's 87.2.
Robustness Across Architectures
CKD consistently outperforms baseline methods across a wide range of student configurations. As illustrated in the figure below, CKD maintains a performance lead over LogitKD and other methods regardless of the student's depth or width.
Conclusion
Contextual Knowledge Distillation (CKD) represents a significant step forward in model compression. By prioritizing the geometric structure of linguistic context over individual token values, CKD achieves superior accuracy while enabling flexible student architectures. Its ability to integrate with other compression techniques like DynaBERT makes it a versatile tool for creating efficient, high-performance language models for edge deployment.
Summary updated