↑↓ move Enter open ⌘K find from any page 256 of 256 tabs
Loading the recording…

Ranking by the words a question shares

BM25 scores a paragraph for a question from the words they share, with no model and no training. It answers two questions about every shared word: how rare is it in the collection, and how often does this paragraph use it compared with how long the paragraph is? Rare words that a paragraph repeats count most. Decades after it was designed, BM25 is still the baseline every neural retriever is measured against, and on many collections a hard one to beat.

This tab runs it on the same 2,067 SQuAD paragraphs and 300 questions as every Retrieval tab, with bm25s's version of the Lucene formula, and , so its numbers sit beside the Embeddings tab's dense retriever, bge-small-en-v1.5.

Text to terms

BM25 sees a text as a bag of terms. The Text to terms panel shows the steps on the question: lowercase it, keep every run of two or more letters or digits, drop 33 stopwords (the, of, is …), and cut each remaining word to its stem with the Snowball English stemmer, so historians and historian become one term, historian. Word order is gone. Over the corpus, 250,003 words become 171,770 terms, 16,190 of them distinct; 49.2% of those occur in only one paragraph.

The paragraph below the question is shaded where it holds one of the question's terms, by what that term adds to its score. Its length is its number of terms after the stopwords; the average over the corpus is 83.1.

Inverse document frequency

A term that occurs everywhere says little about any one paragraph; a rare one says a lot. If of the paragraphs contain term , its inverse document frequency is

With , a term in one paragraph gets 7.23 and one in half of them about 0.69. In the first featured question, exagger (the stem of exaggerate) is in 5 paragraphs and weighs 5.93, while some is in 334 and weighs 1.82. The Inverse document frequency bars show every term of the selected question. The 1 inside the logarithm is Lucene's change to Robertson's original formula, which goes negative for a term in more than half the paragraphs.

Saturation and length normalization

The second factor rewards a paragraph for using the term more often, with diminishing returns:

where counts term in paragraph . The fraction is 0 for an absent term and rises towards 1 with every repeat: sets how quickly repeats stop helping, and scales the denominator by the paragraph's length relative to the average, so a long paragraph needs more repeats for the same weight. The Term frequency, saturated chart draws the fraction for this paragraph's length and for half, one and two times the average. A term the question repeats counts once per occurrence. The classic form multiplies by , which scales every score alike and changes no ranking.

The One question's score, term by term bars split each of the ten best paragraphs' scores into those terms. The toolbar's and buttons rescore the featured questions on the page from the recorded posting lists, and the grid at the right gives nDCG@10 over all 300 questions for every setting. It is flat over a wide range: from 0.734 at , (no length normalization, slow saturation) to 0.845 at , , with the default at 0.838.

Against dense retrieval

On these questions BM25 puts the relevant paragraph first more often than bge-small does, Recall@1 0.733 against 0.673, and its nDCG@10 is higher, 0.838 against 0.810; bge-small finds more of them somewhere in its top 100 (1.000 against 0.983). SQuAD's questions were written by people looking at the paragraph, so they reuse its words, which favours exact matching.

The two methods fail on different questions. The table at the right counts them: both put the relevant paragraph first for 167 questions, only BM25 for 53, only bge-small for 35, neither for 45. A dense model matches meaning but can miss a rare name or number; BM25 matches strings exactly but cannot see that two different words mean the same thing. The Hybrid tab fuses the two lists, and the SPLADE tab learns term weights, and terms a text never says, with a language model.

Where it came from

Spärck Jones introduced inverse document frequency in 1972. Robertson and colleagues derived term weighting from a probabilistic model of relevance in the 1970s, and BM25 (Best Match 25) came out of their Okapi system at City University London, where Robertson and Walker's approximations to a 2-Poisson model gave the saturating term-frequency factor in 1994. Robertson and Zaragoza's 2009 survey sets out the whole framework. Kamphuis and colleagues compared the variants that search engines actually implement and found the differences small; bm25s, used here, implements several of them with sparse matrices in Python.

Papers

  1. The Probabilistic Relevance Framework: BM25 and Beyond Stephen Robertson, Hugo Zaragoza · Foundations and Trends in Information Retrieval 2009 The survey of the probabilistic relevance framework that BM25 comes from, with the derivation of its IDF and saturation.
  2. Some Simple Effective Approximations to the 2-Poisson Model for Probabilistic Weighted Retrieval S. E. Robertson, S. Walker · SIGIR 1994 Introduces the saturating term-frequency factor and the length normalization that BM25 uses.
  3. A statistical interpretation of term specificity and its application in retrieval Karen Spärck Jones · Journal of Documentation 1972 Introduces inverse document frequency: weighting a term by how few documents contain it.
  4. Which BM25 Do You Mean? A Large-Scale Reproducibility Study of Scoring Variants Chris Kamphuis, Arjen P. de Vries, Leonid Boytsov, Jimmy Lin · ECIR 2020 Compares the BM25 variants search engines implement, including the Lucene variant this tab records.
  5. BM25S: Orders of magnitude faster lexical search via eager sparse scoring Xing Han Lù · arXiv 2024 The library this tab's drawer is checked against: BM25 scores precomputed into a sparse matrix.
  6. BEIR: A Heterogenous Benchmark for Zero-shot Evaluation of Information Retrieval Models Nandan Thakur, Nils Reimers, Andreas Rücklé, Abhishek Srivastava, Iryna Gurevych · NeurIPS Datasets and Benchmarks 2021 Shows BM25 as a robust zero-shot baseline that many neural retrievers fail to beat outside their training data.

See also