Lecture 19 · Animations
Information retrieval: the lexical foundation
Two pieces of today, run in front of you: BM25, with its two parameters on sliders; and the ranking metrics, recomputed term by term as you change which results are relevant. Press Step to advance one unit and read what happened; press Play to let it run.
All data on this page is synthetic: the ten one-line “abstracts” and the term counts are made up, not taken from SciFact. Reset always gives back the same picture. Logarithms are natural logarithms, except $\log_2$ in the discount of DCG.
1BM25 and its two parameters
The query insulin resistance in obesity against ten made-up documents A–J, described by their length and their counts of the query terms. Bottom: each document's BM25 score, split into its four terms' contributions and sorted — move $k_1$ and $b$ and watch the order change. Top left: one term's contribution against its count; top right, against the document's length. Each step pastes one more insulin into document D, as a spammer would.
for $N$ documents of which $n_t$ contain $t$, and avgdl the mean document length. For $k_1 > 0$ the denominator is larger than $\text{tf}$, so each term's contribution is below $\mathrm{idf}(t)(k_1+1)$, whatever $\text{tf}$: the saturation. At $k_1 = 0$ the fraction is $1$ for any $\text{tf} > 0$, so the score is $\sum$ idf over the query terms the document contains.
- in occurs in all ten documents and its idf is 0.047: its segment of every bar is a sliver. No stop-word list was needed.
- Each step adds a copy of insulin to D. The first copies raise its score most; later ones add almost nothing, and the insulin part never crosses the dashed bound $\mathrm{idf}(k_1+1)$.
- Document B is long (620 tokens) and has the most occurrences of everything: it leads at $b = 0.4$ and loses its lead as $b$ grows.
- Set $b = 0$: B leads by more. Set $b = 1$: B drops to third, behind the short documents A and C.
- Set $k_1 = 0$: A, B and C tie exactly, because each contains all four terms once or more and counts no longer matter.
- Press Play with $k_1 = 0.9$: after 40 copies D is still below C, which mentions each term once. Then set $k_1 = 5$, close to raw counting: D jumps above C.
2Evaluating a ranking, term by term
Ten ranked results; click one to change its relevance. It starts as the lecture's worked example — relevant documents at ranks 1, 2 and 8. Under each rank, every term each metric adds up: the precision at each hit for AP, and the gain and discount for DCG, with the ideal ordering beneath. Each step makes one swap towards the ideal ordering, moving a more relevant result one place up.
With $R$ the set of relevant documents (those in the list, plus any the system never retrieved):
$$\text{P}@k = \frac{|R \cap \text{top-}k|}{k},\quad \text{R}@k = \frac{|R \cap \text{top-}k|}{|R|},$$ $$\text{RR} = \frac{1}{\text{rank of the first relevant}},$$ $$\text{AP} = \frac{1}{|R|}\sum_{i\,:\,d_i \in R}\text{P}@i,$$ $$\text{DCG}@k = \sum_{i=1}^{k}\frac{g_i}{\log_2(i+1)},$$ $$\text{NDCG}@k = \frac{\text{DCG}@k}{\text{IDCG}@k}.$$IDCG@$k$ is the DCG@$k$ of the ideal ordering: every relevant document, most relevant first. The gain is $g_i = \text{rel}_i$ (linear) or $2^{\text{rel}_i} - 1$; for binary relevance both give 0 or 1. RR is 0 if nothing relevant is retrieved. A relevant document never retrieved counts as grade 1.
- At the start the side panel reads the lecture's numbers: AP 0.7917, DCG@10 1.9464, IDCG@10 2.1309, NDCG@10 0.9134 — while R@10 and RR both say 1.
- Stepping moves the rank-8 document up. AP and NDCG rise with every swap; R@10 and RR do not move at all: they cannot read that part of the order.
- AP divides by $|R|$, not by the number of hits: add a relevant document the system never retrieved, and AP falls although the list is unchanged.
- Leave one relevant document and move it: ranks 1, 2, 5, 10 give RR 1, 0.5, 0.2, 0.1 and NDCG@10 1, 0.6309, 0.3869, 0.2891, while R@10 stays 1.
- Set relevant, not retrieved to 1: R@10 drops to 0.75 and AP to 0.5938.
- Switch to graded relevance and give ranks 1, 2, 3 the grades 1, 1, 3 and rank 8 the grade 0 (clicks cycle 0 → 1 → 2 → 3 → 0). With linear gain the two fair documents contribute 1.63 to DCG and the excellent one 1.5; with $2^{\text{rel}} - 1$ the excellent one contributes 3.5.