Okapi BM25

In information retrieval, Okapi BM25 (BM stands for Best Matching) is a ranking function used by search engines to rank matching documents according to their relevance to a given search query. It is based on the probabilistic retrieval framework developed in the 1970s and 1980s by Stephen E. Robertson, Karen Spärck Jones, and others.

The name of the actual ranking function is BM25. To set the right context, however, it is usually referred to as "Okapi BM25", since the Okapi information retrieval system, implemented at London's City University in the 1980s and 1990s, was the first system to implement this function.

BM25 and its newer variants, e.g. BM25F (a version of BM25 that can take document structure and anchor text into account), represent state-of-the-art TF-IDF-like retrieval functions used in document retrieval.[citation needed]

The ranking function

BM25 is a bag-of-words retrieval function that ranks a set of documents based on the query terms appearing in each document, regardless of the inter-relationship between the query terms within a document (e.g., their relative proximity). It is not a single function, but actually a whole family of scoring functions, with slightly different components and parameters. One of the most prominent instantiations of the function is as follows.

Given a query Q, containing keywords ${\displaystyle q_{1},...,q_{n}}$, the BM25 score of a document D is:

${\displaystyle {\text{score}}(D,Q)=\sum _{i=1}^{n}{\text{IDF}}(q_{i})\cdot {\frac {f(q_{i},D)\cdot (k_{1}+1)}{f(q_{i},D)+k_{1}\cdot \left(1-b+b\cdot {\frac {|D|}{\text{avgdl}}}\right)}},}$

where ${\displaystyle f(q_{i},D)}$ is ${\displaystyle q_{i}}$'s term frequency in the document D, ${\displaystyle |D|}$ is the length of the document D in words, and avgdl is the average document length in the text collection from which documents are drawn. ${\displaystyle k_{1}}$ and b are free parameters, usually chosen, in absence of an advanced optimization, as ${\displaystyle k_{1}\in [1.2,2.0]}$ and ${\displaystyle b=0.75}$.[1] ${\displaystyle {\text{IDF}}(q_{i})}$ is the IDF (inverse document frequency) weight of the query term ${\displaystyle q_{i}}$. It is usually computed as:

${\displaystyle {\text{IDF}}(q_{i})=\log {\frac {N-n(q_{i})+0.5}{n(q_{i})+0.5}},}$

where N is the total number of documents in the collection, and ${\displaystyle n(q_{i})}$ is the number of documents containing ${\displaystyle q_{i}}$.

There are several interpretations for IDF and slight variations on its formula. In the original BM25 derivation, the IDF component is derived from the Binary Independence Model.

Please note that the above formula for IDF shows potentially major drawbacks when using it for terms appearing in more than half of the corpus documents. These terms' IDF is negative, so for any two almost-identical documents, one which contains the term and one which does not contain it, the latter will possibly get a larger score. This means that terms appearing in more than half of the corpus will provide negative contributions to the final document score. This is often an undesirable behavior, so many real-world applications would deal with this IDF formula in a different way:

• Each summand can be given a floor of 0, to trim out common terms;
• The IDF function can be given a floor of a constant ${\displaystyle \epsilon }$, to avoid common terms being ignored at all;
• The IDF function can be replaced with a similarly shaped one which is non-negative, or strictly positive to avoid terms being ignored at all.

IDF information theoretic interpretation

Here is an interpretation from information theory. Suppose a query term ${\displaystyle q}$ appears in ${\displaystyle n(q)}$ documents. Then a randomly picked document ${\displaystyle D}$ will contain the term with probability ${\displaystyle {\frac {n(q)}{N}}}$ (where ${\displaystyle N}$ is again the cardinality of the set of documents in the collection). Therefore, the information content of the message "${\displaystyle D}$ contains ${\displaystyle q}$" is:

${\displaystyle -\log {\frac {n(q)}{N}}=\log {\frac {N}{n(q)}}.}$

Now suppose we have two query terms ${\displaystyle q_{1}}$ and ${\displaystyle q_{2}}$. If the two terms occur in documents entirely independently of each other, then the probability of seeing both ${\displaystyle q_{1}}$ and ${\displaystyle q_{2}}$ in a randomly picked document ${\displaystyle D}$ is:

${\displaystyle {\frac {n(q_{1})}{N}}\cdot {\frac {n(q_{2})}{N}},}$

and the information content of such an event is:

${\displaystyle \sum _{i=1}^{2}\log {\frac {N}{n(q_{i})}}.}$

With a small variation, this is exactly what is expressed by the IDF component of BM25.

Modifications

• At the extreme values of the coefficient b BM25 turns into ranking functions known as BM11 (for ${\displaystyle b=1}$) and BM15 (for ${\displaystyle b=0}$).[2]
• BM25F[3][4] is a modification of BM25 in which the document is considered to be composed from several fields (such as headlines, main text, anchor text) with possibly different degrees of importance, term relevance saturation and length normalization.
• BM25+[5] is an extension of BM25. BM25+ was developed to address one deficiency of the standard BM25 in which the component of term frequency normalization by document length is not properly lower-bounded; as a result of this deficiency, long documents which do match the query term can often be scored unfairly by BM25 as having a similar relevancy to shorter documents that do not contain the query term at all. The scoring formula of BM25+ only has one additional free parameter ${\displaystyle \delta }$ (a default value is 1.0 in absence of a training data) as compared with BM25:
${\displaystyle {\text{score}}(D,Q)=\sum _{i=1}^{n}{\text{IDF}}(q_{i})\cdot \left[{\frac {f(q_{i},D)\cdot (k_{1}+1)}{f(q_{i},D)+k_{1}\cdot \left(1-b+b\cdot {\frac {|D|}{\text{avgdl}}}\right)}}+\delta \right]}$

References

1. ^ Christopher D. Manning, Prabhakar Raghavan, Hinrich Schütze. An Introduction to Information Retrieval, Cambridge University Press, 2009, p. 233.
2. ^ http://xapian.org/docs/bm25.html
3. ^ Hugo Zaragoza, Nick Craswell, Michael Taylor, Suchi Saria, and Stephen Robertson. Microsoft Cambridge at TREC-13: Web and HARD tracks. In Proceedings of TREC-2004.
4. ^ Stephen Robertson & Hugo Zaragoza (2009). "The Probabilistic Relevance Framework: BM25 and Beyond". 3 (4). Found. Trends Inf. Retr.: 333–389. doi:10.1561/1500000019.
5. ^ Yuanhua Lv and ChengXiang Zhai. Lower-bounding term frequency normalization. In Proceedings of CIKM'2011, pages 7-16.