DiPair: Fast and Accurate Distillation for Trillion-Scale Text Matching and Pair Modeling

Jiecao Chen, Liu Yang, Karthik Raman, Michael Bendersky, Jung-Jung Yeh, Yun Zhou, Marc Najork, Danyang Cai, Ehsan Emadzadeh · DOI

Abstract

Pre-trained models like BERT (Devlin et al., 2018) have dominated NLP / IR applications such as single sentence classification, text pair classification, and question answering. However, deploying these models in real systems is highly non-trivial due to their exorbitant computational costs. A common remedy to this is knowledge distillation (Hinton et al., 2015), leading to faster inference. However -- as we show here -- existing works are not optimized for dealing with pairs (or tuples) of texts. Consequently, they are either not scalable or demonstrate subpar performance. In this work, we propose DiPair -- a novel framework for distilling fast and accurate models on text pair tasks. Coupled with an end-to-end training strategy, DiPair is both highly scalable and offers improved quality-speed tradeoffs. Empirical studies conducted on both academic and real-world e-commerce benchmarks demonstrate the efficacy of the proposed approach with speedups of over 350x and minimal quality drop relative to the cross-attention teacher BERT model.

Introduction

Modeling the relationship between pairs of text, such as query-document relevance in search engines or term-product matching in e-commerce, presents a massive computational challenge at scale. Industry applications typically face a harsh trade-off between interaction-focused models (Cross-Attention) and representation-focused models (Dual-Encoders). Cross-attention models like BERT offer high accuracy by allowing words in both texts to attend to each other, but their quadratic complexity and lack of pre-computability make them prohibitively slow for real-time applications. Conversely, Dual-Encoders are fast due to embedding caching but suffer from significant accuracy drops because texts do not interact during encoding. DiPair addresses this by bridging the gap between these two paradigms.

The DiPair Framework

DiPair is a hybrid architecture designed to achieve the speed of a dual-encoder with the nuanced matching capabilities of a cross-attention model. It utilizes knowledge distillation from a large teacher model, such as a 12-layer BERT-base.

DiPair Architecture Overview

The architecture consists of three primary components:

  1. Dual-Encoder with Truncation: Texts are processed through separate, shallow Transformer encoders (initialized from early BERT layers). Instead of pooling into a single vector, DiPair extracts the first $N$ and $M$ token embeddings from the left and right texts.
  2. Projection: These $N+M$ embeddings are projected to a lower dimension (e.g., 768D to 256D) to optimize caching storage and downstream speed with minimal performance loss.
  3. The Head: Concatenated embeddings are fed into a lightweight Transformer "head." By drastically reducing the sequence length to $N+M$ tokens, the cross-attention cost becomes negligible.

To ensure stability, a two-stage training strategy is employed: the dual-encoder is initially frozen while the head is trained to convergence, followed by end-to-end fine-tuning of the entire system.

Experimental Evaluation

The authors evaluated DiPair on two primary datasets: Q2P-MAT (derived from MSMARCO) and P2T-REL (a proprietary e-commerce dataset). Performance was measured against a fine-tuned BERT-base teacher.

Speedup vs. AUC-ROC Trade-off

Key Results

  • Speed-Quality Trade-off: As shown in the figure above, DiPair (DiPair-TSF) achieves a >350x inference speedup compared to the BERT-base teacher while maintaining high AUC-ROC. It significantly outperforms standard Dual-Encoders (DE-FFNN) in quality and is 8x faster than standard distilled models like BERT-Tiny.
  • Accuracy: On the P2T-REL task, DiPair achieved a Pearson correlation of 0.731, closely approaching the teacher's 0.757, whereas standard dual-encoders lagged at 0.677.
  • Efficiency of the Transformer Head: Experiments showed that a Transformer head is essential for closing the quality gap, as simple Feed-Forward Neural Networks (FFNNs) plateaued in performance regardless of parameter count.

Discussion and Future Work

DiPair demonstrates that end-to-end training allows dual-encoders to learn to "push" critical semantic information into a small number of tokens for subsequent cross-attention. While highly effective for static document caching in search, future work may address online serving constraints for dynamic pairs and explore multimodal extensions for image or audio-document matching. The internal representation of information within the truncated embeddings also remains a subject for further investigation.

Summary updated

BibTeX
@inproceedings{chen2020dipair,
  author = {Jiecao Chen and Liu Yang and Karthik Raman and Michael Bendersky and Jung-Jung Yeh and Yun Zhou and Marc Najork and Danyang Cai and Ehsan Emadzadeh},
  title = {{DiPair: Fast and Accurate Distillation for Trillion-Scale Text Matching and Pair Modeling}},
  booktitle = {Conference on Empirical Methods in Natural Language Processing},
  year = {2020},
  doi = {10.18653/v1/2020.findings-emnlp.264},
}
Figure