Commit 2d0cc7b3 authored by Kathryn Elliott's avatar Kathryn Elliott

Clean up find_maximally_coherent_model.

parent f5780e4b
......@@ -239,20 +239,28 @@ class TopicModel:
self._models = models
def find_maximally_coherent_model(self):
max_model = None
max_n = 0
max_coherence_model = None
scores = []
# Documentation for these parameters: https://radimrehurek.com/gensim/models/coherencemodel.html
for n in self._models:
coherence_model = CoherenceModel(model = self._models[n], texts = self._corpus, dictionary = self._dictionary, coherence='c_v')
if(max_coherence_model == None or coherence_model.get_coherence() > max_coherence_model.get_coherence()):
coherence_score = coherence_model.get_coherence()
scores.append((n, coherence_score))
if(max_coherence_model == None or coherence_score > max_coherence_model.get_coherence()):
max_coherence_model = coherence_model
max_n = n
max_model = self._models[n]
for (n, score) in scores:
self._logging.info("Coherence for topic {0} = {1}".format(n, score))
return((max_n, max_model))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment