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 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
15 changes: 10 additions & 5 deletions gensim/models/phrases.py
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,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.
Ignore all bigrams with total collected count lower than this value.
corpus_word_count : int
Total number of words in the corpus.

Expand All @@ -678,10 +678,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:
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 no phrases will be created
# from bigrams less frequent than min_count
return float('-inf')


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