Represent a document by the counts of its words.
A query is scored by a weighted sum over the words it shares with the document. The two decisions are how to weight a word across the corpus and how to weight it within a document.
Across the corpus. A word that occurs in nearly every document tells you nothing; a word that occurs in few documents tells you a lot. Sparck Jones (1972) proposed weighting a word by the log of the inverse of its document frequency. The following result puts that weight on a probabilistic footing.
Let indicate whether a document is relevant to a fixed query, and let indicate whether the document contains term . The binary independence model assumes that, given , the are independent. Write and , and assume for terms that are not in the query.
Theorem 4.1 (term weights under binary independence). Under the binary independence model, the posterior odds that a document with term vector is relevant are where does not depend on the document. Ranking by posterior odds is therefore ranking by the sum of over the query terms that the document contains.
Proof. By Bayes’ rule the posterior odds equal the prior odds times . By independence this ratio is . Each factor equals . For the assumption makes the factor equal to one. The product of the factors over does not depend on , and the remaining product is .
The theorem has not yet produced an IDF. For that we need values of and . Almost all documents are not relevant, so , where is the number of documents containing and is the corpus size. If we know nothing about relevant documents we may set , which makes . Then . The usual estimate adds one half to each count to keep the logarithm finite, and the implementation here adds one inside the logarithm so that a term in more than half of the documents gets a small positive weight instead of a negative one: The weight is large for rare terms and close to zero for ubiquitous ones. the companion book example shows how large the spread is in this corpus: the mean IDF is 7.40 for entity words, 4.18 for topic words, 2.87 for common words and 0.69 for attribute words, which occur in about half of all documents.
Within a document. Raw term frequency over-rewards repetition: a document that says “mitochondria” twenty times is probably not twenty times more relevant than one that says it three times. Robertson and Zaragoza (2009) motivate a saturating function through the 2-Poisson model of “eliteness”: a document is either about a term or not, and term frequency is a noisy signal of which. Once a document has plausibly shown that it is about the term, further occurrences add little evidence. The BM25 score is where is the length of and the mean length. The factor in is increasing and concave, equals one at when , and cannot exceed . Its marginal gain from one more occurrence is with , which decays quadratically. The parameter interpolates between no length normalisation () and full normalisation (), since a long document has more chances to contain a term by accident.
The saturation table shows the limit in numbers: with the factor is 1.96 at and 2.15 at , against a limit of 2.2.
The parameter grid is a lesson in humility. Across and the development nDCG@10 ranges only from 0.5846 to 0.5976, the best cell is , , and on the test queries plain TF-IDF cosine (nDCG@10 0.603) is not worse than BM25 (0.599). Here the evidence is one rare word, and a ranking built on one word is insensitive to the shape of the term-frequency curve. That does not mean BM25 does not matter; the last test shows when it does. For each of 300 queries we add a spam document that repeats two of the query’s topic words 40 times each, and count how often it is ranked first. With the share is 0.170 at , 0.303 at , 0.580 at , and 0.750 when saturation is effectively removed (, which makes the tf factor linear). Saturation is a defence against term-frequency manipulation, and a partial one. the companion book example returns to what happens when the manipulation is deliberate.
The recall of the sparse methods is capped by vocabulary mismatch: recall@10 is 0.523 for both TF-IDF and BM25, close to the 0.504 of relevant documents that contain the query’s entity word. A word-matching method cannot know that the alias and the name refer to one entity. A dense method can learn it.
Continue with the book
Explore the full treatment, worked examples, and exercises in Applied AI Under Uncertainty.
Companion article for Applied AI Under Uncertainty, published by Choral Software. Article text and original examples © 2026 Choral Software. All rights reserved.
