Text Embeddings by Weakly-Supervised Contrastive Pre-training

Liang Wang, Nan Yang, Xiaolong Huang, Binxing Jiao, Linjun Yang, Daxin Jiang, Rangan Majumder, Furu Wei

Abstract

High-quality text embeddings are fundamental to modern NLP tasks such as retrieval, clustering, and classification. This paper introduces E5 (EmbEddings from bidirEctional Encoder rEpresentations), a family of models trained using a novel two-stage contrastive learning recipe. By leveraging a massive, filtered dataset of 270 million text pairs (CCPairs), E5 achieves state-of-the-art performance on major benchmarks. Notably, E5-PT is the first unsupervised model to outperform the BM25 baseline on the BEIR retrieval benchmark, while the fine-tuned E5-large model sets a new standard on the MTEB leaderboard, outperforming models with 40x more parameters.

Introduction

The development of general-purpose text embeddings has historically faced a significant hurdle: the trade-off between the scale of unsupervised data and the quality of supervised labels. Supervised models like GTR or Sentence-T5 deliver strong performance but are constrained by the limited scope of labeled datasets. Conversely, unsupervised models trained on massive synthetic data often struggle to surpass traditional keyword-matching algorithms like BM25. E5 addresses this by combining a massive-scale weakly-supervised pre-training phase with a high-quality supervised fine-tuning stage, underpinned by a rigorous data curation process.

Methods

The E5 framework relies on a refined training pipeline and a simple yet effective architectural modification to handle asymmetric retrieval tasks.

Architecture and Data Curation

E5 utilizes a standard Transformer encoder with average pooling. To distinguish between queries and documents in retrieval tasks, the model prepends "query:" and "passage:" prefixes to the input text. This allows a shared encoder to learn distinct representations for different roles.

The training data, CCPairs (Colossal Clean text Pairs), consists of 270 million pairs mined from diverse sources including Reddit, StackExchange, and Common Crawl. To ensure high quality, the authors implemented a consistency-based filter. An initial model was used to rank pairs; only those where the model correctly identified the paired text within the top-2 against a million distractors were retained. This process reduced the raw 1.3 billion pairs to a high-signal subset.

The E5 data curation pipeline and model architecture.

Two-Stage Training

  1. Weakly-Supervised Pre-training: The model is pre-trained on CCPairs using a contrastive InfoNCE loss with a very large batch size (32,768), providing a rich set of in-batch negatives.
  2. Supervised Fine-tuning: The pre-trained weights are further refined using labeled datasets such as MS-MARCO and NLI. This stage incorporates hard negative mining and knowledge distillation from a Cross-Encoder teacher to maximize retrieval accuracy.

Results

E5 demonstrates exceptional performance across a wide range of NLP tasks, proving that data quality and training strategy can outweigh raw parameter scale.

BEIR and MTEB Benchmarks

On the BEIR retrieval benchmark, the pre-trained E5-PT model achieved an nDCG@10 of 44.2, surpassing the BM25 baseline of 41.7. This marks a significant milestone for unsupervised embedding models.

On the Massive Text Embedding Benchmark (MTEB), which spans 56 datasets across diverse categories, the fine-tuned E5-large model achieved an average score of 61.4. As shown in the table below, E5-large consistently outperforms larger models like GTR-XXL and Sentence-T5-XXL, despite having significantly fewer parameters.

Performance of E5 models compared to baselines on the MTEB benchmark.

Key Insights

  • Efficiency: E5-large (330M parameters) provides superior embeddings compared to models 40x its size, highlighting the importance of the contrastive training signal.
  • Prefix Utility: The use of task-specific prefixes is crucial for performance in asymmetric retrieval, helping the model bridge the gap between short queries and long passages.

Conclusion

The E5 family of models sets a new state-of-the-art for text embeddings by prioritizing data quality and a structured two-stage training approach. While challenges remain in "long-tail" domains like scientific fact-checking, E5 provides a highly efficient and effective "universal interface" for text representation. Future work will explore iterative data filtering and expanding the model's multilingual capabilities.

Summary updated

BibTeX
@misc{wang2022text,
  author = {Liang Wang and Nan Yang and Xiaolong Huang and Binxing Jiao and Linjun Yang and Daxin Jiang and Rangan Majumder and Furu Wei},
  title = {{Text Embeddings by Weakly-Supervised Contrastive Pre-training}},
  year = {2022},
  eprint = {2212.03533},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2212.03533},
}
Figure