Skip to content
DeepForgeby svx
All problems
MediumNLPnlp-403

BM25 IDF from Document Frequency

Problem

The BM25 IDF is ln(1 + (N - df + 0.5) / (df + 0.5)).

Given the number of documents and the document frequency, return the IDF.

Hint

The inner 1 + keeps the weight nonnegative.

Test cases

case 1
in: [100,10]
expected: 2.2637452596777816
case 2
in: [10,5]
expected: 0.6931471805599453
case 3
in: [1000,1]
expected: 6.503289671207057
Starter codePython
def bm25_idf_from_document_frequency(n_docs, df):
    # Your code here
    pass

3 test cases · run your code against them in the editor