class_docstr: Objects of this class allow for building and maintaining a model for topic coherence.
  
  Examples
  ---------
  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
  
  .. sourcecode:: pycon
  
      >>> from gensim.test.utils import common_corpus, common_dictionary
      >>> from gensim.models.ldamodel import LdaModel
      >>> from gensim.models.coherencemodel import CoherenceModel
      >>>
      >>> model = LdaModel(common_corpus, 5, common_dictionary)
      >>>
      >>> cm = CoherenceModel(model=model, corpus=common_corpus, coherence='u_mass')
      >>> coherence = cm.get_coherence()  # get coherence value
  
  Another way of using this feature is through providing tokenized topics such as:
  
  .. sourcecode:: pycon
  
      >>> from gensim.test.utils import common_corpus, common_dictionary
      >>> from gensim.models.coherencemodel import CoherenceModel
      >>> topics = [
      ...     ['human', 'computer', 'system', 'interface'],
      ...     ['graph', 'minors', 'trees', 'eps']
      ... ]
      >>>
      >>> cm = CoherenceModel(topics=topics, corpus=common_corpus, dictionary=common_dictionary, coherence='u_mass')
      >>> coherence = cm.get_coherence()  # get coherence value
class_docstr_tok: ["Objects","of","this","class","allow","for","building","and","maintaining","a","model","for","topic","coherence",".","Examples","--","--","--","--","-","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","..","sourcecode",":",":","pycon",">",">",">","from","gensim.test.utils","import","common_corpus",",","common_dictionary",">",">",">","from","gensim.models.ldamodel","import","LdaModel",">",">",">","from","gensim.models.coherencemodel","import","CoherenceModel",">",">",">",">",">",">","model","=","LdaModel","(","common_corpus",",","5",",","common_dictionary",")",">",">",">",">",">",">","cm","=","CoherenceModel","(","model=model",",","corpus=common_corpus",",","coherence='u_mass","'",")",">",">",">","coherence","=","cm.get_coherence","(",")","#","get","coherence","value","Another","way","of","using","this","feature","is","through","providing","tokenized","topics","such","as",":","..","sourcecode",":",":","pycon",">",">",">","from","gensim.test.utils","import","common_corpus",",","common_dictionary",">",">",">","from","gensim.models.coherencemodel","import","CoherenceModel",">",">",">","topics","=","[","...","[","'human","'",",","'computer","'",",","'system","'",",","'interface","'","]",",","...","[","'graph","'",",","'minors","'",",","'trees","'",",","'eps","'","]","...","]",">",">",">",">",">",">","cm","=","CoherenceModel","(","topics=topics",",","corpus=common_corpus",",","dictionary=common_dictionary",",","coherence='u_mass","'",")",">",">",">","coherence","=","cm.get_coherence","(",")","#","get","coherence","value"]
docstr: Get average topic and model coherences.
  
  Parameters
  ----------
  model_topics : list of list of str
      Topics from the model.
  
  Returns
  -------
  list of (float, float)
      Sequence of pairs of average topic coherence and average coherence.
docstr_tok: ["Get","average","topic","and","model","coherences",".","Parameters","--","--","--","--","--","model_topics",":","list","of","list","of","str","Topics","from","the","model",".","Returns","--","--","--","-","list","of","(","float",",","float",")","Sequence","of","pairs","of","average","topic","coherence","and","average","coherence","."]
code: def _compare_model_topics(self, model_topics):
      """Get average topic and model coherences.
  
      Parameters
      ----------
      model_topics : list of list of str
          Topics from the model.
  
      Returns
      -------
      list of (float, float)
          Sequence of pairs of average topic coherence and average coherence.
  
      """
      coherences = []
      last_topn_value = min(self.topn - 1, 4)
      topn_grid = list(range(self.topn, last_topn_value, -5))
  
      for model_num, topics in enumerate(model_topics):
          self.topics = topics
  
          # We evaluate at various values of N and average them. This is a more robust,
          # according to: http://people.eng.unimelb.edu.au/tbaldwin/pubs/naacl2016.pdf
          coherence_at_n = {}
          for n in topn_grid:
              self.topn = n
              topic_coherences = self.get_coherence_per_topic()
  
              # Let's record the coherences for each topic, as well as the aggregated
              # coherence across all of the topics.
              # Some of them may be nan (if all words were OOV), so do mean value imputation.
              filled_coherences = np.array(topic_coherences)
              filled_coherences[
                  np.isnan(filled_coherences)
              ] = np.nanmean(filled_coherences)
              coherence_at_n[n] = (
                  topic_coherences,
                  self.aggregate_measures(filled_coherences),
              )
  
          topic_coherences, avg_coherences = zip(
              *coherence_at_n.values()
          )
          avg_topic_coherences = np.vstack(topic_coherences).mean(0)
          model_coherence = np.mean(avg_coherences)
          logging.info(
              "Avg coherence for model %d: %.5f"
              % (model_num, model_coherence)
          )
          coherences.append((avg_topic_coherences, model_coherence))
  
      return coherences
  
imports: import logging
  import multiprocessing
  from collections import namedtuple
  import numpy
  from gensim import interfaces, matutils
  from gensim import utils
  from gensim.topic_coherence import segmentation, probability_estimation, direct_confirmation_measure, indirect_confirmation_measure, aggregation
  from gensim.topic_coherence.probability_estimation import unique_ids_from_segments
label_desc: Use image node_id 26 for calling the CoherenceModel obj's underlying member method code with example usage: obj._compare_model_topics(model_topics) and returns: coherences