Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Warn when BM25.average_idf < 0 #2687

Merged
merged 1 commit into from
Dec 2, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions gensim/summarization/bm25.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
"""


import logging
import math
from six import iteritems
from six.moves import range
Expand All @@ -48,6 +49,8 @@
PARAM_B = 0.75
EPSILON = 0.25

logger = logging.getLogger(__name__)


class BM25(object):
"""Implementation of Best Matching 25 ranking function.
Expand Down Expand Up @@ -116,6 +119,13 @@ def _initialize(self, corpus):
negative_idfs.append(word)
self.average_idf = float(idf_sum) / len(self.idf)

if self.average_idf < 0:
piskvorky marked this conversation as resolved.
Show resolved Hide resolved
logger.warning(
'Average inverse document frequency is less than zero. Your corpus of {} documents'
' is either too small or it does not originate from natural text. BM25 may produce'
' unintuitive results.'.format(self.corpus_size)
)

eps = EPSILON * self.average_idf
for word in negative_idfs:
self.idf[word] = eps
Expand Down