-
-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Refactor BM25
#2275
Refactor BM25
#2275
Conversation
horpto
commented
Nov 22, 2018
- remove unnecessary attributes
- move calculation of average_idf in _initialize
- more readable names
gensim/summarization/bm25.py
Outdated
idf_sum += idf | ||
if idf < 0: | ||
negative_idfs.append(word) | ||
self.average_idf = idf_sum / len(self.idf) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use float (or explicitly cast to float). Both to avoid potential Python errors in integer vs float division, as well as to make the intent clear to readers of the code.
nd[word] += 1 | ||
|
||
# collect idf sum to calculate an average idf for epsilon value | ||
idf_sum = 0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Safer to use float (or explicitly cast to float below).
Both to avoid potential Python errors in integer vs float division in future refactorings, as well as (mainly) to make the intent clear to readers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh, yes. you're right. Damn python2.
- remove unnecessary attributes - move calculation of average_idf in _initialize - more readable names
d2f2311
to
a1875c8
Compare