class_docstr: Estimate Dynamic Topic Model parameters based on a training corpus.
class_docstr_tok: ["Estimate","Dynamic","Topic","Model","parameters","based","on","a","training","corpus","."]
docstr: Parameters
  ----------
  corpus : {iterable of list of (int, float), scipy.sparse.csc}, optional
      Stream of document vectors or sparse matrix of shape (`num_documents`, `num_terms`).
      If not given, the model is left untrained (presumably because you want to call
      :meth:`~gensim.models.ldamodel.LdaSeqModel.update` manually).
  time_slice : list of int, optional
      Number of documents in each time-slice. Each time slice could for example represent a year's published
      papers, in case the corpus comes from a journal publishing over multiple years.
      It is assumed that `sum(time_slice) == num_documents`.
  id2word : dict of (int, str), optional
      Mapping from word IDs to words. It is used to determine the vocabulary size, as well as for
      debugging and topic printing.
  alphas : float, optional
      The prior probability for the model.
  num_topics : int, optional
      The number of requested latent topics to be extracted from the training corpus.
  initialize : {'gensim', 'own', 'ldamodel'}, optional
      Controls the initialization of the DTM model. Supports three different modes:
          * 'gensim': Uses gensim's LDA initialization.
          * 'own': Uses your own initialization matrix of an LDA model that has been previously trained.
          * 'lda_model': Use a previously used LDA model, passing it through the `lda_model` argument.
  sstats : numpy.ndarray , optional
      Sufficient statistics used for initializing the model if `initialize == 'own'`. Corresponds to matrix
      beta in the linked paper for time slice 0, expected shape (`self.vocab_len`, `num_topics`).
  lda_model : :class:`~gensim.models.ldamodel.LdaModel`
      Model whose sufficient statistics will be used to initialize the current object if `initialize == 'gensim'`.
  obs_variance : float, optional
      Observed variance used to approximate the true and forward variance as shown in
      `David M. Blei, John D. Lafferty: "Dynamic Topic Models"
      <https://mimno.infosci.cornell.edu/info6150/readings/dynamic_topic_models.pdf>`_.
  chain_variance : float, optional
      Gaussian parameter defined in the beta distribution to dictate how the beta values evolve over time.
  passes : int, optional
      Number of passes over the corpus for the initial :class:`~gensim.models.ldamodel.LdaModel`
  random_state : {numpy.random.RandomState, int}, optional
      Can be a np.random.RandomState object, or the seed to generate one. Used for reproducibility of results.
  lda_inference_max_iter : int, optional
      Maximum number of iterations in the inference step of the LDA training.
  em_min_iter : int, optional
      Minimum number of iterations until converge of the Expectation-Maximization algorithm
  em_max_iter : int, optional
      Maximum number of iterations until converge of the Expectation-Maximization algorithm.
  chunksize : int, optional
      Number of documents in the corpus do be processed in in a chunk.
docstr_tok: ["Parameters","--","--","--","--","--","corpus",":","{","iterable","of","list","of","(","int",",","float",")",",","scipy.sparse.csc","}",",","optional","Stream","of","document","vectors","or","sparse","matrix","of","shape","(","`","num_documents","`",",","`","num_terms","`",")",".","If","not","given",",","the","model","is","left","untrained","(","presumably","because","you","want","to","call",":","meth",":","`","~gensim.models.ldamodel.LdaSeqModel.update","`","manually",")",".","time_slice",":","list","of","int",",","optional","Number","of","documents","in","each","time-slice",".","Each","time","slice","could","for","example","represent","a","year","'s","published","papers",",","in","case","the","corpus","comes","from","a","journal","publishing","over","multiple","years",".","It","is","assumed","that","`","sum","(","time_slice",")","==","num_documents","`",".","id2word",":","dict","of","(","int",",","str",")",",","optional","Mapping","from","word","IDs","to","words",".","It","is","used","to","determine","the","vocabulary","size",",","as","well","as","for","debugging","and","topic","printing",".","alphas",":","float",",","optional","The","prior","probability","for","the","model",".","num_topics",":","int",",","optional","The","number","of","requested","latent","topics","to","be","extracted","from","the","training","corpus",".","initialize",":","{","'gensim","'",",","'own","'",",","'ldamodel","'","}",",","optional","Controls","the","initialization","of","the","DTM","model",".","Supports","three","different","modes",":","*","'gensim","'",":","Uses","gensim","'s","LDA","initialization",".","*","'own","'",":","Uses","your","own","initialization","matrix","of","an","LDA","model","that","has","been","previously","trained",".","*","'lda_model","'",":","Use","a","previously","used","LDA","model",",","passing","it","through","the","`","lda_model","`","argument",".","sstats",":","numpy.ndarray",",","optional","Sufficient","statistics","used","for","initializing","the","model","if","`","initialize","==","'own","'","`",".","Corresponds","to","matrix","beta","in","the","linked","paper","for","time","slice","0",",","expected","shape","(","`","self.vocab_len","`",",","`","num_topics","`",")",".","lda_model",":",":","class",":","`","~gensim.models.ldamodel.LdaModel","`","Model","whose","sufficient","statistics","will","be","used","to","initialize","the","current","object","if","`","initialize","==","'gensim","'","`",".","obs_variance",":","float",",","optional","Observed","variance","used","to","approximate","the","true","and","forward","variance","as","shown","in","`","David","M.","Blei",",","John","D.","Lafferty",":","``","Dynamic","Topic","Models","''","<","https",":","\/\/mimno.infosci.cornell.edu\/info6150\/readings\/dynamic_topic_models.pdf",">","`","_",".","chain_variance",":","float",",","optional","Gaussian","parameter","defined","in","the","beta","distribution","to","dictate","how","the","beta","values","evolve","over","time",".","passes",":","int",",","optional","Number","of","passes","over","the","corpus","for","the","initial",":","class",":","`","~gensim.models.ldamodel.LdaModel","`","random_state",":","{","numpy.random.RandomState",",","int","}",",","optional","Can","be","a","np.random.RandomState","object",",","or","the","seed","to","generate","one",".","Used","for","reproducibility","of","results",".","lda_inference_max_iter",":","int",",","optional","Maximum","number","of","iterations","in","the","inference","step","of","the","LDA","training",".","em_min_iter",":","int",",","optional","Minimum","number","of","iterations","until","converge","of","the","Expectation-Maximization","algorithm","em_max_iter",":","int",",","optional","Maximum","number","of","iterations","until","converge","of","the","Expectation-Maximization","algorithm",".","chunksize",":","int",",","optional","Number","of","documents","in","the","corpus","do","be","processed","in","in","a","chunk","."]
code: def __init__(
      self,
      corpus=None,
      time_slice=None,
      id2word=None,
      alphas=0.01,
      num_topics=10,
      initialize="gensim",
      sstats=None,
      lda_model=None,
      obs_variance=0.5,
      chain_variance=0.005,
      passes=10,
      random_state=None,
      lda_inference_max_iter=25,
      em_min_iter=6,
      em_max_iter=20,
      chunksize=100,
  ):
      """
  
      Parameters
      ----------
      corpus : {iterable of list of (int, float), scipy.sparse.csc}, optional
          Stream of document vectors or sparse matrix of shape (`num_documents`, `num_terms`).
          If not given, the model is left untrained (presumably because you want to call
          :meth:`~gensim.models.ldamodel.LdaSeqModel.update` manually).
      time_slice : list of int, optional
          Number of documents in each time-slice. Each time slice could for example represent a year's published
          papers, in case the corpus comes from a journal publishing over multiple years.
          It is assumed that `sum(time_slice) == num_documents`.
      id2word : dict of (int, str), optional
          Mapping from word IDs to words. It is used to determine the vocabulary size, as well as for
          debugging and topic printing.
      alphas : float, optional
          The prior probability for the model.
      num_topics : int, optional
          The number of requested latent topics to be extracted from the training corpus.
      initialize : {'gensim', 'own', 'ldamodel'}, optional
          Controls the initialization of the DTM model. Supports three different modes:
              * 'gensim': Uses gensim's LDA initialization.
              * 'own': Uses your own initialization matrix of an LDA model that has been previously trained.
              * 'lda_model': Use a previously used LDA model, passing it through the `lda_model` argument.
      sstats : numpy.ndarray , optional
          Sufficient statistics used for initializing the model if `initialize == 'own'`. Corresponds to matrix
          beta in the linked paper for time slice 0, expected shape (`self.vocab_len`, `num_topics`).
      lda_model : :class:`~gensim.models.ldamodel.LdaModel`
          Model whose sufficient statistics will be used to initialize the current object if `initialize == 'gensim'`.
      obs_variance : float, optional
          Observed variance used to approximate the true and forward variance as shown in
          `David M. Blei, John D. Lafferty: "Dynamic Topic Models"
          <https://mimno.infosci.cornell.edu/info6150/readings/dynamic_topic_models.pdf>`_.
      chain_variance : float, optional
          Gaussian parameter defined in the beta distribution to dictate how the beta values evolve over time.
      passes : int, optional
          Number of passes over the corpus for the initial :class:`~gensim.models.ldamodel.LdaModel`
      random_state : {numpy.random.RandomState, int}, optional
          Can be a np.random.RandomState object, or the seed to generate one. Used for reproducibility of results.
      lda_inference_max_iter : int, optional
          Maximum number of iterations in the inference step of the LDA training.
      em_min_iter : int, optional
          Minimum number of iterations until converge of the Expectation-Maximization algorithm
      em_max_iter : int, optional
          Maximum number of iterations until converge of the Expectation-Maximization algorithm.
      chunksize : int, optional
          Number of documents in the corpus do be processed in in a chunk.
  
      """
      self.id2word = id2word
      if corpus is None and self.id2word is None:
          raise ValueError(
              "at least one of corpus/id2word must be specified, to establish input space dimensionality"
          )
  
      if self.id2word is None:
          logger.warning(
              "no word id mapping provided; initializing from corpus, assuming identity"
          )
          self.id2word = utils.dict_from_corpus(corpus)
          self.vocab_len = len(self.id2word)
      elif self.id2word:
          self.vocab_len = len(self.id2word)
      else:
          self.vocab_len = 0
  
      if corpus is not None:
          try:
              self.corpus_len = len(corpus)
          except TypeError:
              logger.warning(
                  "input corpus stream has no len(); counting documents"
              )
              self.corpus_len = sum(1 for _ in corpus)
  
      self.time_slice = time_slice
      if self.time_slice is not None:
          self.num_time_slices = len(time_slice)
  
      self.num_topics = num_topics
      self.num_time_slices = len(time_slice)
      self.alphas = np.full(num_topics, alphas)
  
      # topic_chains contains for each topic a 'state space language model' object
      # which in turn has information about each topic
      # the sslm class is described below and contains information
      # on topic-word probabilities and doc-topic probabilities.
      self.topic_chains = []
      for topic in range(num_topics):
          sslm_ = sslm(
              num_time_slices=self.num_time_slices,
              vocab_len=self.vocab_len,
              num_topics=self.num_topics,
              chain_variance=chain_variance,
              obs_variance=obs_variance,
          )
          self.topic_chains.append(sslm_)
  
      # the following are class variables which are to be integrated during Document Influence Model
      self.top_doc_phis = None
      self.influence = None
      self.renormalized_influence = None
      self.influence_sum_lgl = None
  
      # if a corpus and time_slice is provided, depending on the user choice of initializing LDA, we start DTM.
      if corpus is not None and time_slice is not None:
          self.max_doc_len = max(len(line) for line in corpus)
  
          if initialize == "gensim":
              lda_model = ldamodel.LdaModel(
                  corpus,
                  id2word=self.id2word,
                  num_topics=self.num_topics,
                  passes=passes,
                  alpha=self.alphas,
                  random_state=random_state,
                  dtype=np.float64,
              )
              self.sstats = np.transpose(lda_model.state.sstats)
          if initialize == "ldamodel":
              self.sstats = np.transpose(lda_model.state.sstats)
          if initialize == "own":
              self.sstats = sstats
  
          # initialize model from sstats
          self.init_ldaseq_ss(
              chain_variance, obs_variance, self.alphas, self.sstats
          )
  
          # fit DTM
          self.fit_lda_seq(
              corpus,
              lda_inference_max_iter,
              em_min_iter,
              em_max_iter,
              chunksize,
          )
  
imports: import logging
  import numpy
  from scipy.special import digamma, gammaln
  from scipy import optimize
  from gensim import utils, matutils
  from gensim.models import ldamodel
label_desc: Use image node_id 1 to create a new LdaSeqModel object from inherited base classes: utils with example: obj = LdaSeqModel(corpus, time_slice, id2word, alphas, num_topics, initialize, sstats, lda_model, obs_variance, chain_variance, passes, random_state, lda_inference_max_iter, em_min_iter, em_max_iter, chunksize)