Contextual Knowledge Distillation for Transformer Compression

Geondo Park, Gyeongman Kim, Eunho YangOpenReview 2020

TL;DR

This paper introduces Contextual Knowledge Distillation (CKD), a novel method for compressing large Transformer language models. CKD goes beyond traditional knowledge distillation by transferring not just individual word representations, but also the relationships between words within a layer and how a word's representation evolves across layers. This approach achieves state-of-the-art performance in compressing models while maintaining their capabilities.

What Problem Does This Paper Address?

The incredible success of large Transformer-based language models like BERT has come at the cost of significant computational and memory requirements. This makes deploying these powerful models on resource-constrained devices (like mobile phones) a major challenge. Knowledge Distillation (KD) is a common technique to address this by training smaller "student" models to mimic larger "teacher" models. However, existing KD methods often treat word representations independently, ignoring the rich contextual information and structural relationships that these models learn. This paper aims to bridge this gap by developing a KD strategy that leverages these learned contextual relationships for more effective compression.

Methods

The core of this paper is the Contextual Knowledge Distillation (CKD) strategy. CKD introduces two novel types of contextual knowledge to be transferred from the teacher to the student model:

  • Word Relation (WR)-based Contextual Knowledge: This captures the relationships between word representations within the same layer. The authors propose using pairwise and triple-wise relationships, defined by distances and angles between word vectors, to represent this knowledge. This allows the student to learn how words are positioned relative to each other in the embedding space.
  • Layer Transforming Relation (LTR)-based Contextual Knowledge: This focuses on how a single word's representation evolves across different layers. By capturing the transformation of a word's representation as it passes through the network hierarchy, the student can learn to mimic the abstract conceptual development within the teacher model.

CKD can be combined with existing distillation methods, such as matching class probabilities, to further enhance performance. The authors also introduce a mechanism for aligning layers when teacher and student models have different numbers of layers.

Datasets

The paper evaluates CKD on standard language understanding benchmarks:

  • Stanford Question Answer Dataset (SQUAD)
  • General Language Understanding Evaluation (GLUE) benchmark, which includes tasks like Natural Language Inference, Sentiment Classification, and Paraphrase Similarity Matching.

Key Insights and Ideas

  • Context is King: The paper strongly argues that the relationships between word representations are as, if not more, important than individual representations themselves for effective knowledge distillation.
  • Beyond Individual Words: Traditional KD methods often treat word representations in isolation. CKD's innovation lies in explicitly transferring the structural and relational information learned by the teacher.
  • Flexibility in Architecture: Unlike some prior KD methods that impose architectural constraints (e.g., same embedding size or number of attention heads), CKD is designed to be more flexible, allowing for greater architectural diversity between teacher and student models.
  • Synergistic Components: Both Word Relation and Layer Transforming Relation components contribute significantly to performance, and their combination yields the best results.

Key Results

  • State-of-the-Art Performance: CKD consistently outperforms existing state-of-the-art distillation methods on GLUE benchmarks, often by a significant margin.
  • Improved MobileBERT Performance: CKD boosts the performance of MobileBERT, a highly efficient thin BERT architecture, on GLUE tasks.
  • Effective Across Model Sizes: The method demonstrates strong performance across various student model sizes, from small BERTs to larger ones, indicating its general applicability.
  • Competitive with Teacher: In some cases, especially with data augmentation, student models trained with CKD even surpass the performance of the teacher model.
  • SQuAD 1.1v Improvement: CKD shows a 2.1%p improvement over TinyBERT on the SQuAD 1.1v dataset.

Limitations and Future Work

  • Hyperparameter Tuning: While the paper aims to reduce hyperparameter search, finding optimal values for CKD still requires careful tuning.
  • Locality for Weights: The paper uses a "locality" heuristic to manage the computational cost of calculating relationship weights. Future work could explore more sophisticated methods for defining these weights, potentially using attention matrices directly.
  • Further Exploration of Relationships: The authors suggest defining weights continuously using attention matrices, rather than discretely with locality, as a future direction.

Summary updated

BibTeX
@misc{park2020contextual,
  author = {Geondo Park and Gyeongman Kim and Eunho Yang},
  title = {{Contextual Knowledge Distillation for Transformer Compression}},
  year = {2020},
  url = {https://openreview.net/forum?id=Aj4_e50nB8},
  howpublished = {OpenReview},
}
Figure