Query-Likelihood Language Models and Smoothing
Ranking by the probability a document's language model generates the query — and why smoothing is not optional but the whole game
The vector space model asked a geometric question — how close is the document’s term-weight vector to the query’s? — and BM25 asked a probabilistic one — how likely is the document to be relevant? Query likelihood asks a third, generative question, and it turns out to be the most direct of the three. Imagine the author of each document equipped with a private, biased die over the vocabulary — their language model — that they roll to produce text. Hand each author the query and ask: how probable is it that your die would have produced these exact words? Rank the documents by that probability and you have a retrieval model that never mentions relevance at all, yet competes with BM25 on every standard benchmark.
The appeal is that the model is almost entirely forced. Once we commit to “rank by the probability the document generates the query,” the only freedom left is how we estimate each document’s die from the handful of words the document actually contains — and that single estimation choice, smoothing, is where all the action is. Get it wrong in the most natural way and the model assigns probability zero to most of the collection.
- 1.10-K · net interest margin sensitivity-10.93
- 2.10-K · foreign-exchange risk-10.95
- 3.10-K · boilerplate legal-10.96
- 4.News · Fed rate decision-10.97
- 5.Earnings call · brief update-10.98
- 6.Earnings call · long Q&A (padded)-11.19
The maximum-likelihood estimate tf/|d| already divides by length, so the padded transcript never hijacks the top — query likelihood’s only real problem is the zero, which smoothing removes.
Make the failure concrete with the same finance corpus the vector space model and BM25 score. The query is interest rate exposure. A one-line 10-K disclosure — “net interest margin is sensitive to interest rate moves and our rate exposure is disclosed” — contains all three query words. So does a ninety-minute earnings-call transcript padded with hundreds of words of operational filler. But a foreign-exchange filing that talks only about currency rate movements and exposure to translation never says interest — and under the naive model its probability of generating the query is exactly zero, its log-score , and it is unrankable. On this six-document corpus, three of the six documents are killed this way. Smoothing is what brings them back, and the laboratory above lets you watch each smoothing scheme rescue them and reshuffle the ranking as you turn its single knob.
What we cover
- The query-likelihood model: documents as multinomial language models.
- The zero-frequency catastrophe and why the maximum-likelihood estimate is unusable.
- Two smoothings: Jelinek–Mercer interpolation and Dirichlet smoothing.
- Dirichlet smoothing is a Bayesian posterior mean (Theorem 1).
- The KL-divergence view: query likelihood as cross-entropy (Theorem 2).
- The dual role of smoothing: an IDF-like effect that emerges, not imposed (Theorem 3).
- Length adaptivity, the contrast with the length hijack, and a finance case study.
The query-likelihood model
We model each document as a probability distribution over the vocabulary — a multinomial unigram language model, “unigram” because it treats word order as irrelevant and scores each query term independently. Ranking is by the probability that , sampled times, produces the query.
Definition 1 (Query-likelihood retrieval).
Let be the number of times term occurs in the query . Under the multinomial unigram model, the probability that document ‘s language model generates the query is
and because ranking is invariant under the logarithm, we rank documents by
The whole model now reduces to a single question: what is ? The most natural answer is the maximum-likelihood estimate — the relative frequency of the term in the document:
where is the term’s count in and the document’s length in tokens. This estimate is the maximum-likelihood estimator of a multinomial, and it already does something the raw tf-idf dot product never did: it divides by document length. A term that appears twice in a fifteen-word filing has probability ; the same term appearing three times in a 249-word padded transcript has probability . Length normalization is not bolted on afterward — it is built into the probability itself.
The zero-frequency catastrophe
The maximum-likelihood estimate has a fatal flaw, and it is not subtle. If a single query term never appears in a document, , so , and the product in Definition 1 collapses to zero — . One missing word annihilates the entire score, no matter how perfectly the document matches the rest of the query.
Proposition 1 (The zero-frequency catastrophe).
Under the maximum-likelihood document model, whenever omits any query term. The model can only rank documents that contain every query term; all others are tied at .
This is not a corner case to be patched — for any query of more than one or two words it is the common case. On the worked corpus, the query interest rate exposure leaves only three of six documents with finite scores; the foreign-exchange filing (no interest), the macro news item (no exposure), and the short transcript (no exposure) are all sent to , even though two of them are plainly about the topic. A model that cannot rank documents missing one query word out of three is not a retrieval model at all.
The diagnosis is the same one statistics makes of any unregularized maximum-likelihood estimate over sparse counts: zero observed occurrences is not the same as zero probability. A fifteen-word filing that happens not to use the word “translation” has not declared translation impossible; it has simply given us too small a sample to estimate its rate. The cure is to pull each estimate away from the raw counts toward a sensible default — the collection model
the relative frequency of term across the entire corpus ( its total count, the total number of tokens). The collection model is never zero for a term anyone ever queries, and mixing a little of it into every document model is exactly smoothing.
Two smoothings
There are two canonical ways to mix the document model with the collection model, and they differ in one decision: should the amount of smoothing be the same for every document, or should it adapt to document length?
Definition 2 (Jelinek–Mercer and Dirichlet smoothing).
Jelinek–Mercer smoothing is a fixed linear interpolation with a single mixing weight :
Dirichlet smoothing adds pseudo-counts distributed according to the collection model, with :
Both produce genuine probability distributions — every term gets nonzero probability, and the weights over the vocabulary sum to one (the companion harness verifies this for a range of and ). The difference is structural. Jelinek–Mercer trusts the document and the collection in a fixed ratio regardless of how much evidence the document offers. Dirichlet smoothing instead rewrites itself as
a Jelinek–Mercer interpolation whose effective mixing weight shrinks as the document grows. A long document is trusted more (it has supplied more evidence); a short one is smoothed harder toward the collection. We will see in Section 6 that this length-dependence is exactly a length-normalization term, the probabilistic cousin of BM25’s .
Dirichlet smoothing is a Bayesian posterior mean
The two pseudo-counts in Dirichlet smoothing are not an arbitrary patch. They are precisely what Bayesian estimation of a multinomial prescribes.
Theorem 1 (Dirichlet smoothing as posterior mean).
Treat the document model as an unknown multinomial parameter and place on it a conjugate Dirichlet prior with concentration parameters . After observing the document’s term counts , the posterior is , and its mean is exactly the Dirichlet-smoothed estimate
Proof.
The Dirichlet distribution is the conjugate prior for the multinomial: a prior multiplied by a multinomial likelihood with counts yields a posterior, because both contribute the same functional form and the exponents simply add. The mean of a distribution is . Substituting gives the posterior mean above.
The denominator simplifies cleanly. The prior pseudo-counts sum to
because the collection model is a probability distribution, and the observed counts sum to the document length, . Hence , and the posterior mean is as claimed.
∎So is not a tuning knob bolted onto a heuristic — it is the strength of the prior, measured in pseudo-tokens. Setting asserts that, before reading a word of the document, our belief about its language model is worth two thousand tokens drawn from the collection. A short filing of fifteen real tokens is then dominated by its prior; a long transcript of several hundred is dominated by its own evidence. The companion harness confirms the identity to machine precision across and every document — the smoothing formula and the posterior mean are the same object.
The KL-divergence view
Query likelihood looks like it ranks by a generation probability, but there is a more revealing way to read the same number: as a measure of how far the document’s language model sits from the query’s.
Theorem 2 (Query likelihood is negative cross-entropy).
Let be the empirical query model — the query’s own relative term frequencies. Ranking documents by the query likelihood is rank-equivalent to ranking by the negative KL divergence from the query model to the document model:
where is the (smoothed) document model and is the Shannon entropy of the query model.
Proof.
Expand the KL divergence and split the logarithm:
Negate both sides:
The cross-entropy sum is the query likelihood up to a scalar: since and ,
Substituting gives the stated identity. For a fixed query, is the same for every document and is a positive constant, so ordering documents by is identical to ordering them by .
∎The Shannon entropy term is the price of admission that cancels: it depends only on the query, so it shifts every document’s score by the same amount and never changes the ranking. What remains, , is the negative cross-entropy of the document model relative to the query model — retrieval as finding the document whose language model is least surprised by the query. The harness checks this equivalence not only on the worked corpus but on two hundred random strict instances, where ties cannot mask a disagreement.
This reframing is the single most useful idea in the topic, because it generalizes. Nothing in the proof required to be the raw query frequencies; any distribution over terms will do. Replace the thin empirical query model with a richer relevance model estimated from documents we believe to be relevant, and the same cross-entropy ranking becomes pseudo-relevance feedback — the Rocchio and RM3 methods build directly on this view.
The dual role of smoothing
We argued that smoothing is forced by the zero-frequency catastrophe. But Zhai and Lafferty observed that it does a second job at the same time: it supplies the IDF-like weighting that the raw query-likelihood score otherwise lacks.
Theorem 3 (Smoothing's IDF-like effect (Zhai–Lafferty)).
The Jelinek–Mercer log score decomposes into a document-dependent matched-term sum plus a constant that is the same for every document:
Inside the matched-term sum, the per-term weight is strictly decreasing in the collection probability : a query term that is rare in the collection contributes more than a common one. This is an inverse-collection-frequency effect, the language-model analogue of IDF.
Proof.
For a matched term (), factor the smoothed probability:
Taking logs, . For an unmatched term, , so its log is just — the same trailing constant with no matched-term contribution. Summing over all query terms collects the pieces over matched terms only, while the pieces accumulate over all query terms into , which depends on the query and collection but not on the document.
For the monotonicity, fix a matched frequency so is held constant and view the weight as a function of : with . Then , so the weight strictly decreases as the collection probability rises.
∎Two consequences are worth drawing out. First, only the matched-term sum varies across documents, so it alone determines the ranking — the harness confirms it reproduces the full query-likelihood order exactly. Second, the IDF-like weight here is emergent, not designed: nobody inserted an inverse-document-frequency factor, yet rare query terms automatically dominate because the collection probability sits in the denominator. This is the honest version of a claim often made loosely — query-likelihood models “contain IDF.” They contain an inverse-collection-frequency effect that behaves like IDF, and it falls out of smoothing rather than being a separate ingredient.
Length adaptivity and the length hijack
Section 3 noted that Dirichlet smoothing’s effective mixing weight shrinks with length. That same factor is, read another way, a length-normalization penalty.
Proposition 2 (Dirichlet length normalization).
The Dirichlet-smoothed log score carries an explicit length penalty. Collecting the document-length dependence, the score includes the additive term , which is strictly decreasing in : longer documents are penalized more. Equivalently, the effective smoothing weight is strictly decreasing in , so short documents are smoothed harder toward the collection.
The function is manifestly decreasing in for , and the harness verifies both the monotonicity and that the longest document on the corpus receives the most negative length penalty. This is the probabilistic counterpart of BM25’s parameter: where BM25 stretches its saturation point in proportion to length, Dirichlet smoothing discounts long documents through the prior’s diminishing relative weight. Jelinek–Mercer, with its fixed , has no such term — which is precisely why Dirichlet smoothing is the better default for the short, keyword-style queries that dominate retrieval.
The headline payoff is the contrast with the vector space model. On that page, the same corpus and the same query exposed the length-hijack flip: the raw tf-idf dot product ranked the padded transcript first, purely because length let it accumulate term occurrences, and only cosine normalization rescued the concise filing. Query likelihood never has that problem to begin with. Because divides by length, the padded transcript’s query-term probabilities are tiny ( rather than the filing’s ), and the concise on-point filing ranks first under the bare maximum-likelihood estimate, under Jelinek–Mercer, and under Dirichlet smoothing alike. The model that solves the zero-frequency problem solves the length problem for free.
Finance case study
Query likelihood and BM25 are close cousins on the same corpus, and the production system runs both rather than choosing because they fail differently. BM25’s saturating term-frequency transform is more forgiving of a query term repeated many times in a genuinely on-topic document; query likelihood’s collection-model smoothing gives a cleaner, parameter-light handle on the wildly varying lengths of transcripts. Where they agree, the fusion is confident; where they disagree, the disagreement is itself signal that downstream reranking can exploit.
Honest caveats
Implementation
The companion notebook builds the multinomial language models from scratch over the shared finance corpus ( documents, collection tokens) and turns every claim above into an assertion. It confirms the zero-frequency catastrophe — the maximum-likelihood model leaves exactly three of six documents finite and smoothing rescues all six — then verifies the Dirichlet posterior-mean identity to machine precision, the KL rank-equivalence on the worked example plus two hundred random strict instances, the Zhai–Lafferty decomposition and its inverse-collection-frequency monotonicity, and the Dirichlet length penalty.
The printed rankings make the story legible. For interest rate exposure, the unsmoothed model scores the on-point filing at and the padded transcript at (with the three term-missing documents at ); Jelinek–Mercer at scores the on-point filing first at , ahead of the boilerplate filing at and the rescued foreign-exchange filing at ; Dirichlet at keeps the on-point filing first at , now in a tight pack with the foreign-exchange and boilerplate filings at and , the heavy prior having compressed the scores toward the collection. The collection probabilities the interactive laboratory mirrors — , , — are printed by the harness so the page, the notebook, and the viz read one set of numbers.
Connections
- query likelihood replaces the geometric similarity of the vector space model with a generative probability; the MLE P(t|d) = tf/|d| is the length-normalized term weight the raw tf-idf dot product lacks vector-space-model-tfidf
- the two dominant probabilistic retrieval models — BM25 ranks by probability of relevance (the BIM), query likelihood ranks by probability of generating the query; they are unified through the KL-divergence / risk-minimization view bm25-binary-independence-model
- query likelihood is a generative instance of the PRP under a risk-minimization framing: ranking by P(q | document model) is the decision rule that minimizes Bayes risk under a specific loss probability-ranking-principle
- the KL-divergence view generalizes directly to relevance models: RM3 replaces the empirical query model θ_q with a feedback-estimated relevance model, re-scored by the same cross-entropy pseudo-relevance-feedback
References & Further Reading
- paper A Language Modeling Approach to Information Retrieval — Ponte & Croft (1998) The original query-likelihood model for IR
- paper A Study of Smoothing Methods for Language Models Applied to Ad Hoc Information Retrieval — Zhai & Lafferty (2004) The definitive study of Jelinek-Mercer and Dirichlet smoothing and the dual role of smoothing
- paper Document Language Models, Query Models, and Risk Minimization for Information Retrieval — Lafferty & Zhai (2001) The KL-divergence / risk-minimization framework that unifies query likelihood and relevance models
- book Introduction to Information Retrieval — Manning, Raghavan & Schütze (2008) Chapter 12: language models for information retrieval
- documentation Pyserini: reproducible IR with Lucene query-likelihood (QL/QLD) Reference Dirichlet-smoothed query-likelihood retrieval