All problems
BM25F Field-Weighted Score
Problem
Return a field-weighted BM25F score. For each field i add weights[i] * idf * (tf_i * (k1 + 1)) / (tf_i + k1 * (1 - b + b * len_i / avg_len_i)).
idf = log(1 + (N - df + 0.5) / (df + 0.5)), and fields with term frequency 0 contribute nothing.
Hint
The idf factor is shared; each field only changes the saturation term and its weight.
Test cases
case 1
in: [[2,0],[50,100],[50,100],[1,0.5],10,100]
expected: 3.233921799539688
case 2
in: [[1,1],[25,50],[50,50],[1,0.3],1,2]
expected: 1.1023276129550097
case 3
in: [[0,0],[50,50],[50,50],[1,1],5,10]
expected: 0
case 4
in: [[2,2],[50,50],[50,50],[0,1],10,100]
expected: 3.233921799539688
Starter codePython
import math
def bm25f_score(term_freqs, field_lens, avg_field_lens, weights, df, n_docs, k1=1.5, b=0.75):
# Your code here
pass4 test cases · run your code against them in the editor