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

Fix min_count handling in phrases detection using npmi #2072

Merged
merged 6 commits into from
Jul 31, 2018
Merged
Changes from 2 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
15 changes: 10 additions & 5 deletions gensim/models/phrases.py
Original file line number Diff line number Diff line change
Expand Up @@ -661,7 +661,7 @@ def npmi_scorer(worda_count, wordb_count, bigram_count, len_vocab, min_count, co
len_vocab : int
NOT USED.
min_count: int
NOT USED.
Take into account only bigrams with count above this value.
corpus_word_count : int
Number of words in corpus.

Expand All @@ -671,10 +671,15 @@ def npmi_scorer(worda_count, wordb_count, bigram_count, len_vocab, min_count, co
where :math:`prob(word) = \\frac{word\_count}{corpus\_word\_count}`

"""
pa = worda_count / corpus_word_count
pb = wordb_count / corpus_word_count
pab = bigram_count / corpus_word_count
return log(pab / (pa * pb)) / -log(pab)
if bigram_count > min_count:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sharp inequality goes against the established pattern in the other classes in this module, and in word2vec etc. Should be >= IMO.

pa = worda_count / corpus_word_count
pb = wordb_count / corpus_word_count
pab = bigram_count / corpus_word_count
return log(pab / (pa * pb)) / -log(pab)
else:
# Return -infinity to make sure that phrases
# will be created only out of bigrams more frequent than min_count
return float('-inf')


def pseudocorpus(source_vocab, sep, common_terms=frozenset()):
Expand Down