Skip to content
DeepForgeby svx
All problems
HardNLPnlp-413

BM25 Multi Term Score

Problem

The full BM25 score sums over query terms: idf(t) * tf(t) (k1 + 1) / (tf(t) + k1 (1 - b + b dl / avgdl)), with idf(t) = ln(1 + (N - df(t) + 0.5) / (df(t) + 0.5)).

Given the query term frequencies, the document frequencies, N, the document length, the average length, k1, and b, return the score.

Hint

Compute each term contribution with its own IDF and sum.

Test cases

case 1
in: [[2,1],[10,20],100,50,40,1.2,0.75]
expected: 4.354903273150793
case 2
in: [[1],[5],10,100,100,1.5,0.5]
expected: 0.6931471805599453
case 3
in: [[3,3],[2,2],50,30,60,1,0.25]
expected: 9.338430660697304
Starter codePython
def bm25_multi_term_score(query_tfs, document_frequencies, n_docs, doc_length, avgdoc_length, k1, b):
    # Your code here
    pass

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