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: Parameters
  ----------
  model : :class:`~gensim.models.basemodel.BaseTopicModel`, optional
      Pre-trained topic model, should be provided if topics is not provided.
      Currently supports :class:`~gensim.models.ldamodel.LdaModel`,
      :class:`~gensim.models.ldamulticore.LdaMulticore`.
      Use `topics` parameter to plug in an as yet unsupported model.
  topics : list of list of str, optional
      List of tokenized topics, if this is preferred over model - dictionary should be provided.
  texts : list of list of str, optional
      Tokenized texts, needed for coherence models that use sliding window based (i.e. coherence=`c_something`)
      probability estimator .
  corpus : iterable of list of (int, number), optional
      Corpus in BoW format.
  dictionary : :class:`~gensim.corpora.dictionary.Dictionary`, optional
      Gensim dictionary mapping of id word to create corpus.
      If `model.id2word` is present, this is not needed. If both are provided, passed `dictionary` will be used.
  window_size : int, optional
      Is the size of the window to be used for coherence measures using boolean sliding window as their
      probability estimator. For 'u_mass' this doesn't matter.
      If None - the default window sizes are used which are: 'c_v' - 110, 'c_uci' - 10, 'c_npmi' - 10.
  coherence : {'u_mass', 'c_v', 'c_uci', 'c_npmi'}, optional
      Coherence measure to be used.
      Fastest method - 'u_mass', 'c_uci' also known as `c_pmi`.
      For 'u_mass' corpus should be provided, if texts is provided, it will be converted to corpus
      using the dictionary. For 'c_v', 'c_uci' and 'c_npmi' `texts` should be provided (`corpus` isn't needed)
  topn : int, optional
      Integer corresponding to the number of top words to be extracted from each topic.
  processes : int, optional
      Number of processes to use for probability estimation phase, any value less than 1 will be interpreted as
      num_cpus - 1.
docstr_tok: ["Parameters","--","--","--","--","--","model",":",":","class",":","`","~gensim.models.basemodel.BaseTopicModel","`",",","optional","Pre-trained","topic","model",",","should","be","provided","if","topics","is","not","provided",".","Currently","supports",":","class",":","`","~gensim.models.ldamodel.LdaModel","`",",",":","class",":","`","~gensim.models.ldamulticore.LdaMulticore","`",".","Use","`","topics","`","parameter","to","plug","in","an","as","yet","unsupported","model",".","topics",":","list","of","list","of","str",",","optional","List","of","tokenized","topics",",","if","this","is","preferred","over","model","-","dictionary","should","be","provided",".","texts",":","list","of","list","of","str",",","optional","Tokenized","texts",",","needed","for","coherence","models","that","use","sliding","window","based","(","i.e",".","coherence=","`","c_something","`",")","probability","estimator",".","corpus",":","iterable","of","list","of","(","int",",","number",")",",","optional","Corpus","in","BoW","format",".","dictionary",":",":","class",":","`","~gensim.corpora.dictionary.Dictionary","`",",","optional","Gensim","dictionary","mapping","of","id","word","to","create","corpus",".","If","`","model.id2word","`","is","present",",","this","is","not","needed",".","If","both","are","provided",",","passed","`","dictionary","`","will","be","used",".","window_size",":","int",",","optional","Is","the","size","of","the","window","to","be","used","for","coherence","measures","using","boolean","sliding","window","as","their","probability","estimator",".","For","'u_mass","'","this","does","n't","matter",".","If","None","-","the","default","window","sizes","are","used","which","are",":","'c_v","'","-","110",",","'c_uci","'","-","10",",","'c_npmi","'","-","10.","coherence",":","{","'u_mass","'",",","'c_v","'",",","'c_uci","'",",","'c_npmi","'","}",",","optional","Coherence","measure","to","be","used",".","Fastest","method","-","'u_mass","'",",","'c_uci","'","also","known","as","`","c_pmi","`",".","For","'u_mass","'","corpus","should","be","provided",",","if","texts","is","provided",",","it","will","be","converted","to","corpus","using","the","dictionary",".","For","'c_v","'",",","'c_uci","'","and","'c_npmi","'","`","texts","`","should","be","provided","(","`","corpus","`","is","n't","needed",")","topn",":","int",",","optional","Integer","corresponding","to","the","number","of","top","words","to","be","extracted","from","each","topic",".","processes",":","int",",","optional","Number","of","processes","to","use","for","probability","estimation","phase",",","any","value","less","than","1","will","be","interpreted","as","num_cpus","-","1","."]
code: def __init__(
      self,
      model=None,
      topics=None,
      texts=None,
      corpus=None,
      dictionary=None,
      window_size=None,
      keyed_vectors=None,
      coherence="c_v",
      topn=20,
      processes=-1,
  ):
      """
  
      Parameters
      ----------
      model : :class:`~gensim.models.basemodel.BaseTopicModel`, optional
          Pre-trained topic model, should be provided if topics is not provided.
          Currently supports :class:`~gensim.models.ldamodel.LdaModel`,
          :class:`~gensim.models.ldamulticore.LdaMulticore`.
          Use `topics` parameter to plug in an as yet unsupported model.
      topics : list of list of str, optional
          List of tokenized topics, if this is preferred over model - dictionary should be provided.
      texts : list of list of str, optional
          Tokenized texts, needed for coherence models that use sliding window based (i.e. coherence=`c_something`)
          probability estimator .
      corpus : iterable of list of (int, number), optional
          Corpus in BoW format.
      dictionary : :class:`~gensim.corpora.dictionary.Dictionary`, optional
          Gensim dictionary mapping of id word to create corpus.
          If `model.id2word` is present, this is not needed. If both are provided, passed `dictionary` will be used.
      window_size : int, optional
          Is the size of the window to be used for coherence measures using boolean sliding window as their
          probability estimator. For 'u_mass' this doesn't matter.
          If None - the default window sizes are used which are: 'c_v' - 110, 'c_uci' - 10, 'c_npmi' - 10.
      coherence : {'u_mass', 'c_v', 'c_uci', 'c_npmi'}, optional
          Coherence measure to be used.
          Fastest method - 'u_mass', 'c_uci' also known as `c_pmi`.
          For 'u_mass' corpus should be provided, if texts is provided, it will be converted to corpus
          using the dictionary. For 'c_v', 'c_uci' and 'c_npmi' `texts` should be provided (`corpus` isn't needed)
      topn : int, optional
          Integer corresponding to the number of top words to be extracted from each topic.
      processes : int, optional
          Number of processes to use for probability estimation phase, any value less than 1 will be interpreted as
          num_cpus - 1.
  
      """
      if model is None and topics is None:
          raise ValueError("One of model or topics has to be provided.")
      elif topics is not None and dictionary is None:
          raise ValueError(
              "dictionary has to be provided if topics are to be used."
          )
  
      self.keyed_vectors = keyed_vectors
      if keyed_vectors is None and texts is None and corpus is None:
          raise ValueError("One of texts or corpus has to be provided.")
  
      # Check if associated dictionary is provided.
      if dictionary is None:
          if isinstance(model.id2word, utils.FakeDict):
              raise ValueError(
                  "The associated dictionary should be provided with the corpus or 'id2word'"
                  " for topic model should be set as the associated dictionary."
              )
          else:
              self.dictionary = model.id2word
      else:
          self.dictionary = dictionary
  
      # Check for correct inputs for u_mass coherence measure.
      self.coherence = coherence
      self.window_size = window_size
      if self.window_size is None:
          self.window_size = SLIDING_WINDOW_SIZES[self.coherence]
      self.texts = texts
      self.corpus = corpus
  
      if coherence in BOOLEAN_DOCUMENT_BASED:
          if utils.is_corpus(corpus)[0]:
              self.corpus = corpus
          elif self.texts is not None:
              self.corpus = [
                  self.dictionary.doc2bow(text) for text in self.texts
              ]
          else:
              raise ValueError(
                  "Either 'corpus' with 'dictionary' or 'texts' should "
                  "be provided for %s coherence.",
                  coherence,
              )
  
      # Check for correct inputs for sliding window coherence measure.
      elif coherence == "c_w2v" and keyed_vectors is not None:
          pass
      elif coherence in SLIDING_WINDOW_BASED:
          if self.texts is None:
              raise ValueError(
                  "'texts' should be provided for %s coherence.",
                  coherence,
              )
      else:
          raise ValueError(
              "%s coherence is not currently supported.", coherence
          )
  
      self._topn = topn
      self._model = model
      self._accumulator = None
      self._topics = None
      self.topics = topics
  
      self.processes = (
          processes if processes >= 1 else max(1, mp.cpu_count() - 1)
      )
  
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 1 to create a new CoherenceModel object from inherited base classes: interfaces with example: obj = CoherenceModel(model, topics, texts, corpus, dictionary, window_size, keyed_vectors, coherence, topn, processes)