class_docstr: Ensemble Latent Dirichlet Allocation (eLDA), a method of training a topic model ensemble.
  
  Extracts stable topics that are consistently learned across multiple LDA models. eLDA has the added benefit that
  the user does not need to know the exact number of topics the topic model should extract ahead of time.
class_docstr_tok: ["Ensemble","Latent","Dirichlet","Allocation","(","eLDA",")",",","a","method","of","training","a","topic","model","ensemble",".","Extracts","stable","topics","that","are","consistently","learned","across","multiple","LDA","models",".","eLDA","has","the","added","benefit","that","the","user","does","not","need","to","know","the","exact","number","of","topics","the","topic","model","should","extract","ahead","of","time","."]
docstr: Create a gensim model from the stable topics.
  
  The returned representation is an Gensim LdaModel (:py:class:`gensim.models.LdaModel`) that has been
  instantiated with an A-priori belief on word probability, eta, that represents the topic-term distributions of
  any stable topics the were found by clustering over the ensemble of topic distributions.
  
  When no stable topics have been detected, None is returned.
  
  Returns
  -------
  :py:class:`gensim.models.LdaModel`
      A Gensim LDA Model classic_model_representation for which:
      ``classic_model_representation.get_topics() == self.get_topics()``
docstr_tok: ["Create","a","gensim","model","from","the","stable","topics",".","The","returned","representation","is","an","Gensim","LdaModel","(",":","py",":","class",":","`","gensim.models.LdaModel","`",")","that","has","been","instantiated","with","an","A-priori","belief","on","word","probability",",","eta",",","that","represents","the","topic-term","distributions","of","any","stable","topics","the","were","found","by","clustering","over","the","ensemble","of","topic","distributions",".","When","no","stable","topics","have","been","detected",",","None","is","returned",".","Returns","--","--","--","-",":","py",":","class",":","`","gensim.models.LdaModel","`","A","Gensim","LDA","Model","classic_model_representation","for","which",":","``","classic_model_representation.get_topics","(",")","==","self.get_topics","(",")","``"]
code: def generate_gensim_representation(self):
      """Create a gensim model from the stable topics.
  
      The returned representation is an Gensim LdaModel (:py:class:`gensim.models.LdaModel`) that has been
      instantiated with an A-priori belief on word probability, eta, that represents the topic-term distributions of
      any stable topics the were found by clustering over the ensemble of topic distributions.
  
      When no stable topics have been detected, None is returned.
  
      Returns
      -------
      :py:class:`gensim.models.LdaModel`
          A Gensim LDA Model classic_model_representation for which:
          ``classic_model_representation.get_topics() == self.get_topics()``
  
      """
      logger.info(
          "generating classic gensim model representation based on results from the ensemble"
      )
  
      sstats_sum = self.sstats_sum
      # if sstats_sum (which is the number of words actually) should be wrong for some fantastic funny reason
      # that makes you want to peel your skin off, recreate it (takes a while):
      if (
          sstats_sum == 0
          and "corpus" in self.gensim_kw_args
          and not self.gensim_kw_args["corpus"] is None
      ):
          for document in self.gensim_kw_args["corpus"]:
              for token in document:
                  sstats_sum += token[1]
          self.sstats_sum = sstats_sum
  
      stable_topics = self.get_topics()
  
      num_stable_topics = len(stable_topics)
  
      if num_stable_topics == 0:
          logger.error(
              "the model did not detect any stable topic. You can try to adjust epsilon: "
              "recluster(eps=...)"
          )
          self.classic_model_representation = None
          return
  
      # create a new gensim model
      params = self.gensim_kw_args.copy()
      params["eta"] = self.eta
      params["num_topics"] = num_stable_topics
      # adjust params in a way that no training happens
      params["passes"] = 0  # no training
      # iterations is needed for inference, pass it to the model
  
      classic_model_representation = self.get_topic_model_class()(
          **params
      )
  
      # when eta was None, use what gensim generates as default eta for the following tasks:
      eta = classic_model_representation.eta
      if sstats_sum == 0:
          sstats_sum = classic_model_representation.state.sstats.sum()
          self.sstats_sum = sstats_sum
  
      # the following is important for the denormalization
      # to generate the proper sstats for the new gensim model:
      # transform to dimensionality of stable_topics. axis=1 is summed
      eta_sum = 0
      if isinstance(eta, (int, float)):
          eta_sum = [eta * len(stable_topics[0])] * num_stable_topics
      else:
          if len(eta.shape) == 1:  # [e1, e2, e3]
              eta_sum = [[eta.sum()]] * num_stable_topics
          if (
              len(eta.shape) > 1
          ):  # [[e11, e12, ...], [e21, e22, ...], ...]
              eta_sum = np.array(eta.sum(axis=1)[:, None])
  
      # the factor, that will be used when get_topics() is used, for normalization
      # will never change, because the sum for eta as well as the sum for sstats is constant.
      # Therefore predicting normalization_factor becomes super easy.
      # corpus is a mapping of id to occurrences
  
      # so one can also easily calculate the
      # right sstats, so that get_topics() will return the stable topics no
      # matter eta.
  
      normalization_factor = (
          np.array(
              [[sstats_sum / num_stable_topics]] * num_stable_topics
          )
          + eta_sum
      )
  
      sstats = stable_topics * normalization_factor
      sstats -= eta
  
      classic_model_representation.state.sstats = sstats.astype(
          np.float32
      )
      # fix expElogbeta.
      classic_model_representation.sync_state()
  
      self.classic_model_representation = classic_model_representation
  
      return classic_model_representation
  
imports: import logging
  import os
  from multiprocessing import Process, Pipe, ProcessError
  import importlib
  from typing import Set, Optional, List
  import numpy
  from scipy.spatial.distance import cosine
  from dataclasses import dataclass
  from gensim import utils
  from gensim.models import ldamodel, ldamulticore, basemodel
  from gensim.utils import SaveLoad
label_desc: Use image node_id 5 for calling the EnsembleLda obj's underlying member method code with example usage: obj.generate_gensim_representation() and returns: classic_model_representation