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

Refactor BM25 #2275

Merged
merged 6 commits into from
Jan 9, 2019
Merged

Refactor BM25 #2275

merged 6 commits into from
Jan 9, 2019

Conversation

horpto
Copy link
Contributor

@horpto horpto commented Nov 22, 2018

  • remove unnecessary attributes
  • move calculation of average_idf in _initialize
  • more readable names

idf_sum += idf
if idf < 0:
negative_idfs.append(word)
self.average_idf = idf_sum / len(self.idf)
Copy link
Owner

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
Copy link
Owner

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.

Copy link
Contributor Author

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
@menshikh-iv menshikh-iv changed the title Refactor BM25 Refactor BM25 Jan 9, 2019
@menshikh-iv menshikh-iv merged commit 9b28532 into piskvorky:develop Jan 9, 2019
@horpto horpto deleted the refactor-bm25 branch January 19, 2019 12:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants