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 and return per-word likelihood bound, using a chunk of documents as evaluation corpus.
  
  Also output the calculated statistics, including the perplexity=2^(-bound), to log at INFO level.
  
  Parameters
  ----------
  chunk : list of list of (int, float)
      The corpus chunk on which the inference step will be performed.
  total_docs : int, optional
      Number of docs used for evaluation of the perplexity.
  
  Returns
  -------
  numpy.ndarray
      The variational bound score calculated for each word.
docstr_tok: ["Calculate","and","return","per-word","likelihood","bound",",","using","a","chunk","of","documents","as","evaluation","corpus",".","Also","output","the","calculated","statistics",",","including","the","perplexity=2^","(","-bound",")",",","to","log","at","INFO","level",".","Parameters","--","--","--","--","--","chunk",":","list","of","list","of","(","int",",","float",")","The","corpus","chunk","on","which","the","inference","step","will","be","performed",".","total_docs",":","int",",","optional","Number","of","docs","used","for","evaluation","of","the","perplexity",".","Returns","--","--","--","-","numpy.ndarray","The","variational","bound","score","calculated","for","each","word","."]
code: def log_perplexity(self, chunk, total_docs=None):
      """Calculate and return per-word likelihood bound, using a chunk of documents as evaluation corpus.
  
      Also output the calculated statistics, including the perplexity=2^(-bound), to log at INFO level.
  
      Parameters
      ----------
      chunk : list of list of (int, float)
          The corpus chunk on which the inference step will be performed.
      total_docs : int, optional
          Number of docs used for evaluation of the perplexity.
  
      Returns
      -------
      numpy.ndarray
          The variational bound score calculated for each word.
  
      """
      if total_docs is None:
          total_docs = len(chunk)
      corpus_words = sum(
          cnt for document in chunk for _, cnt in document
      )
      subsample_ratio = 1.0 * total_docs / len(chunk)
      perwordbound = self.bound(
          chunk, subsample_ratio=subsample_ratio
      ) / (subsample_ratio * corpus_words)
      logger.info(
          "%.3f per-word bound, %.1f perplexity estimate based on a held-out corpus of %i documents with %i words",
          perwordbound,
          np.exp2(-perwordbound),
          len(chunk),
          corpus_words,
      )
      return perwordbound
  
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 10 for calling the LdaModel obj's underlying member method code with example usage: obj.log_perplexity(chunk, total_docs) and returns: perwordbound