Pathway to Relevance: How Cross-Encoders Implement a Semantic Variant of BM25
Read first: Axiomatic Causal Interventions for Reverse Engineering Relevance Computation in Neural Retrieval Models · A Mathematical Framework for Transformer Circuits
TL;DR. Lu, Chen and Eickhoff reverse-engineer ms-marco-MiniLM-L-12-v2, a 12-layer BERT-style cross-encoder, and find that it rebuilds BM25 out of attention. Matching heads compute a semantic term frequency (soft TF) as attention mass from each query token to exact and similar document tokens. That attention already shows saturation and length penalties. The top singular vector of the embedding matrix stores IDF. Four late relevance scoring heads let [CLS] collect IDF-weighted soft TF. A linear model built only from these pieces predicts the cross-encoder’s score with r = 0.8157, against 0.4200 for tuned BM25.
Why it matters now. It gives a detailed causal analysis of a relevance circuit in a MiniLM cross-encoder (the authors describe it as the first to causally uncover such a circuit in neural IR). For an IR researcher it answers a long-standing question in IR terms: does BERT re-learn the classical heuristics? The answer is yes, in a semantic form, with an extra step BM25 lacks (query contextualisation). The circuit also gives handles for editing. Changing one number per token in the embedding matrix changes how much the model weights that term, which the authors use for safety filtering and domain adaptation.
Key idea
Section titled “Key idea”BM25 as a hypothesis.
Each part is mapped to an axiom, and each axiom gets a diagnostic dataset of minimal pairs built from MS MARCO (Table 1):
| BM25 part | Axiom | Perturbation (baseline → perturbed) |
|---|---|---|
| TF | TFC1 | append one more copy of a query term |
| soft TF | STMC1 | append the most similar synonym (chosen from GPT-4o candidates by embedding similarity) |
| saturation () | TFC2 | restore the term step by step in a pronoun-only document |
| length () | LNC1 | append more and more non-relevant sentences |
| IDF | TDC | no pairs; found with SVD instead |
Path patching backwards. Starting from the output logit, patch each head’s contribution on a specific path from the perturbed run into the baseline run. Keep heads whose patching shifts the score toward the perturbed one, then repeat with those heads’ inputs as the new target. This finds which components carry the signal and through which edges (§3.3, App. C).
IDF from SVD. Write . The top left singular vector assigns one number per vocabulary token, and it correlates at r = −0.7136 with MS MARCO IDF (§4.4). Edit a token’s entry and you change its importance.
Testing the circuit. For each query token, take , the matching score (attention mass from to the document, summed over matching heads), and their product. Fit a linear regression to the cross-encoder’s score (§5).
Key results
Section titled “Key results”- Relevance scoring heads (§4.1). Path patching to the logit picks out 10.1, 10.4, 10.7 and 10.10. Their effects are larger on TFC1 than STMC1, so exact matches count more than semantic ones. [CLS]-to-query attention in these heads correlates with IDF at an average r = 0.67.
- Query contextualisation heads (§4.2). 8.10 and 9.11 receive the matching signal and make all query tokens attend to one or two high-IDF query tokens (IDF correlation r = 0.781 and 0.829). BM25 has no step like this: it scores terms independently.
- Matching heads (§4.3). Thirteen heads (0.8, 1.7, 2.1, 3.1, 4.9, 5.7, 5.9, 6.3, 6.5, 7.9, 8.0, 8.1, 8.8). Their attention between query and document tokens correlates with embedding cosine similarity at r = 0.500, against 0.132 for other heads. Mean-ablating them lowers the average logit from 5.146 to −4.394 on TFC1 and from −1.998 to −4.611 on STMC1. On TFC2, attention rises sharply after the first occurrence and then plateaus (saturation). On LNC1 it falls as irrelevant sentences are added (length normalisation).
- IDF editing is causal (§4.4). With doc1 = the first query token repeated and doc2 = the second repeated, raising token 1’s IDF through raises doc1’s score more than doc2’s, and lowering it does the reverse.
- BM25-like fit (§5.2, App. G). On MS MARCO (queries of up to five tokens, 80/20 split), the linear model reaches r = 0.8157 vs 0.4200 for BM25 with tuned , . On 12 BEIR datasets, BM25 top-10 candidates and query lengths 1–22, it gets median Pearson 0.8401, median Spearman 0.7619 and 88.4% agreement with the cross-encoder’s NDCG@10.
- Uses (§6). Lowering the IDF of unsafe tokens makes the safe document rank above the unsafe one in 80.396% of 17,537 adversarial samples, with nDCG 0.9861 (a 1.39% drop). On NFCorpus, aligning token IDFs before fine-tuning gives the best NDCG@1, and fine-tuning only the embedding matrix is not significantly worse than full fine-tuning (three seeds).
Limitations & open questions
Section titled “Limitations & open questions”- One model. A single MiniLM cross-encoder. Whether larger cross-encoders, ELECTRA rerankers or LLM rerankers use the same circuit is untested.
- Not all of the score. The linear model leaves part of the variance unexplained. The authors point to non-linearity, MLP layers they did not analyse, possibly more heads, and world knowledge (as ABNIRML found for T5 and ColBERT).
- BM25 is a chosen reference. TF-IDF and query-likelihood share the same heuristics, so the circuit may equally be described in their terms.
- Synthetic pairs. Appended terms and GPT-4o synonyms produce unnatural documents, as in the axiomatic interventions paper.
- Open: what query contextualisation computes, and whether it relates to term dependence or proximity axioms. Appendix H argues that earlier findings that BERT “violates” axioms came from testing axioms one at a time instead of in combination.
Connections
Section titled “Connections”- Axiomatic causal interventions is the predecessor: TFC1 only, activation patching, a bi-encoder. Its duplicate-token heads match this paper’s matching heads.
- Activation patching explains why the choice of corruption and metric matters. Path patching is the edge-level version.
- ROME edits an MLP to change a fact. Here a single embedding direction is edited to change term importance: the same “localise, then edit” pattern.
- SPARSEUP and ColBERT build term matching into the architecture. This paper shows a cross-encoder learns it on its own.
- Probing ranking LLMs asks the correlational version of the same question for RankLlama and finds some BM25 ingredients but not BM25 itself.
- MechIR is the tooling for running this kind of analysis.
Questions to think through
These questions have no single right answer. Write or say your answer before you open the hints. Mark a question once you could defend your answer in a reading group.
- Derive / compute
The paper approximates the cross-encoder score by a linear model over, for each query token, −U₀(q_i), the matching score MS_total(q_i, d) and their product. Starting from BM25 = Σ_t IDF(t)·f(TF(t,d)), explain which term plays which role, and why the product term is needed.
What a strong answer covers
- BM25 sums, over query terms, IDF times a saturating, length-normalised TF factor.
- −U₀(q_i) stands in for IDF: the top left singular vector of the embedding matrix correlates at r = −0.7136 with MS MARCO IDF, so its negative tracks IDF.
- MS_total is a weighted sum (13 learned weights α_k) of each matching head's attention mass from q_i to document tokens: a soft TF that already includes saturation and length effects.
- The product −U₀·MS_total is the IDF × TF interaction; with only additive terms the model could not express "a match on a rare term counts more".
- Mechanism
Trace one query term from the embedding layer to the [CLS] logit through the circuit the paper reports, naming each head group and what it reads and writes.
What a strong answer covers
- Embeddings: each token's value on U₀ carries its IDF; path patching shows embeddings are the main input to matching heads.
- Matching heads (13, e.g. 0.8, 1.7, 4.9 … 8.8) in early and middle layers: query and document tokens attend to exact and semantically similar copies, so the attention mass from a query token to the document is a soft TF. Their attention also saturates with repetition and falls with irrelevant length.
- Query contextualisation heads 8.10 and 9.11: all query tokens attend to one or two high-IDF query tokens (r = 0.781 and 0.829 with IDF), spreading their matching signal across the query.
- Relevance scoring heads 10.1, 10.4, 10.7, 10.10: [CLS] attends to query tokens, each head covering a different IDF band (10.1 high, 10.10 low), collecting IDF-weighted soft TF for the classifier.
- What if…
Which two interventions in the paper go beyond correlation to show that the matching heads and U₀ are used, and what did each show?
What a strong answer covers
- Mean-ablating the 13 matching heads drops average logits on perturbed samples (TFC1: 5.146 → −4.394; STMC1: −1.998 → −4.611), so they are needed for the match signal.
- Editing a token's value on U₀ (lowering it raises its effective IDF) changes the score monotonically: with doc1 = repeated first query token, raising that token's IDF raises doc1's score more than doc2's, and lowering it does the reverse.
- Path patching itself is causal: replacing a head's input along a specific path shows which edges carry the soft-TF signal.
- The linear-model fit (r = 0.8157) is not an intervention; it tests whether the discovered pieces are sufficient to predict the score.
- Critique
The circuit's linear model reaches r = 0.8157 with the cross-encoder's scores, versus 0.4200 for tuned BM25. What does this number establish and what does it leave open?
What a strong answer covers
- It shows the features read off the circuit (U₀ and matching-head attention) predict the cross-encoder's score much better than BM25 does, so the circuit captures the main mechanism.
- It is correlational and was first fit on MS MARCO with queries of five tokens or fewer; App. G extends to 12 BEIR datasets and lengths 1–22, with median Pearson 0.8401 but median Spearman 0.7619 (median p = 0.072).
- About a third of the variance is unexplained: the linear model misses non-linearity, MLP layers, possibly other heads, and world knowledge (the authors list these).
- The comparison is to BM25 only; TF-IDF or query-likelihood use similar heuristics, so "BM25-like" is the authors' reference point rather than a unique identification.
- Design
The paper uses U₀ editing to demote unsafe tokens. Design a similar intervention for a domain shift you care about, for example making a cross-encoder treat a domain's jargon as high-IDF, and say how you would check that ranking quality is preserved.
What a strong answer covers
- Compute the target corpus's IDF, then move each token's U₀ value so the model's internal IDF matches (lower U₀ = higher IDF), as in the IDF-aligned condition.
- Measure nDCG@10 on in-domain queries before and after, and on MS MARCO or another general set as a control, since the edit changes a shared embedding.
- Check for side effects on tokens that share subwords, and sweep the edit scale: the paper's scaling curves show non-monotonic regions.
- Compare to fine-tuning only the embedding matrix, which the paper's NFCorpus experiment suggests may be enough for adaptation.
- Research idea
Query contextualisation heads have no counterpart in BM25, which scores each query term independently. Propose a research question about them and an experiment to answer it.
What a strong answer covers
- Question: do these heads implement something like query-term dependence or proximity, where a weak term's weight depends on whether the high-IDF term matched?
- Experiment: build pairs where the high-IDF term matches in both documents but a low-IDF term matches in only one, then patch 8.10 and 9.11 to see whether the low-IDF term's contribution changes.
- Compare with axioms beyond BM25 (e.g. term proximity or semantic coverage) as the diagnostic datasets.
- Check whether the same heads exist in other cross-encoders or LLM rerankers, using MechIR-style tooling.