Skip to content

Commit

Permalink
FIX MIND-Lab#91 add parameter for setting num of processes coherence
Browse files Browse the repository at this point in the history
  • Loading branch information
silviatti committed Apr 15, 2023
1 parent 37b9434 commit 86eae20
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
5 changes: 5 additions & 0 deletions HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
History
=======

1.11.2
---------------
* fix #91 add parameter for setting num of processes for gensim coherence


1.11.1
---------------
* fix gensim requirements #87
Expand Down
13 changes: 10 additions & 3 deletions octis/evaluation_metrics/coherence_metrics.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@


class Coherence(AbstractMetric):
def __init__(self, texts=None, topk=10, measure='c_npmi'):
def __init__(self, texts=None, topk=10, processes=1, measure='c_npmi'):
"""
Initialize metric
Expand All @@ -23,6 +23,7 @@ def __init__(self, texts=None, topk=10, measure='c_npmi'):
topk : how many most likely words to consider in
the evaluation
measure : (default 'c_npmi') measure to use.
processes: number of processes
other measures: 'u_mass', 'c_v', 'c_uci', 'c_npmi'
"""
super().__init__()
Expand All @@ -32,6 +33,7 @@ def __init__(self, texts=None, topk=10, measure='c_npmi'):
self._texts = texts
self._dictionary = Dictionary(self._texts)
self.topk = topk
self.processes = processes
self.measure = measure

def info(self):
Expand Down Expand Up @@ -59,8 +61,13 @@ def score(self, model_output):
if self.topk > len(topics[0]):
raise Exception('Words in topics are less than topk')
else:
npmi = CoherenceModel(topics=topics, texts=self._texts, dictionary=self._dictionary,
coherence=self.measure, processes=1, topn=self.topk)
npmi = CoherenceModel(
topics=topics,
texts=self._texts,
dictionary=self._dictionary,
coherence=self.measure,
processes=self.processes,
topn=self.topk)
return npmi.get_coherence()


Expand Down

0 comments on commit 86eae20

Please sign in to comment.