Skip to content
DeepForgeby svx
All problems
HardNLPnlp-404

BM25 Term Score Contribution

Problem

The BM25 contribution of one query term is idf * tf (k1 + 1) / (tf + k1 (1 - b + b * dl / avgdl)).

Given the term frequency, document length, average document length, IDF, k1, and b, return the contribution.

Hint

Length normalization uses the ratio of document length to the average.

Test cases

case 1
in: [3,50,40,2,1.2,0.75]
expected: 2.9830508474576276
case 2
in: [1,100,50,1,1.2,0.75]
expected: 0.7096774193548387
case 3
in: [5,10,10,3,1.5,0.5]
expected: 5.769230769230769
Starter codePython
def bm25_term_score_contribution(tf, doc_length, avgdoc_length, idf, k1, b):
    # Your code here
    pass

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