Learn · The Art of Not Looking
budding
Rare Words Are Evidence
Ranking begins when a match changes belief. Rarity supplies the odds, repetition saturates, and length explains how repetition arose.
“The general object of statistical weighting schemes is to assign high values to discriminating terms.”
— Stephen E. Robertson and Karen Spärck Jones, “Relevance Weighting of Search Terms”
This is the sixth chapter in a book about search from first principles. The first five chapters established which documents truly match. Here you will derive a term's relevance weight as a log-odds ratio, see the collection-only Robertson–Spärck Jones estimate emerge when relevance judgments are absent, and distinguish that signed weight from popular nonnegative IDF variants. You will derive the asymptote and derivative of term-frequency saturation, treat length normalization as an interpolation with two meaningful endpoints, and assemble BM25 term by term. You will also see why low weight is not the same as deleting a stopword and why BM25's false independence assumption can remain a useful approximation. The next chapter asks what happens when the same term occurs in a title, path, heading, and body.
The librarian does not count every word equally
A reader asks for “the apple pie.” Imagine a librarian hearing the words one at a time.
theappears in almost every document and barely narrows the shelves;appleremoves much of the room;piemay leave one small neighborhood.
The useful question is not “did the term occur?” but “how much should seeing this term change belief that the document is relevant?”
Raw term frequency answers a different question. A 40-page history of orchards might mention apple 80 times. A one-page recipe that directly answers the query might mention it 4 times. Counting alone rewards the long document for having more opportunities to repeat.
Relevance — whether a document satisfies the information need represented by the query. It is a judgment about the document–need pair, not an intrinsic property of either one. Learn more.
Odds turn evidence into addition
Let mean that a document is relevant to the query. For one query term , define
and
Seeing changes the odds of relevance by the likelihood ratio
But absence also carries information. Compare the odds for a document where the term occurs with the odds for a document where it does not. The resulting binary-independence weight is
Log-odds — the logarithm of . A likelihood ratio multiplies prior odds; taking its logarithm turns independent multiplicative evidence into an additive score. Learn more.
The logarithm is not cosmetic compression. Under the model's conditional- independence assumption, likelihood ratios for query terms multiply. Logs turn that product into a sum:
That additive form will later let term contributions be accumulated in any grouping and bounded before every document is fully scored.
The sign has meaning:
- gives positive evidence;
- gives zero evidence;
- gives negative evidence under the model.
Ranking by any positive-base logarithm gives the same order. The base changes units, not winners.
Estimating the weight without relevance judgments
Suppose the corpus has:
- documents;
- documents containing term ;
- judged-relevant documents;
- judged-relevant documents containing .
With half-count smoothing, estimate
and
Substitution into the log-odds ratio yields the Robertson–Spärck Jones relevance weight
Most first-pass searches have no query-specific relevance judgments. A common neutral estimate takes and estimates nonrelevant occurrence from the whole collection. The weight reduces to
Now rarity has emerged from an odds model. When is small, the numerator dominates and the weight is positive. At about half the corpus it crosses zero. Above half, the raw RSJ weight is negative: under these assumptions, presence is more characteristic of nonrelevant documents than relevant ones.
Inverse document frequency is a corpus statistic with a probabilistic interpretation. It is not a dictionary of which words matter in every domain.
There is more than one formula called IDF
Implementations often need nonnegative term contributions for pruning, explanation, or product behavior. Two common alternatives are
and
Both approach zero as approaches . Neither is algebraically identical to the signed RSJ weight. Flooring negative RSJ values at zero is another policy. These choices can change rankings and whether an upper-bound algorithm is legal, so an index and query engine must name the exact variant rather than store a field called merely idf.
For :
| signed RSJ | qualitative reading | |
|---|---|---|
| 1 | large positive | highly discriminating |
| 100 | positive | useful collection evidence |
| 500 | zero | presence alone does not move the modeled odds |
| 900 | negative | common enough to be evidence against relevance in the raw model |
| 1000 | strongly negative | ubiquitous presence cannot distinguish relevant documents |
The last row exposes an often-repeated but incorrect simplification: the raw RSJ expression does not tend to zero for a ubiquitous term. Nonnegative variants do. A careful system says which one it uses and why.
The tenth occurrence is not ten first occurrences
Document frequency measures how widely a term is distributed. Term frequency measures how often it occurs in one document. Linear frequency would give every repetition the same increment:
That rewards verbosity and repetition without limit. BM25 uses a saturating shape. Start with
where . Its asymptote is
and its derivative is
The derivative is positive and decreases toward zero. Every additional occurrence helps, but each helps less than the previous one.
BM25 commonly multiplies by :
This makes the contribution equal to 1 when while preserving the ranking shape for fixed . The asymptote becomes . A smaller saturates sooner; a larger behaves more like linear frequency across the observed range.
A count needs a denominator
Four occurrences in a 100-token note are denser than four occurrences in a 100,000-token book. Let
- be the indexed length of document ;
- be the corpus average indexed length;
- control length normalization.
Define the length factor
Replace in the saturation denominator with :
The endpoints explain the parameter:
- at , and document length has no effect;
- at , and the count is fully normalized by relative length in this formula;
- when , every gives .
This is an interpolation between two assumptions, not a universal correction. Some long documents cover many topics and need normalization. Others are long because the answer itself is detailed. Tuning changes that judgment.
The “document length” must be measured after the analyzer choices that define the index. If one side counts stopwords and the other does not, the formula's symbols agree while its data does not.
Assemble BM25 from the three decisions
For query and document , a common BM25 form is
Every factor is now inspectable:
- document frequency supplies corpus rarity;
- term frequency supplies within-document evidence;
- sets how quickly repetition saturates;
- relative length and control verbosity normalization;
- the sum combines per-term evidence under the independence approximation.
BM25 score with explicit IDF policy
BM25-SCORE(queryTerms, document, corpus, k1, b, idfPolicy)
Input: analyzed query terms, document statistics, corpus statistics, parameters
Output: additive relevance score and per-term explanation
score ← 0
explanation ← empty sequence
for each distinct term t in queryTerms
n ← documents in corpus containing t
f ← occurrences of t in document
if f = 0
continue
idf ← IDF(idfPolicy, corpus.documentCount, n)
lengthRatio ← document.length / corpus.averageDocumentLength
denominator ← f + k1 × (1 - b + b × lengthRatio)
tfWeight ← (k1 + 1) × f / denominator
contribution ← idf × tfWeight
append (t, n, f, idf, tfWeight, contribution) to explanation
score ← score + contribution
return (score, explanation)The algorithm takes statistic lookups per candidate document when query terms have already been deduplicated and the index supplies , , , and . Candidate generation and postings traversal are separate costs. Its auxiliary working space is without an explanation and when the explanation is retained.
Query term frequency is omitted here deliberately. Some BM25 variants include a second saturation factor for it; many short web queries treat each distinct query term once. Again, “BM25” names a family unless every factor and parameter is pinned.
Work one ranking by hand
Take , use the nonnegative variant, and query apple pie. Suppose:
| Term | Documents containing it |
|---|---|
| apple | 400 |
| pie | 20 |
The pie contribution receives much larger IDF. Compare two documents at and :
| Document | Length | apple count | pie count | Interpretation |
|---|---|---|---|---|
| recipe | 200 | 3 | 4 | short and focused |
| orchard history | 4000 | 80 | 1 | long, many apple mentions |
The history's 80 repetitions do not become 80 times the evidence of one occurrence, and its length raises the saturation denominator. The rare pie match dominates the distinction. This is exactly the behavior raw frequency could not express.
The explanation should expose the actual numbers rather than say “matched better.” A ranking bug becomes diagnosable when a reader can see n, f, relative length, IDF variant, saturation, and final contribution for each term.
Stopwords: cheap evidence is not absent evidence
A stoplist deletes selected tokens during analysis. Low or nonpositive IDF reduces their ranking contribution without deleting them. Those operations are not equivalent.
Consider the query
how was this website built
A stoplist containing how, was, and this leaves only website built. That remainder describes a broad topic. The removed words carried the query's interrogative shape, phrase positions, and potential exact-match evidence even if their standalone ranking weights were small.
Keeping a common term allows:
- exact phrase and proximity checks;
- literal page find;
- quoted-query semantics;
- explanations that preserve what the reader typed;
- later analyzers or tasks to make a different choice.
This does not prove that every deployment should index every token. Storage, privacy, language, and latency can justify exclusions. It proves that deletion is a semantic decision, while IDF is a graded scoring decision. One cannot be described as merely a faster implementation of the other.
The raw signed RSJ weight adds another reason for precision: a ubiquitous term does not automatically receive “almost zero” there; it becomes negative. Systems that want common terms to contribute zero or a small positive amount choose a nonnegative IDF variant or a floor. The policy belongs in the scoring contract.
The false assumption that still helps
The binary independence model assumes query terms are conditionally independent given relevance or nonrelevance. Natural language violates this constantly. new and york are not independent in documents about New York; machine and learning form a concept together.
Why can an approximation built on a false assumption work?
- The score needs a useful ordering, not calibrated posterior probabilities.
- Log-odds rarity captures a strong marginal signal even when dependencies remain.
- Saturation and length normalization repair two major failures of binary term presence for ordinary text.
- Parameters can be evaluated on held-out judgments for the actual task.
- Phrase, field, proximity, and learned features can add evidence the independence model omits.
That is an empirical defense, not a proof of universal superiority. The model earns deployment by beating alternatives on named judgments and latency budgets, not by having a probabilistic ancestry.
In the 1970s, Karen Spärck Jones and Stephen Robertson were trying to turn relevance information and collection statistics into principled term weights. Their 1976 paper derived a family of weights from a general probabilistic retrieval theory and tested them on the small judged collections available at the time. The enduring move was not one frozen formula. It was to ask how a term's distribution differs between relevant and nonrelevant documents, then express that distinction as additive log evidence.
BM25 arrived through later Okapi experiments and model revisions. Robertson and Hugo Zaragoza's 2009 account is unusually candid about that lineage: the probabilistic framework, the eliteness interpretation of within-document frequency, and practical parameterizations accumulated rather than descending from one immaculate derivation. That history is a reason to expose the pieces, not to distrust them.
Engineering reality
For each indexed field and segment, a production scorer must pin:
- the exact analyzer and document-length definition;
- the IDF expression, smoothing, sign or floor policy;
- , , and any query-frequency factor;
- whether document frequency is global, per shard, or approximated;
- how deletions and newly committed documents update , , and average length;
- the numeric type and deterministic tie-break order.
Distributed statistics create a subtle failure. If each shard computes IDF from only its local and , identical documents can receive different scores solely because of placement. Merging shard top-k lists then compares numbers built from different corpora. A coordinator needs common statistics, a correction phase, or an explicitly approximate contract.
Very common terms can also dominate traversal cost even when their score is small. Keeping them semantically does not require decoding their entire postings list for every query. Phrase anchors, shortest-list-first planning, impact ordering, and later upper-bound algorithms can avoid much of that work. Storage policy and query execution are separate levers.
What not to do
| Wrong turn | Failure | Reversal condition |
|---|---|---|
| count every occurrence linearly | verbosity wins without bound | controlled equal-length records where count is the task |
| call every rarity expression “IDF” | sign and rankings change silently | one exact formula is fixed by the artifact |
| delete common words because their rank weight is small | phrase and query shape disappear | a task contract explicitly excludes those semantics |
| treat BM25 as a calibrated relevance probability | assumptions and parameters do not justify calibration | calibration is separately measured and fitted |
| tune and by intuition | knobs become folklore | judged queries and held-out evaluation exist |
| compute unrelated shard statistics | scores are not comparable | merge is explicitly approximate or a common statistic is supplied |
The differential oracle for the arithmetic is a direct mathematical implementation over small exact statistics. Ranking tests should pin both the total order and the per-term decomposition. Property checks should establish that, under nonnegative IDF, contribution is nondecreasing in frequency, bounded by its stated asymptote, and decreases as document length grows when and other values are fixed.
The field changes the meaning of an occurrence
BM25 has treated a document as one bag of analyzed tokens. Real documents have titles, paths, headings, tags, captions, and bodies. One occurrence in a title often carries more editorial authority than one in a footnote. The fields also have different typical lengths.
A tempting extension scores every field with BM25 and adds the already- saturated answers. That gives the same term several “first occurrences,” one per field, and can overreward documents that scatter weak evidence across the schema.
The next chapter derives BM25F's answer: normalize and weight field frequencies, combine them into one pseudo-frequency, and saturate once.
Lessons
- The binary-independence term weight is a log-odds ratio comparing term presence with term absence under relevance and nonrelevance.
- Without relevance judgments, a neutral estimate yields the signed Robertson–Spärck Jones weight .
- Signed RSJ, , nonnegative log-one-plus, and floored variants are different scoring policies.
- Saturation is monotone with a decreasing derivative: repetition helps, but each occurrence contributes less.
- interpolates between no document-length normalization and the formula's full relative-length normalization.
- BM25 combines corpus rarity, within-document frequency, saturation, and length. It is a family until every variant and parameter is fixed.
- Low ranking weight is not token deletion. Stopword removal can destroy phrase, literal, and query-shape evidence.
- Conditional term independence is false for language; BM25 remains an approximation whose value must be established by evaluation.
Practice
- Starting from and , derive as the difference between the log-odds when a term is present and absent.
- Compute signed RSJ and nonnegative log-one-plus IDF for and . Identify every ordering difference.
- Differentiate and prove that it is increasing and concave for .
- Hold term frequency fixed and compare the BM25 term-frequency factor at and for documents half, equal to, and twice the average length.
- Construct a query where deleting stopwords changes an exact phrase answer even though the same stopwords would receive almost no weight under your chosen nonnegative IDF policy.
References
- Stephen E. Robertson and Karen Spärck Jones. “Relevance Weighting of Search Terms.” Journal of the American Society for Information Science 27, no. 3, 1976.
- Stephen Robertson and Hugo Zaragoza. “The Probabilistic Relevance Framework: BM25 and Beyond.” Foundations and Trends in Information Retrieval 3, no. 4, 2009.
- Karen Spärck Jones. “A Statistical Interpretation of Term Specificity and Its Application in Retrieval.” Journal of Documentation 28, no. 1, 1972.