class gensim.models.CoherenceModel(model=None, topics=None, texts=None, corpus=None, dictionary=None, window_size=None, coherence='c_v', topn=10)[source]

Objects of this class allow for building and maintaining a model for topic coherence.

The main methods are:

  1. constructor, which initializes the four stage pipeline by accepting a coherence measure,
  2. the get_coherence() method, which returns the topic coherence.

One way of using this feature is through providing a trained topic model. A dictionary has to be explicitly provided if the model does not contain a dictionary already. >>> cm = CoherenceModel(model=tm, corpus=corpus, coherence=’u_mass’) # tm is the trained topic model >>> cm.get_coherence()

Another way of using this feature is through providing tokenized topics such as: >>> topics = [[‘human’, ‘computer’, ‘system’, ‘interface’],

[‘graph’, ‘minors’, ‘trees’, ‘eps’]]
>>> cm = CoherenceModel(topics=topics, corpus=corpus, dictionary=dictionary, coherence='u_mass') # note that a dictionary has to be provided.
>>> cm.get_coherence()

Model persistency is achieved via its load/save methods.


__init__([model, topics, texts, corpus, ...]) Args: —- model : Pre-trained topic model.
get_coherence() Return coherence value based on pipeline parameters.
load(fname[, mmap]) Load a previously saved object from file (also see save).
save(fname_or_handle[, separately, ...]) Save the object to file (also see load).