Classical NLPNLP 05
BM25
BM25 is the default ranking in Lucene, Elasticsearch, Solr and most open-source search tools, and it is TF-IDF with two changes. First, repetition has diminishing returns: the tenth mention of a word adds far less than the first (set by k1). Second, it corrects for document length by an adjustable amount, because long documents match words just by being long (set by b). The TF-IDF used here already divides by document length, which discounts long documents in full, much as BM25 does with b = 1. So in this side-by-side comparison the main differences are BM25’s diminishing returns and its slightly different idf; lower b to see length matter less. Search the abstracts below and compare the two rankings side by side. The abstracts are fictional.
Settings
0 = only whether a word appears matters; higher = repeats keep counting for longer.
0 = ignore document length; 1 = fully discount long documents, as the TF-IDF here does.
How repetition is counted
BM25 ▲▼ = change from TF-IDF rank
TF-IDF
Click a document to see its text and how each query word contributed; it opens in both columns. TF-IDF uses the same formula as the TF-IDF panel. BM25 uses the idf variant from the Lucene search library, ln(1 + (N − n + 0.5) / (n + 0.5)), which unlike the original formula never goes negative for very common words.
documents (click to view or edit, one per line)
Background
BM25 (“Best Matching 25”) was developed by Stephen Robertson, Karen Spärck Jones and colleagues for the Okapi search system, and presented in its now-standard form at the TREC-3 evaluation in 1994. It follows from a probabilistic model of relevance, and remains the default ranking in the Lucene search library (and Elasticsearch, which is built on it) as well as a standard baseline in retrieval research.
The formula
For each query word: idf × f·(k1 + 1) / (f + k1·(1 − b + b·|d| / avgdl)), summed over the query, where f is how often the word occurs in the document, |d| is the document’s length and avgdl the average length. Typical settings are k1 between 1.2 and 2 and b = 0.75.
References
- Robertson, S. E., Walker, S., Jones, S., Hancock-Beaulieu, M. M., & Gatford, M. (1995). Okapi at TREC-3. In Overview of the Third Text REtrieval Conference (TREC-3) (pp. 109–126). NIST. (S. Jones here is Susan Jones, not Karen Spärck Jones.)
- Robertson, S., & Zaragoza, H. (2009). The probabilistic relevance framework: BM25 and beyond. Foundations and Trends in Information Retrieval, 3(4), 333–389. doi.org/10.1561/1500000019
- Apache Lucene. BM25Similarity, source code (documents the idf variant used here). github.com/apache/lucene