Study Vault Search notes, aliases and full text
Graph
ConceptDBISAI-written · not yet proofread

BM25

Also Okapi BM25 · Best Match 25

BM25 is the tf.idf-style posting score tf* · log2(N / df) whose modified term frequency tf* = tf · (k + 1) / (k · α + tf), α = 1 − b + b · DL / AVDL, saturates in tf and normalizes by document length.

Know these firstTF-IDFTerm Frequency

Formula#

The idf factor log⁡2(N/dfw)\log_2(N/\mathrm{df}_w) is the same as in tf.idf; only tf\mathrm{tf} is replaced by tf∗\mathrm{tf}^*. Rewriting shows that α\alpha acts as a normalization of tf\mathrm{tf}:

tf∗=tf⋅(k+1)k⋅α+tf=tfα⋅k+1k+tf/α.\mathrm{tf}^* = \frac{\mathrm{tf} \cdot (k+1)}{k \cdot \alpha + \mathrm{tf}} = \frac{\mathrm{tf}}{\alpha} \cdot \frac{k+1}{k + \mathrm{tf}/\alpha}.

Parameters:

  • bb controls the length normalization: b=0b = 0 gives α=1\alpha = 1 (none), b=1b = 1 gives α=DL/AVDL\alpha = \mathrm{DL}/\mathrm{AVDL} (full, “too extreme”); bb interpolates between the two.
  • kk controls the saturation: tf∗→k+1\mathrm{tf}^* \to k + 1 as tf→∞\mathrm{tf} \to \infty.
  • Standard setting: k=1.75k = 1.75, b=0.75b = 0.75.

Special cases (lecture):

  • k=0k = 0: tf∗=1\mathrm{tf}^* = 1 for every tf>0\mathrm{tf} > 0 (binary: presence only), so the score is the idf.
  • k→∞k \to \infty, b=0b = 0: α=1\alpha = 1 and tf∗→tf\mathrm{tf}^* \to \mathrm{tf}, i.e. plain tf.idf. (For general bb, tf∗→tf/α\mathrm{tf}^* \to \mathrm{tf}/\alpha, a length-normalized tf.)

Properties#

Plausibility argument for tf∗\mathrm{tf}^* (DBIS_VL02 > Plausibility argument): the “simplest” function with

  • tf∗=0  ⟺  tf=0\mathrm{tf}^* = 0 \iff \mathrm{tf} = 0,
  • tf∗\mathrm{tf}^* increasing in tf\mathrm{tf} (strictly for k>0k > 0),
  • tf∗→\mathrm{tf}^* \to a fixed limit (k+1k + 1) as tf→∞\mathrm{tf} \to \infty (fixes the linearity problem of tf.idf),

for any α>0\alpha > 0; choosing α\alpha from DL/AVDL\mathrm{DL}/\mathrm{AVDL} fixes the length problem.

Propertytf.idfBM25
tf factortf\mathrm{tf}, unbounded and lineartf∗≤k+1\mathrm{tf}^* \le k + 1, saturating
Length normalizationnonevia α\alpha (strength bb)
idf factorlog⁡2(N/df)\log_2(N/\mathrm{df})same
Usesimple baselinestandard, outperformed other formulas on benchmarks for many years

Implementation (DBIS_VL02 > Implementation advice): build the inverted lists with tf scores, compute DL\mathrm{DL} per document and AVDL\mathrm{AVDL} in the same pass, then make a second pass over the lists and replace each tf by tf∗⋅log⁡2(N/df)\mathrm{tf}^* \cdot \log_2(N/\mathrm{df}), where df\mathrm{df} is the length of the list.

Vector space view: with BM25 scores as entries of the term-document matrix AA, the dot product qTAq^T A gives exactly the same ranking as the inverted-index ranking (DBIS_VL11 > Variant 1: dot product with BM25 scores); BM25 already accounts for document length, which the plain dot product with tf would not.

Example#

Sources#

Search

Type In
↑ ↓ move ↵ open ⇥ next section Ctrl↵ results page Prefix # to search text only