# Text Embeddings by Weakly-Supervised Contrastive Pre-training

Weak contrastive pre-training trains text embeddings that beat BM25 without labels

Liang Wang, Nan Yang, Xiaolong Huang, Binxing Jiao, Linjun Yang, Daxin Jiang and 2 more · arXiv · 2022-12-7

- **Problem** Single-vector text embeddings need many training pairs, but labeled pairs are scarce and automatically built pairs are noisy. Embeddings trained that way have not matched BM25 on retrieval without further fine-tuning.
- **Method** E5 is trained contrastively on about 270M web text pairs, filtered by a consistency check. Unlike earlier pair-building methods, it keeps only pairs the model already ranks as consistent.
- **Results** E5-PTbase scores 42.9 nDCG@10 averaged over 15 BEIR datasets, against 41.7 for BM25. The authors state it is the first unsupervised model to beat BM25 on BEIR.

## Why labeled pairs are the bottleneck

Single-vector embeddings are attractive for retrieval and matching because they are compact and efficient to search and easy for downstream applications to consume. Pre-trained language models such as BERT and GPT give transferable representations, but their outputs are not organized as one vector per text in the way retrieval systems need.

Contrastive learning on text pairs is the usual way to shape these vectors, and the existing options split into two groups. One group fine-tunes pre-trained models on supervised data, which gives strong results for a target task but depends on labeled examples. The other group builds pairs automatically, for example by inverse cloze, random cropping or neighboring spans; these pairs are abundant but noisy, and the resulting embeddings have not matched BM25 without further fine-tuning.

The authors aim for a single embedding model that works off the shelf in both zero-shot and fine-tuned settings, trained without relying on small labeled sets or low-quality synthetic pairs.

## Building the CCPairs text pairs

The pairs come from several web sources: Reddit posts with comments, Stackexchange questions with upvoted answers, Wikipedia entity or section titles with passages, scientific papers, Common Crawl pages and news articles. Simple rules remove the noisiest material first; for example, Reddit comments longer than 4096 characters or with a score below 1 are dropped, and web passages with high perplexity are removed.

After this preliminary filtering about 1.3 billion text pairs remain, most of them from Reddit and Common Crawl.

A consistency-based filter then tests each pair against a model trained on the full noisy set: the model ranks the query against a pool of 1 million random passages, and the pair is kept only if its own passage lands in the top-k, with k set to 2 after manual inspection. This leaves about 270M pairs for contrastive pre-training, so the filter makes the training cost manageable and keeps pairs the model already treats as consistent with their labels.

The authors base the filter on the observation that neural networks fit clean labels before they overfit noisy ones, and they note that repeating the filter iteratively is left for future work. Evaluation datasets are excluded by exact string match, so pairs that appear in the evaluation sets are removed.

## How the contrastive objective is computed

Pre-training treats each pair (q\_i, p\_i) as a positive and draws a list of negative passages for the same query, and the InfoNCE loss pushes the score of the positive above the scores of its negatives. \\\\\[ \\\\mathcal{L}\_{cont} = -\\\\frac{1}{n}\\\\sum\_{i=1}^{n}\\\\log\\\\frac{e^{s\_\\\\theta(q\_i,p\_i)}}{e^{s\_\\\\theta(q\_i,p\_i)}+\\\\sum\_{j=1}^{m}e^{s\_\\\\theta(q\_i,p\_{ij}^-)}} \\\\\] The minus sign means the loss is minimized, so the positive score is raised relative to the summed exponentials of its negatives in the denominator.

The score \\\\(s\_\\\\theta(q,p)\\\\) is the cosine similarity between the two embeddings \\\\(E\_q\\\\) and \\\\(E\_p\\\\), divided by a temperature \\\\(\\\\tau\\\\) that is set to 0.01 by default. Each text is encoded by a pre-trained Transformer whose output layer is averaged into a fixed-size vector, so one encoder serves both sides of the pair. Sharing the encoder is made asymmetric by prefixing 'query:' to queries and 'passage:' to passages; where the query role is unclear, as with citation pairs, one side is picked at random.

The authors report that this asymmetry matters for retrieval tasks in which paraphrases of the query exist in the target corpus.

Negatives come from in-batch sampling, so the passages of the other pairs in the same batch act as negatives for each query. The authors found this more stable than MoCo when the batch is large enough, and they use a batch size of 32,768 for all E5 sizes. Training runs for 20k steps with AdamW, a 1,000-step warmup and linear decay, which is approximately 2.5 epochs over the dataset.

## Supervised fine-tuning with distillation

The second stage adds human-labeled data, which the authors use because earlier work showed that supervised fine-tuning gives consistent gains. The mix is NLI, MS-MARCO passage ranking and NQ; the authors observe that NLI helps STS and linear probing, while MS-MARCO and NQ transfer to retrieval.

For MS-MARCO and NQ the negatives are mined hard negatives, and the teacher is a cross-encoder whose soft scores are distilled into the student embedding model; for NLI, contradiction sentences serve as hard negatives. The loss combines a KL divergence term between the teacher and student probabilities with the contrastive loss on hard labels, as \\\\\[ \\\\min D\_{KL}(p\_{ce},p\_{stu})+\\\\alpha\\\\mathcal{L}\_{cont} \\\\\] Here p\_ce and p\_stu are the teacher and student probabilities, and the paper sets alpha to 0.2 for all three E5 sizes in fine-tuning.

Fine-tuning runs for 3 epochs with batch size 256 on 8 GPUs, and each example carries 7 hard negatives. NLI has only one hard negative per example, so six sentences are sampled at random from the corpus to fill the seven slots.

## Zero-shot retrieval on BEIR

The unsupervised comparison covers the 15 BEIR datasets that provide public downloads, scored by nDCG@10. Averaged over these 15 datasets, E5-PTbase scores 42.9 against 41.7 for BM25, which is 1.2 points higher. The authors state that this is the first reported unsupervised model to beat BM25 on BEIR.

E5-PTlarge gives the best score on 7 of the 15 datasets, and E5-PTbase on 2, while BM25 is best on 5.

The pre-training data differ across these methods: Contriever uses random cropping, while LaPraDor mixes ICT with dropout-based positives from SimCSE, and the authors note that their own route needs more work in dataset curation. The authors read the better scores as the payoff of that curation effort.

## Fine-tuned retrieval on BEIR

After fine-tuning, E5base averages 48.7 nDCG@10 and E5large averages 50.0 across the BEIR datasets. This is above GTRlarge at 47.0, a model with more parameters. The MS-MARCO and NQ columns are in-domain for these models, since those datasets were used in fine-tuning, while the other datasets are zero-shot transfer.

Most datasets gain from fine-tuning, but FiQA, Scidocs and Fever do not follow this pattern. The authors attribute these exceptions to the fine-tuning datasets lacking enough domain diversity.

## MTEB results and model size

The MTEB comparison uses the English subsets of 56 datasets, grouped into category averages across classification, clustering, pair classification, reranking, retrieval, STS and summarization. E5large averages 61.4 and E5base averages 60.4 after fine-tuning, which is above GTRxxl at 59.0 and Sentence-T5xxl at 59.5. The introduction states that E5base is competitive against these two models, which have 40× more parameters.

The authors expect the model to gain from further scaling. Among the unsupervised rows, E5-PTsmall, E5-PTbase and E5-PTlarge average 54.3, 55.6 and 56.6 over the 56 datasets.

BERT-FTbase uses the same fine-tuning data as E5 but starts from BERTbase without contrastive pre-training, and it averages 55.2 against 60.4 for E5base. The authors read this gap as evidence for the value of contrastive pre-training on CCPairs. Fine-tuning improves most categories, but clustering does not follow: E5-PTbase scores 43.4 there and E5base 42.1.

## Zero-shot text classification on SST-2

Input and label texts are rewritten as sentences from manually written prompt templates, and the predicted label is the one whose embedding is closest to the input embedding. On the dev set of SST-2, the majority-class baseline scores 50.9, zero-shot BERTbase 58.9, E5small 79.7, E5base 81.3 and E5large 85.3. The fully fine-tuned BERTbase and BERTlarge reach 93.5 and 94.9, so zero-shot E5 remains below fine-tuning on this task.

## Batch size, filtering and negatives

Across six BEIR datasets, increasing the in-batch size from 1k to 8k and then 32k improves the average from 45.8 to 50.2 and then 51.6. The authors note that smaller batches can be paired with mined hard negatives, but mining for datasets above 100M pairs is costly.

The authors observe that dataset noise matters less than expected, yet filtering still helps training efficiency and quality.

Pre-batch negatives average 43.3 and MoCo 45.5, against 51.6 for in-batch negatives with the 32k batch on the same six datasets. The authors find MoCo more sensitive to temperature, so better MoCo results may be possible with more tuning.

## Open problems and constraints

The authors conclude that BM25 still has advantages in simplicity, efficiency and interpretability, so the answer to replacing it is not yet. On long-tail domains such as Trec-Covid, on long documents such as Touche-2020, and on tasks that depend on exact lexical match such as Fever, they say dense retrievers still need further work.

Fine-tuning gains are uneven across BEIR, with exceptions on FiQA, Scidocs and Fever attributed to domain diversity. Whether state-of-the-art embeddings can be reached without any human-labeled data is left as an open question by the authors.

RoBERTa initialization performed worse than BERT on most BEIR datasets, and an auxiliary masked language modeling loss on 25% of pairs left results unchanged while raising training cost.

The BEIR MS-MARCO data have no document titles, so those results are expected to be lower than the title-based setting used for comparison with RocketQA. The evaluation covers 15 of the 19 BEIR datasets, namely those with public downloads.

## Paper info

- **Authors**: Liang Wang, Nan Yang, Xiaolong Huang, Binxing Jiao, Linjun Yang, Daxin Jiang, Rangan Majumder, Furu Wei
- **Venue**: arXiv · Preprint
- **First published**: 2022-12-7
- **Added**: 2026-11-12
- **Updated**: 2024-2-22
- **Version**: v2
- **arXiv**: 2212.03533
- **Category**: cs.CL · cs.IR
- **Original paper terms**: [CC BY 4.0](https://creativecommons.org/licenses/by/4.0/)
- **What we show**: Paper info and commentary

[Original paper ↗](https://arxiv.org/abs/2212.03533v2) · [PDF ↗](https://arxiv.org/pdf/2212.03533v2)

AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.

## Quote from the paper

Liang Wang, Nan Yang, Xiaolong Huang, Binxing Jiao, Linjun Yang, Daxin Jiang, Rangan Majumder, Furu Wei (2022). Text Embeddings by Weakly-Supervised Contrastive Pre-training. arXiv:2212.03533v2. https://arxiv.org/abs/2212.03533v2

**BibTeX**

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

## Other paper commentary

- [Representation Learning on Graphs: Methods and Applications](https://refivu.com/en/papers/3ca2c648-5d7e-46c2-be1e-357cc66ab085-representation-learning-on-graphs-methods-and-applications.md)
- [Deep Learning Face Representation by Joint Identification-Verification](https://refivu.com/en/papers/1824448e-2edd-4d03-a6b5-1fbd92b71da3-deep-learning-face-representation-by-joint-identification.md)
- [Curiosity-driven Exploration by Self-supervised Prediction](https://refivu.com/en/papers/93936438-d2c7-4a12-b814-3073185546ca-curiosity-driven-exploration-by-self-supervised-prediction.md)
- [ConvNeXt V2: Co-designing and Scaling ConvNets with Masked Autoencoders](https://refivu.com/en/papers/d6599a02-0aa8-4eec-a1c3-2bdc45716f23-convnext-v2-co-designing-and-scaling-convnets-with.md)
- [Person Re-identification by Local Maximal Occurrence Representation and Metric Learning](https://refivu.com/en/papers/ce1c4e84-0a27-40a3-8d69-3dc923b2cf52-person-re-identification-by-local-maximal-occurrence.md)
- [UNITER: UNiversal Image-TExt Representation Learning](https://refivu.com/en/papers/c2b71a61-22ad-48f9-af71-922539fd9eab-uniter-universal-image-text-representation-learning.md)
- [Reading Wikipedia to Answer Open-Domain Questions](https://refivu.com/en/papers/0abc2d22-75a1-4c4d-91be-624a590aabec-reading-wikipedia-to-answer-open-domain-questions.md)
- [CogVideoX: Text-to-Video Diffusion Models with An Expert Transformer](https://refivu.com/en/papers/d337167e-74d3-423d-ae74-fbe584f8b441-cogvideox-text-to-video-diffusion-models-with-an.md)
- [Neural Combinatorial Optimization with Reinforcement Learning](https://refivu.com/en/papers/428e6cb1-5b5b-43dc-ad1f-c954e953fc5b-neural-combinatorial-optimization-with-reinforcement.md)
- [Towards Open Set Deep Networks](https://refivu.com/en/papers/2821701d-d008-4717-86f5-1119fb0809bf-towards-open-set-deep-networks.md)
- [Graph Embedding Techniques, Applications, and Performance: A Survey](https://refivu.com/en/papers/eeed1384-bf87-452c-b3b1-9ecc6ce7d43b-graph-embedding-techniques-applications-and-performance-a.md)
- [Expanding Performance Boundaries of Open-Source Multimodal Models with Model, Data, and Test-Time Scaling](https://refivu.com/en/papers/90a6655e-9301-4ffa-a598-267663200fa0-expanding-performance-boundaries-of-open-source-multimodal.md)

## Terms in this paper

- [knowledge distillation](https://refivu.com/en/terms/b8544f4ba83e-knowledge-distillation)
- [BM25](https://refivu.com/en/terms/64437f95755a-bm25)
- [SST-2](https://refivu.com/en/terms/8904146eae2e-sst-2)
- [in-batch negatives](https://refivu.com/en/terms/a4ee4e02506f-in-batch-negatives)
- [nDCG@10](https://refivu.com/en/terms/2d8a23b2a2b1-ndcg-10)
- [MoCo](https://refivu.com/en/terms/48667b2992b6-moco)
- [Contriever](https://refivu.com/en/terms/d8eaa624847e-contriever)
- [BEIR benchmark](https://refivu.com/en/terms/e6ee1e396182-beir-benchmark)
- [MS-MARCO](https://refivu.com/en/terms/c1236b1536c7-ms-marco)
- [NQ](https://refivu.com/en/terms/355505a22c59-nq)
- [SimCSE](https://refivu.com/en/terms/6ab4fc4a98e8-simcse)

---

AI-written text can contain mistakes. [Refivu](https://refivu.com/en/papers/d1351af6-6e66-4a03-9f02-44cc61903f8b-text-embeddings-by-weakly-supervised-contrastive-pre)
