All problems
BM25 IDF Computation
Problem
Return the BM25 probabilistic inverse document frequency log(1 + (n_docs - df + 0.5) / (df + 0.5)).
Return 0.0 when n_docs is not positive or df is negative or greater than n_docs.
Hint
This idf is always positive, unlike the classic log(n_docs / df).
Test cases
case 1
in: [10,100]
expected: 2.2637452596777816
case 2
in: [1,1]
expected: 0.28768207245178085
case 3
in: [0,10]
expected: 3.091042453358316
case 4
in: [5,5]
expected: 0.0870113769896297
case 5
in: [11,10]
expected: 0
Starter codePython
import math
def bm25_idf(df, n_docs):
# Your code here
pass5 test cases · run your code against them in the editor