BM25 Ranking
Implement calculate_bm25_scores(corpus, query, k1=1.5, b=0.75). corpus is a list of tokenised documents (lists of strings) and query is a list of query tokens. Return a NumPy array with one BM25 score per document, in corpus order, rounded to 3 decimals.
With N documents, ∣d∣ the length of document d, avgdl the mean document length, f(t,d) the count of term t in d and nt the number of documents containing t:
score(d)=∑t∈queryln(nt+1N+1)⋅f(t,d)+k1(1−b+bavgdl∣d∣)f(t,d)(k1+1)
- The sum runs over the query tokens as given (one term per occurrence); a term absent from a document adds 0 for that document.
- Use the natural logarithm and the IDF variant exactly as written, so a term present in every document has IDF 0.
- Raise
ValueError if corpus or query is empty.