Intermediate
Compute a BM25 term score
Write idf(n, df) with BM25's form: ln(1 + (n - df + 0.5) / (df + 0.5)).
Write term_score(tf, length, avg_len, idf_value, k1=1.2, b=0.75): idf_value * tf * (k1 + 1) / (tf + k1 * (1 - b + b * length / avg_len)). A term with tf = 0 scores 0.
What Check tests
- idf of a rare word
- idf stays positive for a word in every passage
- The handbook example: monthly in D8
- A missing term scores 0
- Repetition saturates
- Longer passages score less for the same tf
Stuck? One hint at a time
The solution unlocks after your first Check. Try first: that is where the learning happens.
main.py
Sign in to run your code.
Output
Press Run to see what your program prints.