Skip to main content
QUICK REVIEW

[Paper Review] Contrastive Distillation on Intermediate Representations for Language Model Compression

Siqi Sun, Zhe Gan|arXiv (Cornell University)|Sep 29, 2020
Topic ModelingComputer Science44 references5 citations
TL;DR

This paper proposes CoDIR, a contrastive distillation framework that improves knowledge distillation in compressed language models by leveraging intermediate representations through a contrastive objective, outperforming existing methods on the GLUE benchmark with a smaller, faster model.

ABSTRACT

Existing language model compression methods mostly use a simple L2 loss to distill knowledge in the intermediate representations of a large BERT model to a smaller one. Although widely used, this objective by design assumes that all the dimensions of hidden representations are independent, failing to capture important structural knowledge in the intermediate layers of the teacher network. To achieve better distillation efficacy, we propose Contrastive Distillation on Intermediate Representations (CoDIR), a principled knowledge distillation framework where the student is trained to distill knowledge through intermediate layers of the teacher via a contrastive objective. By learning to distinguish positive sample from a large set of negative samples, CoDIR facilitates the student's exploitation of rich information in teacher's hidden layers. CoDIR can be readily applied to compress large-scale language models in both pre-training and finetuning stages, and achieves superb performance on the GLUE benchmark, outperforming state-of-the-art compression methods.

Motivation & Objective

  • To address the limitation of conventional knowledge distillation that relies on independent $L_2$ loss between hidden representations, which fails to capture structural dependencies in BERT's intermediate layers.
  • To explore the use of contrastive learning in knowledge distillation for large-scale language models, particularly in exploiting higher-order relationships in intermediate representations.
  • To design effective sampling strategies for contrastive learning that work in both pre-training and fine-tuning stages, where labels are unavailable or sparse.
  • To improve model efficiency and performance by replacing standard $L_2$ distillation with a contrastive objective that distinguishes congruent (same sample) from incongruent (different sample) representation pairs.
  • To demonstrate that mean-pooled representations are more effective than [CLS] tokens for distillation, especially in downstream fine-tuning.

Proposed method

  • CoDIR applies a contrastive loss to intermediate hidden representations of the teacher and student networks, training the student to distinguish congruent pairs (same input) from a large set of incongruent pairs (different inputs).
  • The contrastive objective is formulated as a contrastive learning loss that pulls together representations from the same sample (positive pairs) and pushes apart those from different samples (negative pairs).
  • A memory bank stores all representations from the current batch to enable efficient negative sampling during training, especially in pre-training where labels are not available.
  • For fine-tuning, incongruent pairs are constructed using samples with different labels to maximize dissimilarity; for pre-training, random pairs from the same mini-batch are used as proxies.
  • The method combines contrastive distillation with standard knowledge distillation (KL divergence on logits) and masked language modeling (MLM) loss during pre-training.
  • Mean-pooling of all token representations is used as the sentence-level embedding for distillation, replacing the [CLS] token, which is shown to be more effective empirically.

Experimental results

Research questions

  • RQ1Can contrastive learning on intermediate representations improve knowledge distillation in compressed language models compared to standard $L_2$-based distillation?
  • RQ2How can effective negative sampling be designed for contrastive distillation in both pre-training and fine-tuning stages, especially when labels are unavailable during pre-training?
  • RQ3Does using mean-pooled representations instead of [CLS] tokens lead to better distillation performance in compressed models?
  • RQ4What is the impact of the number of negative samples on the performance of contrastive distillation in the context of language model compression?
  • RQ5Can the proposed CoDIR framework achieve state-of-the-art performance on GLUE while reducing model size and inference time compared to existing compression methods?

Key findings

  • CoDIR outperforms state-of-the-art compression methods on the GLUE benchmark, achieving a 1.9% average improvement over standard MLM pre-training and a 1.0% improvement over KD-only pre-training.
  • The student model, half the size of BERT-base, achieves competitive performance with 2× faster inference speed and reduced GPU demand.
  • Using mean-pooled representations as distillation targets yields 83.0 average GLUE score, outperforming [CLS] token-based distillation (82.5 average score).
  • Increasing the number of negative samples from 100 to 1000 improves performance on most GLUE tasks, with the largest gains observed on MNLI and QNLI.
  • The contrastive loss contributes significantly to performance: adding CRD loss to KD improves average GLUE score by 1.0% over standard KD, and by 1.9% over vanilla MLM pre-training.
  • Model performance shows higher variance on smaller datasets (e.g., CoLA, MRPC, RTE), with standard deviations around 1.5, indicating sensitivity to random seed initialization.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.