class_docstr: Train and use Online Latent Dirichlet Allocation model as presented in
  `'Online Learning for LDA' by Hoffman et al.`_
  
  Examples
  -------
  Initialize a model using a Gensim corpus
  
  .. sourcecode:: pycon
  
      >>> from gensim.test.utils import common_corpus
      >>>
      >>> lda = LdaModel(common_corpus, num_topics=10)
  
  You can then infer topic distributions on new, unseen documents.
  
  .. sourcecode:: pycon
  
      >>> doc_bow = [(1, 0.3), (2, 0.1), (0, 0.09)]
      >>> doc_lda = lda[doc_bow]
  
  The model can be updated (trained) with new documents.
  
  .. sourcecode:: pycon
  
      >>> # In practice (corpus =/= initial training corpus), but we use the same here for simplicity.
      >>> other_corpus = common_corpus
      >>>
      >>> lda.update(other_corpus)
  
  Model persistency is achieved through :meth:`~gensim.models.ldamodel.LdaModel.load` and
  :meth:`~gensim.models.ldamodel.LdaModel.save` methods.
class_docstr_tok: ["Train","and","use","Online","Latent","Dirichlet","Allocation","model","as","presented","in","`","'Online","Learning","for","LDA","'","by","Hoffman","et","al.","`","_","Examples","--","--","--","-","Initialize","a","model","using","a","Gensim","corpus","..","sourcecode",":",":","pycon",">",">",">","from","gensim.test.utils","import","common_corpus",">",">",">",">",">",">","lda","=","LdaModel","(","common_corpus",",","num_topics=10",")","You","can","then","infer","topic","distributions","on","new",",","unseen","documents",".","..","sourcecode",":",":","pycon",">",">",">","doc_bow","=","[","(","1",",","0.3",")",",","(","2",",","0.1",")",",","(","0",",","0.09",")","]",">",">",">","doc_lda","=","lda","[","doc_bow","]","The","model","can","be","updated","(","trained",")","with","new","documents",".","..","sourcecode",":",":","pycon",">",">",">","#","In","practice","(","corpus","=\/=","initial","training","corpus",")",",","but","we","use","the","same","here","for","simplicity",".",">",">",">","other_corpus","=","common_corpus",">",">",">",">",">",">","lda.update","(","other_corpus",")","Model","persistency","is","achieved","through",":","meth",":","`","~gensim.models.ldamodel.LdaModel.load","`","and",":","meth",":","`","~gensim.models.ldamodel.LdaModel.save","`","methods","."]
docstr: Calculate the difference in topic distributions between two models: `self` and `other`.
  
  Parameters
  ----------
  other : :class:`~gensim.models.ldamodel.LdaModel`
      The model which will be compared against the current object.
  distance : {'kullback_leibler', 'hellinger', 'jaccard', 'jensen_shannon'}
      The distance metric to calculate the difference with.
  num_words : int, optional
      The number of most relevant words used if `distance == 'jaccard'`. Also used for annotating topics.
  n_ann_terms : int, optional
      Max number of words in intersection/symmetric difference between topics. Used for annotation.
  diagonal : bool, optional
      Whether we need the difference between identical topics (the diagonal of the difference matrix).
  annotation : bool, optional
      Whether the intersection or difference of words between two topics should be returned.
  normed : bool, optional
      Whether the matrix should be normalized or not.
  
  Returns
  -------
  numpy.ndarray
      A difference matrix. Each element corresponds to the difference between the two topics,
      shape (`self.num_topics`, `other.num_topics`)
  numpy.ndarray, optional
      Annotation matrix where for each pair we include the word from the intersection of the two topics,
      and the word from the symmetric difference of the two topics. Only included if `annotation == True`.
      Shape (`self.num_topics`, `other_model.num_topics`, 2).
  
  Examples
  --------
  Get the differences between each pair of topics inferred by two models
  
  .. sourcecode:: pycon
  
      >>> from gensim.models.ldamulticore import LdaMulticore
      >>> from gensim.test.utils import datapath
      >>>
      >>> m1 = LdaMulticore.load(datapath("lda_3_0_1_model"))
      >>> m2 = LdaMulticore.load(datapath("ldamodel_python_3_5"))
      >>> mdiff, annotation = m1.diff(m2)
      >>> topic_diff = mdiff  # get matrix with difference for each topic pair from `m1` and `m2`
docstr_tok: ["Calculate","the","difference","in","topic","distributions","between","two","models",":","`","self","`","and","`","other","`",".","Parameters","--","--","--","--","--","other",":",":","class",":","`","~gensim.models.ldamodel.LdaModel","`","The","model","which","will","be","compared","against","the","current","object",".","distance",":","{","'kullback_leibler","'",",","'hellinger","'",",","'jaccard","'",",","'jensen_shannon","'","}","The","distance","metric","to","calculate","the","difference","with",".","num_words",":","int",",","optional","The","number","of","most","relevant","words","used","if","`","distance","==","'jaccard","'","`",".","Also","used","for","annotating","topics",".","n_ann_terms",":","int",",","optional","Max","number","of","words","in","intersection\/symmetric","difference","between","topics",".","Used","for","annotation",".","diagonal",":","bool",",","optional","Whether","we","need","the","difference","between","identical","topics","(","the","diagonal","of","the","difference","matrix",")",".","annotation",":","bool",",","optional","Whether","the","intersection","or","difference","of","words","between","two","topics","should","be","returned",".","normed",":","bool",",","optional","Whether","the","matrix","should","be","normalized","or","not",".","Returns","--","--","--","-","numpy.ndarray","A","difference","matrix",".","Each","element","corresponds","to","the","difference","between","the","two","topics",",","shape","(","`","self.num_topics","`",",","`","other.num_topics","`",")","numpy.ndarray",",","optional","Annotation","matrix","where","for","each","pair","we","include","the","word","from","the","intersection","of","the","two","topics",",","and","the","word","from","the","symmetric","difference","of","the","two","topics",".","Only","included","if","`","annotation","==","True","`",".","Shape","(","`","self.num_topics","`",",","`","other_model.num_topics","`",",","2",")",".","Examples","--","--","--","--","Get","the","differences","between","each","pair","of","topics","inferred","by","two","models","..","sourcecode",":",":","pycon",">",">",">","from","gensim.models.ldamulticore","import","LdaMulticore",">",">",">","from","gensim.test.utils","import","datapath",">",">",">",">",">",">","m1","=","LdaMulticore.load","(","datapath","(","``","lda_3_0_1_model","''",")",")",">",">",">","m2","=","LdaMulticore.load","(","datapath","(","``","ldamodel_python_3_5","''",")",")",">",">",">","mdiff",",","annotation","=","m1.diff","(","m2",")",">",">",">","topic_diff","=","mdiff","#","get","matrix","with","difference","for","each","topic","pair","from","`","m1","`","and","`","m2","`"]
code: def diff(
      self,
      other,
      distance="kullback_leibler",
      num_words=100,
      n_ann_terms=10,
      diagonal=False,
      annotation=True,
      normed=True,
  ):
      """Calculate the difference in topic distributions between two models: `self` and `other`.
  
      Parameters
      ----------
      other : :class:`~gensim.models.ldamodel.LdaModel`
          The model which will be compared against the current object.
      distance : {'kullback_leibler', 'hellinger', 'jaccard', 'jensen_shannon'}
          The distance metric to calculate the difference with.
      num_words : int, optional
          The number of most relevant words used if `distance == 'jaccard'`. Also used for annotating topics.
      n_ann_terms : int, optional
          Max number of words in intersection/symmetric difference between topics. Used for annotation.
      diagonal : bool, optional
          Whether we need the difference between identical topics (the diagonal of the difference matrix).
      annotation : bool, optional
          Whether the intersection or difference of words between two topics should be returned.
      normed : bool, optional
          Whether the matrix should be normalized or not.
  
      Returns
      -------
      numpy.ndarray
          A difference matrix. Each element corresponds to the difference between the two topics,
          shape (`self.num_topics`, `other.num_topics`)
      numpy.ndarray, optional
          Annotation matrix where for each pair we include the word from the intersection of the two topics,
          and the word from the symmetric difference of the two topics. Only included if `annotation == True`.
          Shape (`self.num_topics`, `other_model.num_topics`, 2).
  
      Examples
      --------
      Get the differences between each pair of topics inferred by two models
  
      .. sourcecode:: pycon
  
          >>> from gensim.models.ldamulticore import LdaMulticore
          >>> from gensim.test.utils import datapath
          >>>
          >>> m1 = LdaMulticore.load(datapath("lda_3_0_1_model"))
          >>> m2 = LdaMulticore.load(datapath("ldamodel_python_3_5"))
          >>> mdiff, annotation = m1.diff(m2)
          >>> topic_diff = mdiff  # get matrix with difference for each topic pair from `m1` and `m2`
  
      """
      distances = {
          "kullback_leibler": kullback_leibler,
          "hellinger": hellinger,
          "jaccard": jaccard_distance,
          "jensen_shannon": jensen_shannon,
      }
  
      if distance not in distances:
          valid_keys = ", ".join(
              "`{}`".format(x) for x in distances.keys()
          )
          raise ValueError(
              "Incorrect distance, valid only {}".format(valid_keys)
          )
  
      if not isinstance(other, self.__class__):
          raise ValueError(
              "The parameter `other` must be of type `{}`".format(
                  self.__name__
              )
          )
  
      distance_func = distances[distance]
      d1, d2 = self.get_topics(), other.get_topics()
      t1_size, t2_size = d1.shape[0], d2.shape[0]
      annotation_terms = None
  
      fst_topics = [
          {w for (w, _) in self.show_topic(topic, topn=num_words)}
          for topic in range(t1_size)
      ]
      snd_topics = [
          {w for (w, _) in other.show_topic(topic, topn=num_words)}
          for topic in range(t2_size)
      ]
  
      if distance == "jaccard":
          d1, d2 = fst_topics, snd_topics
  
      if diagonal:
          assert t1_size == t2_size, (
              "Both input models should have same no. of topics, "
              "as the diagonal will only be valid in a square matrix"
          )
          # initialize z and annotation array
          z = np.zeros(t1_size)
          if annotation:
              annotation_terms = np.zeros(t1_size, dtype=list)
      else:
          # initialize z and annotation matrix
          z = np.zeros((t1_size, t2_size))
          if annotation:
              annotation_terms = np.zeros(
                  (t1_size, t2_size), dtype=list
              )
  
      # iterate over each cell in the initialized z and annotation
      for topic in np.ndindex(z.shape):
          topic1 = topic[0]
          if diagonal:
              topic2 = topic1
          else:
              topic2 = topic[1]
  
          z[topic] = distance_func(d1[topic1], d2[topic2])
          if annotation:
              pos_tokens = fst_topics[topic1] & snd_topics[topic2]
              neg_tokens = fst_topics[topic1].symmetric_difference(
                  snd_topics[topic2]
              )
  
              pos_tokens = list(pos_tokens)[
                  : min(len(pos_tokens), n_ann_terms)
              ]
              neg_tokens = list(neg_tokens)[
                  : min(len(neg_tokens), n_ann_terms)
              ]
  
              annotation_terms[topic] = [pos_tokens, neg_tokens]
  
      if normed:
          if np.abs(np.max(z)) > 1e-8:
              z /= np.max(z)
  
      return z, annotation_terms
  
imports: import logging
  import numbers
  import os
  import time
  from collections import defaultdict
  import numpy
  from scipy.special import gammaln, psi
  from scipy.special import polygamma
  from gensim import interfaces, utils, matutils
  from gensim.matutils import kullback_leibler, hellinger, jaccard_distance, jensen_shannon, dirichlet_expectation, logsumexp, mean_absolute_difference
  from gensim.models import basemodel, CoherenceModel
  from gensim.models.callbacks import Callback
label_desc: Use image node_id 21 for calling the LdaModel obj's underlying member method code with example usage: obj.diff(other, distance, num_words, n_ann_terms, diagonal, annotation, normed) and returns: z,  annotation_terms