mirror of
https://github.com/TheAlgorithms/Java.git
synced 2025-07-07 01:35:16 +08:00
Add smoothing constant to IDF formula in BM25 to prevent negative scores (#5696)
Co-authored-by: prayas7102 <prayas.prithvirajpratap7@example.com> Co-authored-by: Alex Klymenko <alexanderklmn@gmail.com>
This commit is contained in:
@ -215,6 +215,6 @@ public final class BM25InvertedIndex {
|
||||
*/
|
||||
private double computeIDF(int docFrequency) {
|
||||
// Total number of documents in the index
|
||||
return Math.log((totalDocuments - docFrequency + 0.5) / (docFrequency + 0.5));
|
||||
return Math.log((totalDocuments - docFrequency + 0.5) / (docFrequency + 0.5) + 1);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user