Paper · 2023-12-31 · cs.CL, cs.IR
Improving Text Embeddings with Large Language Models
Generates synthetic embedding training data with GPT-4 and GPT-3.5 (about 500k examples, 93 languages), then fine-tunes Mistral-7B with LoRA (rank 16) and InfoNCE (temperature 0.02) for one epoch. Queries get a task instruction. Author-reported: MTEB average 66.6 with full data (BGE-large 64.2), 63.1 with synthetic data only; BEIR 56.9.
Text embeddingDense retrievalContrastive learningSynthetic query generationtext-embeddingdense-retrievalsynthetic-datamultilingualllm-embedding
arXivPDFCodeMarkdown17 min read
AI-compiled by claude-haiku-5-5 on 2026-10-31, not yet reviewed by a human. Every claim cites its source; check it when a detail matters.
In plain words
A text embedding model turns a sentence or a passage into a list of numbers, so that texts with similar meaning get similar lists. Search engines and retrieval systems use these lists to find relevant documents. The usual recipe trains such a model in several stages on huge collections of loosely matched text pairs, then tunes it on a few carefully labelled datasets. That takes a lot of engineering and only covers the tasks and languages those datasets cover.
This paper asks whether a large language model can skip most of that work. A strong proprietary model is asked to invent search-style tasks, together with matching examples, in many languages. An open 7-billion-parameter language model is then fine-tuned on those examples with a standard contrastive loss. Each query is prefixed with a one-line description of the task, and documents are not. The embedding is read from a special end-of-text position.
The result is a model trained on generated data alone that performs well on English benchmarks. Adding labelled datasets to the training mix makes it stronger still. It is weaker on low-resource languages, and the paper also tests whether it can find a short passkey hidden in very long documents.
TL;DR
- Synthetic data: about 500k examples generated with GPT-4 and GPT-3.5-Turbo, covering 93 languages, from a two-step prompting scheme §3.1 §4.1.
- Training: Mistral-7B with LoRA rank 16, one epoch, InfoNCE with temperature 0.02, queries prefixed with a task instruction §3.2 §4.2 app. A.
- Author-reported: MTEB (56 English datasets) average 66.6 with full data, against 64.2 for BGE-large-en-v1.5; 63.1 with synthetic data only tab. 1.
- Author-reported: BEIR (15 retrieval datasets) average nDCG@10 56.9 tab. 3.
- Pitfall: the repository contains only evaluation code. The training recipe, data generation and passkey experiments cannot be checked against code.
Problem
Strong text embeddings have usually needed multi-stage training: weakly supervised pre-training on billions of pairs, then fine-tuning on labelled data. This is costly to build, and the labelled data is limited in task diversity and language coverage. Encoders are typically small BERT-style models, which leaves out recent LLM advances such as longer context §1.
Method
The method has two parts. A proprietary LLM generates synthetic training examples for many embedding tasks §3.1. A decoder-only LLM is then fine-tuned into an embedding model with a contrastive loss §3.2. The embedding of a text is the last-layer vector at a final [EOS] token §3.2.
Synthetic data §3.1:
- Tasks are grouped as asymmetric (query and document related but not paraphrases) or symmetric (STS and bitext retrieval) §3.1.
- Asymmetric tasks are split by length into four subgroups: short-long, long-short, short-short and long-long. Each subgroup has its own prompt templates §3.1 tab. 8 tab. 9 tab. 10 tab. 11.
- For each asymmetric subgroup, the LLM first brainstorms about 20 one-sentence task definitions, then writes one JSON example per task §3.1 app. C. Symmetric tasks skip the brainstorming step §3.1.
- Placeholders in the templates are sampled at runtime, which adds diversity §3.1 tab. 8 tab. 9 tab. 12 tab. 13. The language is sampled from the XLM-R language list with extra weight on high-resource languages §3.1 app. C.
- Outputs that are not valid JSON are discarded, and exact duplicates are removed by string matching §3.1.
- Generation uses Azure OpenAI with GPT-4 and GPT-3.5-Turbo, about 25% from GPT-3.5-Turbo, at temperature 1.0 and top-p 1.0 §4.1 app. C.
Training §3.2:
- For a relevant pair (q^+, d^+), the query gets an instruction prefix (equation 1). Synthetic data uses its brainstormed task definition. Other datasets use manually written definitions, listed in tab. 14. Documents get no prefix §3.2.
- Query and document are both passed through the LLM with [EOS] appended, and the last-layer [EOS] vector is the embedding §3.2.
- The loss is InfoNCE over the positive, the in-batch negatives and the hard negatives (equation 2). Scores are cosine similarities divided by a fixed temperature \tau = 0.02 (equation 3) §3.2.
- Fine-tuning uses Mistral-7B, one epoch, LoRA rank 16 on all linear layers, gradient checkpointing, mixed precision and DeepSpeed ZeRO-3 §4.2 app. A.
- The full-data model mixes the synthetic data with 13 public datasets, about 1.8M examples after sampling §4.2 app. A. The default ablation setting uses synthetic data plus MS-MARCO only tab. 5.
Equations, as written in the paper:
q^{+}_{\mathrm{inst}} = \text{Instruct: } \{\text{task definition}\}\ \backslash n\ \text{Query: } \{q^{+}\} eq. 1
\mathbb{L} = -\log \frac{\phi(q^{+}_{\mathrm{inst}}, d^{+})}{\phi(q^{+}_{\mathrm{inst}}, d^{+}) + \sum_{n_i \in \mathbb{N}} \phi(q^{+}_{\mathrm{inst}}, n_i)} eq. 2
\phi(q, d) = \exp\left(\frac{1}{\tau} \cos(\mathbf{h}_q, \mathbf{h}_d)\right), \quad \tau = 0.02 eq. 3
Pseudocode, in our words. The query instruction and the embedding:
# Put the task instruction in front of a query [§3.2] [eq. 1]
def instruct(task_definition, query):
return "Instruct: " + task_definition + "\nQuery: " + query
# Encode a batch of texts, appending [EOS] to each [§3.2]
def encode(texts):
# Tokenize and append an [EOS] token to every text [§3.2]
token_ids = tokenize_append_eos(texts) # (B, L)
# Run the LLM with LoRA adapters active [§4.2] [app. A]
hidden = llm_with_lora(token_ids) # (B, L, d)
# Take the last-layer vector at the [EOS] position [§3.2] [tab. 5]
rows = arange(len(texts))
return hidden[rows, eos_positions] # (B, d)The contrastive loss:
# Fixed temperature for all scores [§3.2] [eq. 3]
TAU = 0.02
# Temperature-scaled cosine similarity matrix [§3.2] [eq. 3]
def score(query_vecs, doc_vecs):
cosines = normalize(query_vecs) @ normalize(doc_vecs).T
return exp(cosines / TAU) # (Q, D)
# InfoNCE over positives, in-batch and hard negatives [§3.2] [eq. 2]
def info_nce_loss(query_vecs, pos_vecs, hard_neg_vecs):
# Candidates: every positive and hard negative in the batch [§3.2]
docs = concat(pos_vecs, hard_neg_vecs) # (2B, d)
scores = score(query_vecs, docs) # (B, 2B)
# Query i's own positive is column i; all other columns are negatives
rows = arange(len(query_vecs))
positives = scores[rows, rows] # (B,)
losses = -log(positives / scores.sum(axis=1)) # sum includes positive
# Reduction over the batch is not stated in the paper
return losses.mean()Synthetic data generation, in our words. Asymmetric subgroups only:
# Generate examples for one asymmetric subgroup [§3.1] [app. C]
def generate_asymmetric(subgroup):
# Step one: ask for about 20 one-sentence task definitions [app. C]
tasks = llm(brainstorm_prompt(subgroup))
examples = []
for task in tasks:
# Placeholders and language are sampled per call [§3.1]
values = sample_placeholders(subgroup)
language = sample_language()
# Step two: one JSON example for this task [§3.1] [app. C]
raw = llm(example_prompt(subgroup, task, values, language))
example = parse_json(raw)
# Discard anything that is not valid JSON [§3.1]
if example is not None:
examples.append(example)
# Remove exact string duplicates [§3.1]
return unique_by_exact_string(examples)Hyperparameters
| Name | Value | Where | Notes |
|---|---|---|---|
| Base model | Mistral-7B (checkpoint mistralai/Mistral-7B-v0.1) | §4.2 app. A | the paper also reports a LLaMA-2 7B initialisation tab. 5 |
| Epochs | 1 | §4.2 app. A | |
| Training steps | fewer than 1k | §1 app. A | derived: about 1.8M / 2048 = 880 steps per epoch, not stated |
| Batch size | 2048 | app. A | not stated whether per device or global |
| Learning rate | 1e-4 | app. A | |
| LR schedule | 100 warmup steps, then linear decay | app. A | |
| Optimizer | not stated | ||
| Weight decay | 0.1 | app. A | |
| Hard negatives per pair | 1 | app. A | |
| Max sequence length (training) | 512 | app. A | |
| LoRA rank | 16 | §4.2 tab. 5 | rank 8 scores 64.8 and rank 32 scores 64.6 (+0.3, +0.1) tab. 5 |
| LoRA targets | all linear layers | app. A | 42M trainable parameters |
| LoRA alpha, dropout | not stated | ||
| Temperature \tau | 0.02, fixed | §3.2 eq. 3 | |
| Precision and memory | mixed precision, gradient checkpointing, DeepSpeed ZeRO-3 | §4.2 | versions and configs not stated |
| Hardware | 32 V100 GPUs, about 18 hours | app. A | |
| Hard-negative mining | mE5-base, top 100, for datasets without hard negatives | app. A | how one negative is chosen from the 100 is not stated |
| Dataset sample ratios | ELI5 0.1, MS-MARCO passage 0.5, MS-MARCO document 0.2, Quora 0.1, T2Ranking 0.5 | app. A | no ratio stated for the other training datasets |
| Training data size | about 1.8M examples after sampling | §4.2 app. A | |
| Synthetic data | 500k examples, 150k unique instructions, about 180M tokens | §4.1 | |
| Synthetic data source | Azure OpenAI; GPT-4 and GPT-3.5-Turbo (about 25% GPT-3.5) | §4.1 | |
| Generation sampling | temperature 1.0, top-p 1.0 | app. C | |
| Brainstormed tasks per call | about 20 | app. C tab. 8 tab. 9 tab. 10 tab. 11 | |
| Languages | 93 | §4.1 | sampled from XLM-R list, weighted to high-resource languages app. C |
| Eval truncation | first 512 tokens | §4.2 | |
| Eval cost | about 3 days on 8 V100 GPUs | §4.2 | |
| Embedding size | 4096 | [Limitations] | |
| Pooling | last token | §3.2 tab. 5 |
Placeholder values in the synthetic prompt templates tab. 8 to tab. 13:
| Subgroup | Placeholder | Values |
|---|---|---|
| short-long | query type | extremely long-tail, long-tail, common |
| short-long | query length | under five words; five to fifteen words; ten or more words |
| short-long | difficulty | high school, college, PhD |
| short-long | clarity | clear, understandable with some effort, ambiguous |
| short-long | document length (words) | 50, 100, 200, 300, 400, 500 |
| long-short | document length | less than 10, at least 10, at least 50, at least 100, at least 200 |
| long-short | difficulty | high school, college, PhD |
| long-short | clarity | clear, understandable with some effort, ambiguous |
| STS | high score | 4, 4.5, 5 |
| STS | low score | 2.5, 3, 3.5 |
| STS | unit | sentence, phrase, passage |
| STS | difficulty | elementary school, high school, college |
| bitext | high score | 4, 4.5, 5 |
| bitext | low score | 1.5, 2, 2.5 |
| bitext | unit | sentence, phrase, passage |
| bitext | difficulty | elementary school, high school, college |
The short-short and long-long templates list no placeholders beyond the task and language tab. 10 tab. 11.
Results
Author-reported throughout. MTEB here means the 56 English datasets. BEIR means the 15 public retrieval datasets in BEIR. Full-data models use the synthetic data plus labelled data §4.2 app. A. Baselines are as listed in each table, including commercial models whose training data is not public §4.3.
Headline comparisons:
| Setting | Metric | Baseline | This paper | Source |
|---|---|---|---|---|
| Full data, MTEB average | average score | BGE-large-en-v1.5 64.2 | 66.6 | tab. 1 |
| Synthetic data only, MTEB average | average score | E5-large-v2 62.3 | 63.1 | tab. 1 |
| Synthetic plus MS-MARCO, MTEB average | average score | BGE-large-en-v1.5 64.2 | 64.5 | tab. 1 |
| Full data, BEIR average | nDCG@10 | voyage-lite-01-instruct 55.6 (highest in tab. 3 besides this paper) | 56.9 | tab. 3 |
| MIRACL, 16 languages average, dev | nDCG@10 | mE5-large 66.5 | 62.9 | tab. 6 |
| Bitext, BUCC 2018 (4 languages) | metric not stated | mE5-large 98.6 | 98.9 | tab. 4 |
| Bitext, Tatoeba (112 languages) | metric not stated | LaBSE 81.1 | 70.1 | tab. 4 |
| Personalized passkey, 32k tokens | top-1 accuracy | naive window extension: lower | over 90% with RoPE base 10^5 | §5.2 fig. 5 |
Full tables follow, as printed in the paper.
Table 1, MTEB 56 English datasets, category averages tab. 1:
| Model | Class. | Clust. | PairClass. | Rerank | Retr. | STS | Summ. | Avg |
|---|---|---|---|---|---|---|---|---|
| number of datasets | 12 | 11 | 3 | 4 | 15 | 10 | 1 | 56 |
| Glove | 57.3 | 27.7 | 70.9 | 43.3 | 21.6 | 61.9 | 28.9 | 42.0 |
| SimCSE bert-unsup | 62.5 | 29.0 | 70.3 | 46.5 | 20.3 | 74.3 | 31.2 | 45.5 |
| SimCSE bert-sup | 67.3 | 33.4 | 73.7 | 47.5 | 21.8 | 79.1 | 23.3 | 48.7 |
| Contriever | 66.7 | 41.1 | 82.5 | 53.1 | 41.9 | 76.5 | 30.4 | 56.0 |
| GTR xxl | 67.4 | 42.4 | 86.1 | 56.7 | 48.5 | 78.4 | 30.6 | 59.0 |
| Sentence-T5 xxl | 73.4 | 43.7 | 85.1 | 56.4 | 42.2 | 82.6 | 30.1 | 59.5 |
| E5 large-v2 | 75.2 | 44.5 | 86.0 | 56.6 | 50.6 | 82.1 | 30.2 | 62.3 |
| GTE large | 73.3 | 46.8 | 85.0 | 59.1 | 52.2 | 83.4 | 31.7 | 63.1 |
| BGE large-en-v1.5 | 76.0 | 46.1 | 87.1 | 60.0 | 54.3 | 83.1 | 31.6 | 64.2 |
| E5 mistral-7b + full data | 78.5 | 50.3 | 88.3 | 60.2 | 56.9 | 84.6 | 31.4 | 66.6 |
| w/ synthetic data only | 78.2 | 50.5 | 86.0 | 59.0 | 46.9 | 81.2 | 31.9 | 63.1 |
| w/ synthetic + msmarco | 78.3 | 49.9 | 87.1 | 59.5 | 52.2 | 81.2 | 32.7 | 64.5 |
Table 2, MIRACL dev nDCG@10, high-resource and low-resource languages tab. 2:
| Model | en | fr | es | ru | te | hi | bn | sw |
|---|---|---|---|---|---|---|---|---|
| BM25 | 35.1 | 18.3 | 31.9 | 33.4 | 49.4 | 45.8 | 50.8 | 38.3 |
| mDPR | 39.4 | 43.5 | 47.8 | 40.7 | 35.6 | 38.3 | 44.3 | 29.9 |
| mE5 base | 51.2 | 49.7 | 51.5 | 61.5 | 75.2 | 58.4 | 70.2 | 71.1 |
| mE5 large | 52.9 | 54.5 | 52.9 | 67.4 | 84.6 | 62.0 | 75.9 | 74.9 |
| E5 mistral-7b + full data | 57.3 | 55.2 | 52.2 | 67.7 | 73.9 | 52.1 | 70.3 | 68.4 |
Table 3, comparison with commercial and leaderboard models, as of 2023-12-22 tab. 3:
| Model | BEIR | MTEB |
|---|---|---|
| OpenAI text-embedding-3-large | 55.4 | 64.6 |
| Cohere-embed-english-v3.0 | 55.0 | 64.5 |
| voyage-lite-01-instruct | 55.6 | 64.5 |
| UAE-Large-V1 | 54.7 | 64.6 |
| E5 mistral-7b + full data | 56.9 | 66.6 |
Table 4, bitext mining tab. 4:
| Model | BUCC 2018 (4 langs) | Tatoeba (112 langs) |
|---|---|---|
| mContriever | 93.7 | 37.7 |
| LaBSE | 98.8 | 81.1 |
| mE5 base | 98.1 | 68.1 |
| mE5 large | 98.6 | 75.7 |
| E5 mistral-7b | 98.9 | 70.1 |
Table 5, ablations on MTEB, all models trained on synthetic plus MS-MARCO data unless stated. The first row is the default: last-token pooling, LoRA rank 16, natural-language instructions tab. 5:
| Setting | Class. | Clust. | PairClass. | Rerank | Retr. | STS | Summ. | Avg | Delta |
|---|---|---|---|---|---|---|---|---|---|
| E5 mistral-7b (default) | 78.3 | 49.9 | 87.1 | 59.5 | 52.2 | 81.2 | 32.7 | 64.5 | |
| w/ LLaMA-2 7b init. | 76.2 | 48.1 | 85.1 | 58.9 | 49.6 | 81.2 | 30.8 | 62.9 | -1.6 |
| w/ msmarco data only | 71.6 | 47.1 | 86.1 | 58.8 | 54.4 | 79.5 | 31.7 | 62.7 | -1.8 |
| w/ mean pool | 77.0 | 48.9 | 86.1 | 59.2 | 52.4 | 81.4 | 30.8 | 64.1 | -0.4 |
| w/ weighted mean | 77.0 | 49.0 | 86.1 | 59.2 | 52.0 | 81.4 | 30.2 | 64.0 | -0.5 |
| w/ r=8 | 78.4 | 50.3 | 87.1 | 59.3 | 53.0 | 81.0 | 31.7 | 64.8 | +0.3 |
| w/ r=32 | 78.4 | 50.3 | 87.4 | 59.5 | 52.2 | 81.2 | 30.6 | 64.6 | +0.1 |
| w/o instruction | 72.3 | 47.1 | 82.6 | 56.3 | 48.2 | 76.7 | 30.7 | 60.3 | -4.2 |
| w/ task type prefix | 71.1 | 46.5 | 79.7 | 54.0 | 52.7 | 73.8 | 30.0 | 60.3 | -4.2 |
Table 6, MIRACL dev, all 16 languages, nDCG@10 and Recall@100 tab. 6:
| Lang | BM25 | mDPR | mE5 base | mE5 large | E5 mistral full | BM25 R@100 | mDPR R@100 | mE5 base R@100 | mE5 large R@100 | E5 mistral full R@100 |
|---|---|---|---|---|---|---|---|---|---|---|
| ar | 48.1 | 49.9 | 71.6 | 76.0 | 73.3 | 88.9 | 84.1 | 95.9 | 97.3 | 96.0 |
| bn | 50.8 | 44.3 | 70.2 | 75.9 | 70.3 | 90.9 | 81.9 | 96.6 | 98.2 | 96.0 |
| en | 35.1 | 39.4 | 51.2 | 52.9 | 57.3 | 81.9 | 76.8 | 86.4 | 87.6 | 90.2 |
| es | 31.9 | 47.8 | 51.5 | 52.9 | 52.2 | 70.2 | 86.4 | 88.6 | 89.1 | 87.5 |
| fa | 33.3 | 48.0 | 57.4 | 59.0 | 52.1 | 73.1 | 89.8 | 91.2 | 92.9 | 88.0 |
| fi | 55.1 | 47.2 | 74.4 | 77.8 | 74.7 | 89.1 | 78.8 | 96.9 | 98.1 | 96.7 |
| fr | 18.3 | 43.5 | 49.7 | 54.5 | 55.2 | 65.3 | 91.5 | 90.0 | 90.6 | 92.8 |
| hi | 45.8 | 38.3 | 58.4 | 62.0 | 52.1 | 86.8 | 77.6 | 92.6 | 93.9 | 89.9 |
| id | 44.9 | 27.2 | 51.1 | 52.9 | 52.7 | 90.4 | 57.3 | 87.4 | 87.9 | 88.4 |
| ja | 36.9 | 43.9 | 64.7 | 70.6 | 66.8 | 80.5 | 82.5 | 96.0 | 97.1 | 95.1 |
| ko | 41.9 | 41.9 | 62.2 | 66.5 | 61.8 | 78.3 | 73.7 | 91.6 | 93.4 | 89.4 |
| ru | 33.4 | 40.7 | 61.5 | 67.4 | 67.7 | 66.1 | 79.7 | 92.7 | 95.5 | 95.0 |
| sw | 38.3 | 29.9 | 71.1 | 74.9 | 68.4 | 70.1 | 61.6 | 95.6 | 96.7 | 95.5 |
| te | 49.4 | 35.6 | 75.2 | 84.6 | 73.9 | 83.1 | 76.2 | 98.0 | 99.2 | 95.1 |
| th | 48.4 | 35.8 | 75.2 | 80.2 | 74.0 | 88.7 | 67.8 | 98.0 | 98.9 | 96.5 |
| zh | 18.0 | 51.2 | 51.5 | 56.0 | 54.0 | 56.0 | 94.4 | 92.1 | 93.3 | 90.1 |
| Avg | 39.3 | 41.5 | 62.3 | 66.5 | 62.9 | 78.7 | 78.8 | 93.1 | 94.3 | 92.6 |
Table 7, contrastive pre-training ablation tab. 7 fig. 3:
| Setting | Class. | Clust. | PairClass. | Rerank | Retr. | STS | Summ. | Avg |
|---|---|---|---|---|---|---|---|---|
| XLM-R large + full data | 72.9 | 38.7 | 84.5 | 53.8 | 42.0 | 82.3 | 29.7 | 58.0 |
| XLM-R large w/ cont. pre-train | 77.2 | 47.3 | 85.5 | 58.6 | 50.2 | 84.4 | 30.7 | 63.7 |
| E5 mistral-7b + full data | 78.5 | 50.3 | 88.3 | 60.2 | 56.9 | 84.6 | 31.4 | 66.6 |
| E5 mistral-7b w/ cont. pre-train | 78.7 | 50.1 | 87.7 | 60.9 | 56.9 | 84.9 | 30.2 | 66.7 |
The paper pre-trains Mistral-7B with the mE5 recipe for 10k steps in the last row tab. 7.
Table 17, per-dataset MTEB scores, four settings tab. 17:
| Dataset | w/ synthetic only | w/ synthetic + msmarco | w/o synthetic data | full data |
|---|---|---|---|---|
| BIOSSES | 84.2 | 81.0 | 85.4 | 85.5 |
| SICK-R | 78.6 | 78.5 | 81.7 | 82.6 |
| STS12 | 75.8 | 74.7 | 77.9 | 79.7 |
| STS13 | 84.3 | 85.3 | 88.0 | 88.4 |
| STS14 | 80.9 | 81.2 | 83.7 | 84.5 |
| STS15 | 86.2 | 86.8 | 89.5 | 90.4 |
| STS16 | 85.0 | 85.3 | 86.5 | 87.7 |
| STS17 | 87.3 | 87.7 | 91.0 | 91.8 |
| STS22 | 66.0 | 67.1 | 66.2 | 67.0 |
| STSBenchmark | 83.5 | 84.0 | 87.8 | 88.6 |
| SummEval | 31.9 | 32.7 | 31.9 | 31.4 |
| SprintDuplicateQuestions | 93.5 | 95.8 | 96.0 | 95.7 |
| TwitterSemEval2015 | 78.0 | 78.5 | 81.7 | 81.6 |
| TwitterURLCorpus | 86.5 | 86.9 | 87.7 | 87.8 |
| AmazonCounterfactualClassification | 79.6 | 79.9 | 77.2 | 78.7 |
| AmazonPolarityClassification | 95.8 | 95.9 | 93.9 | 95.9 |
| AmazonReviewsClassification | 56.9 | 55.5 | 48.2 | 55.8 |
| Banking77Classification | 86.2 | 87.0 | 88.8 | 88.2 |
| EmotionClassification | 49.2 | 47.6 | 51.0 | 49.8 |
| ImdbClassification | 94.8 | 94.9 | 89.0 | 94.8 |
| MassiveIntentClassification | 79.8 | 79.9 | 79.6 | 80.6 |
| MassiveScenarioClassification | 81.7 | 82.4 | 82.3 | 82.4 |
| MTOPDomainClassification | 95.6 | 95.9 | 95.7 | 96.1 |
| MTOPIntentClassification | 84.9 | 85.9 | 83.4 | 86.1 |
| ToxicConversationsClassification | 70.2 | 70.8 | 70.9 | 69.6 |
| TweetSentimentExtractionClassification | 63.5 | 63.4 | 61.6 | 63.7 |
| AskUbuntuDupQuestions | 64.3 | 65.3 | 67.4 | 67.0 |
| MindSmallReranking | 33.1 | 32.8 | 32.5 | 32.6 |
| SciDocsRR | 86.0 | 86.0 | 85.7 | 86.3 |
| StackOverflowDupQuestions | 52.5 | 53.7 | 55.9 | 54.9 |
| ArxivClusteringP2P | 51.4 | 51.2 | 47.8 | 50.5 |
| ArxivClusteringS2S | 46.5 | 44.9 | 44.6 | 45.5 |
| BiorxivClusteringP2P | 44.5 | 43.3 | 36.9 | 43.5 |
| BiorxivClusteringS2S | 40.9 | 40.1 | 37.0 | 40.2 |
| MedrxivClusteringP2P | 40.5 | 39.9 | 32.6 | 38.2 |
| MedrxivClusteringS2S | 38.0 | 37.9 | 32.8 | 37.5 |
| RedditClustering | 56.3 | 55.9 | 63.1 | 57.7 |
| RedditClusteringP2P | 66.3 | 64.8 | 66.4 | 66.5 |
| StackExchangeClustering | 72.9 | 72.7 | 74.5 | 73.1 |
| StackExchangeClusteringP2P | 46.1 | 45.6 | 34.3 | 45.9 |
| TwentyNewsgroupsClustering | 52.2 | 52.5 | 55.6 | 54.3 |
| ArguAna | 52.2 | 42.7 | 62.5 | 61.9 |
| ClimateFEVER | 21.1 | 28.8 | 25.2 | 38.4 |
| CQADupstackAndroidRetrieval | 40.8 | 36.0 | 44.5 | 43.0 |
| DBPedia | 42.0 | 43.7 | 47.7 | 48.9 |
| FEVER | 72.5 | 83.5 | 73.1 | 87.8 |
| FiQA2018 | 38.1 | 48.4 | 54.5 | 56.6 |
| HotpotQA | 48.1 | 64.0 | 75.6 | 75.7 |
| MSMARCO | 25.7 | 45.0 | 42.9 | 43.1 |
| NFCorpus | 35.5 | 40.0 | 35.3 | 38.6 |
| NQ | 53.3 | 63.5 | 57.3 | 63.5 |
| QuoraRetrieval | 75.0 | 79.5 | 89.5 | 89.6 |
| SCIDOCS | 20.6 | 15.8 | 19.0 | 16.3 |
| SciFact | 71.5 | 71.9 | 74.7 | 76.4 |
| Touche2020 | 25.4 | 32.5 | 19.1 | 26.4 |
| TRECCOVID | 82.3 | 87.3 | 70.8 | 87.2 |
| Average | 63.1 | 64.5 | 64.6 | 66.6 |
Other results in prose, with their figures and tables:
- Long context §5.2 fig. 4 fig. 5: the personalized passkey task has each document carry a person's name and a random passkey at a random position, with 100 candidates. Each context length uses 50 random queries. The 4k-window default reaches 100% within 4k tokens and degrades beyond it. Naively enlarging the window to 32k is worse. A RoPE base of 10^5 gives over 90% within 32k tokens, with a small loss on shorter contexts. The paper does not quantify that loss in the text.
- Training-data effect §5.1 fig. 3 tab. 7: contrastive pre-training helps XLM-R large by 8.2 retrieval points but has negligible effect on Mistral-7B.
- Instructions §5.3 tab. 5: removing the instruction costs 4.2 average points; the task-type prefix variant costs the same.
- Contamination app. B: a string-match check on MTEB test sets found no substantial contamination that would change the main findings.
Paper vs code
Searched: the paper's artifacts paragraph links github.com/microsoft/unilm
under the e5 folder app. A. The repository is by the authors' organisation,
so it was used without further search. It was cloned at depth 1 at commit
31c5b904ca1bf2afb4c234a6675c683a4e5fc7cd and its root LICENSE is MIT.
- Coverage: the
e5/folder contains evaluation scripts only: MTEB retrieval, MTEB non-retrieval, shared helpers, a model-config table and two shell scripts mteb_beir_eval.py README.md. No training loop, LoRA setup, loss, data-generation script or passkey experiment is in the repository, although the paper says the implementation is based on the HuggingFace PEFT library app. A. Every training detail above is therefore paper-only. - Query instruction: the paper's equation 1 and the code's format match.
The code builds
Instruct: {task}\nQuery:and prepends it to each query utils.py mteb_beir_eval.py [code: e5/mteb_beir_eval.py#L111-L112]. - Document text: the paper says documents get no instruction prefix §3.2. The code does not add one for instruct models, but it builds each BEIR document as title plus space plus text, using the title when the corpus has one mteb_beir_eval.py. The paper does not mention titles.
- [EOS] token: the paper appends [EOS] to queries and documents §3.2. The evaluation code never adds an EOS token; it tokenises with the default tokenizer call utils.py. Whether the tokenizer appends one is not checked here.
- Pooling: the default for the Mistral model is
last, which matches the paper's last-token default tab. 5 model_config.py. The pool function takes the final position when the batch is left-padded, and otherwise the last non-padding position utils.py. Behaviour therefore depends on the tokenizer's padding side. - Normalisation: retrieval embeddings are L2-normalised [code: e5/mteb_beir_eval.py#L84], which makes the dot product equal to the cosine of equation 3. Non-retrieval tasks are normalised except for classification mteb_except_retrieval_eval.py. The paper does not state this.
- Non-retrieval protocol: the code prepends the task instruction to every input, including both sides of pair tasks such as STS mteb_except_retrieval_eval.py [code: e5/mteb_except_retrieval_eval.py#L103-L106]. The paper does not describe the non-retrieval protocol §4.2.
- Length: evaluation truncates to 512 tokens, matching §4.2 [code: e5/utils.py#L73-L82]. Training truncation at 512 app. A cannot be checked.
- Precision: evaluation loads weights in float16 and runs under autocast mteb_beir_eval.py mteb_beir_eval.py. The paper does not state an evaluation precision.
- Task instructions: the retrieval instruction strings I compared match the paper's evaluation instruction table, for example ArguAna, NQ and SciFact utils.py tab. 15. The paper's training instructions tab. 14 are not in the code.
- Released checkpoint: the README reports 56.9 BEIR for
e5-mistral-7b-instructREADME.md, which matches the paper's full-data BEIR number tab. 3. That match does not verify the training recipe, since the training code is absent. - Released artefacts: the paper says it releases models and evaluation scripts
at
unilm/e5app. A. The README links only the passkey dataset README.md. No synthetic training data is in the repository.
Pitfalls
- Training is underspecified. Not stated: optimizer, LoRA alpha and dropout, reduction of the loss over the batch, whether batches mix datasets, the precision used in training, and how one hard negative is chosen from the top 100 mined by mE5-base app. A.
- Equation 2 uses the positive and all negatives in its denominator. The paper does not say whether a hard negative of one query counts as a negative for every other query in the batch. The pseudocode above assumes it does.
- Not every generated example is a query-document pair. Long-short examples carry an input text, a label and a misleading label tab. 9. Symmetric examples are triples with graded scores tab. 12 tab. 13. Short-short and long-long examples have no negative document tab. 10 tab. 11. The paper does not say how these become positive and negative pairs, or how the scores are used.
- The text and the table disagree on one placeholder. Section 3.1 gives query lengths as "less than 5 words, 5-10 words, at least 10 words" §3.1. Table 8 gives "5 to 15 words" tab. 8. Follow the table if you are reproducing the templates, and note the conflict.
- Data quality: the paper says part of the GPT-3.5-Turbo output does not follow the template guidelines, and kept it §4.1. Filtering is limited to JSON parsing and exact-string duplicates §3.1.
- Contamination: the check in app. B is string matching. It found four DBPedia test questions in TriviaQA training data and notes overlapping Wikipedia corpora across DBPedia, NQ and TriviaQA. Several training sets are also MTEB evaluation sets: MS-MARCO, NQ, HotpotQA, FEVER and Quora app. A tab. 17. The paper does not report results with those removed.
- Long context: the paper calls the 4k setting a "sliding window size" without defining it further. It does not say whether the RoPE base change of 10^5 is applied during training or only at inference §5.2. The passkey data is on HuggingFace README.md. The passkey code is not released.
- Low-resource languages: the model is weaker there. In Table 2, sw scores 68.4 against mE5-large 74.9 tab. 2. On bn it is level with mE5-base, 70.3 against 70.2 tab. 6. Only about 1k synthetic examples per low-resource language were generated on average §4.1.
- The paper says a fair comparison with commercial models is not feasible, because their details are not public §4.3. The leaderboard comparison is dated 2023-12-22 tab. 3.
- Terms of the generator: the paper does not discuss the terms under which GPT-4 and GPT-3.5-Turbo outputs were used. Check the provider terms before you reproduce the data pipeline.
- Cost: about 180M generated tokens §4.1; about 18 hours on 32 V100 GPUs app. A; about 3 days of evaluation on 8 V100 GPUs §4.2; embeddings of 4096 dimensions [Limitations].
- Retrieval needs the instruction. The same instruction must be used at query time. Documents are encoded without any prefix, so the document index never has to be rebuilt when the task changes §3.2 §5.3.
Lineage
- Builds on: E5, the multi-stage baseline this paper argues against §1. Also the Mistral-7B base model, Mistral 7B §4.2.
- Uses, without a card here: the LoRA recipe follows RankLLaMA, and LoRA itself §4.2. The position-weighted mean pooling is taken from SGPT app. A.
- Compared against: mE5 (multilingual), BGE, GTE, GTR, Sentence-T5, Contriever, SimCSE, UAE-Large-V1, and commercial embedding APIs tab. 1 tab. 2 tab. 3.
Source and license
Adapted from “Improving Text Embeddings with Large Language Models” by Liang Wang, Nan Yang, Xiaolong Huang, Linjun Yang, Rangan Majumder, Furu Wei (arXiv:2401.00368), used under CC BY 4.0. Changes: condensed and restructured for implementation, with tables, equations and algorithms taken from the paper and its code, each cited to its source. Not affiliated with or endorsed by the authors. Code citations refer to https://github.com/microsoft/unilm at commit 31c5b904ca1b (MIT). Any quoted code is shown under that license.