class_docstr: The constructor estimates the author-topic model parameters based on a training corpus.
class_docstr_tok: ["The","constructor","estimates","the","author-topic","model","parameters","based","on","a","training","corpus","."]
docstr: Parameters
  ----------
  corpus : iterable of list of (int, float), optional
      Corpus in BoW format
  num_topics : int, optional
      Number of topics to be extracted from the training corpus.
  id2word : :class:`~gensim.corpora.dictionary.Dictionary`, optional
      A mapping from word ids (integers) to words (strings).
  author2doc : dict of (str, list of int), optional
      A dictionary where keys are the names of authors and values are lists of document IDs that the author
      contributes to.
  doc2author : dict of (int, list of str), optional
      A dictionary where the keys are document IDs and the values are lists of author names.
  chunksize : int, optional
      Controls the size of the mini-batches.
  passes : int, optional
      Number of times the model makes a pass over the entire training data.
  iterations : int, optional
      Maximum number of times the model loops over each document.
  decay : float, optional
      A number between (0.5, 1] to weight what percentage of the previous lambda value is forgotten
      when each new document is examined. Corresponds to :math:`\kappa` from
      `'Online Learning for LDA' by Hoffman et al.`_
  offset : float, optional
      Hyper-parameter that controls how much we will slow down the first steps the first few iterations.
      Corresponds to :math:`\tau_0` from `'Online Learning for LDA' by Hoffman et al.`_
  alpha : {float, numpy.ndarray of float, list of float, str}, optional
      A-priori belief on document-topic distribution, this can be:
          * scalar for a symmetric prior over document-topic distribution,
          * 1D array of length equal to num_topics to denote an asymmetric user defined prior for each topic.
  
      Alternatively default prior selecting strategies can be employed by supplying a string:
          * 'symmetric': (default) Uses a fixed symmetric prior of `1.0 / num_topics`,
          * 'asymmetric': Uses a fixed normalized asymmetric prior of `1.0 / (topic_index + sqrt(num_topics))`,
          * 'auto': Learns an asymmetric prior from the corpus (not available if `distributed==True`).
  eta : {float, numpy.ndarray of float, list of float, str}, optional
      A-priori belief on topic-word distribution, this can be:
          * scalar for a symmetric prior over topic-word distribution,
          * 1D array of length equal to num_words to denote an asymmetric user defined prior for each word,
          * matrix of shape (num_topics, num_words) to assign a probability for each word-topic combination.
  
      Alternatively default prior selecting strategies can be employed by supplying a string:
          * 'symmetric': (default) Uses a fixed symmetric prior of `1.0 / num_topics`,
          * 'auto': Learns an asymmetric prior from the corpus.
  update_every : int, optional
      Make updates in topic probability for latest mini-batch.
  eval_every : int, optional
      Calculate and estimate log perplexity for latest mini-batch.
  gamma_threshold : float, optional
      Threshold value of gamma(topic difference between consecutive two topics)
      until which the iterations continue.
  serialized : bool, optional
      Indicates whether the input corpora to the model are simple lists
      or saved to the hard-drive.
  serialization_path : str, optional
      Must be set to a filepath, if `serialized = True` is used.
  minimum_probability : float, optional
      Controls filtering the topics returned for a document (bow).
  random_state : {int, numpy.random.RandomState}, optional
      Set the state of the random number generator inside the author-topic model.
docstr_tok: ["Parameters","--","--","--","--","--","corpus",":","iterable","of","list","of","(","int",",","float",")",",","optional","Corpus","in","BoW","format","num_topics",":","int",",","optional","Number","of","topics","to","be","extracted","from","the","training","corpus",".","id2word",":",":","class",":","`","~gensim.corpora.dictionary.Dictionary","`",",","optional","A","mapping","from","word","ids","(","integers",")","to","words","(","strings",")",".","author2doc",":","dict","of","(","str",",","list","of","int",")",",","optional","A","dictionary","where","keys","are","the","names","of","authors","and","values","are","lists","of","document","IDs","that","the","author","contributes","to",".","doc2author",":","dict","of","(","int",",","list","of","str",")",",","optional","A","dictionary","where","the","keys","are","document","IDs","and","the","values","are","lists","of","author","names",".","chunksize",":","int",",","optional","Controls","the","size","of","the","mini-batches",".","passes",":","int",",","optional","Number","of","times","the","model","makes","a","pass","over","the","entire","training","data",".","iterations",":","int",",","optional","Maximum","number","of","times","the","model","loops","over","each","document",".","decay",":","float",",","optional","A","number","between","(","0.5",",","1","]","to","weight","what","percentage","of","the","previous","lambda","value","is","forgotten","when","each","new","document","is","examined",".","Corresponds","to",":","math",":","`","\\kappa","`","from","`","'Online","Learning","for","LDA","'","by","Hoffman","et","al.","`","_","offset",":","float",",","optional","Hyper-parameter","that","controls","how","much","we","will","slow","down","the","first","steps","the","first","few","iterations",".","Corresponds","to",":","math",":","`","\\tau_0","`","from","`","'Online","Learning","for","LDA","'","by","Hoffman","et","al.","`","_","alpha",":","{","float",",","numpy.ndarray","of","float",",","list","of","float",",","str","}",",","optional","A-priori","belief","on","document-topic","distribution",",","this","can","be",":","*","scalar","for","a","symmetric","prior","over","document-topic","distribution",",","*","1D","array","of","length","equal","to","num_topics","to","denote","an","asymmetric","user","defined","prior","for","each","topic",".","Alternatively","default","prior","selecting","strategies","can","be","employed","by","supplying","a","string",":","*","'symmetric","'",":","(","default",")","Uses","a","fixed","symmetric","prior","of","`","1.0","\/","num_topics","`",",","*","'asymmetric","'",":","Uses","a","fixed","normalized","asymmetric","prior","of","`","1.0","\/","(","topic_index","+","sqrt","(","num_topics",")",")","`",",","*","'auto","'",":","Learns","an","asymmetric","prior","from","the","corpus","(","not","available","if","`","distributed==True","`",")",".","eta",":","{","float",",","numpy.ndarray","of","float",",","list","of","float",",","str","}",",","optional","A-priori","belief","on","topic-word","distribution",",","this","can","be",":","*","scalar","for","a","symmetric","prior","over","topic-word","distribution",",","*","1D","array","of","length","equal","to","num_words","to","denote","an","asymmetric","user","defined","prior","for","each","word",",","*","matrix","of","shape","(","num_topics",",","num_words",")","to","assign","a","probability","for","each","word-topic","combination",".","Alternatively","default","prior","selecting","strategies","can","be","employed","by","supplying","a","string",":","*","'symmetric","'",":","(","default",")","Uses","a","fixed","symmetric","prior","of","`","1.0","\/","num_topics","`",",","*","'auto","'",":","Learns","an","asymmetric","prior","from","the","corpus",".","update_every",":","int",",","optional","Make","updates","in","topic","probability","for","latest","mini-batch",".","eval_every",":","int",",","optional","Calculate","and","estimate","log","perplexity","for","latest","mini-batch",".","gamma_threshold",":","float",",","optional","Threshold","value","of","gamma","(","topic","difference","between","consecutive","two","topics",")","until","which","the","iterations","continue",".","serialized",":","bool",",","optional","Indicates","whether","the","input","corpora","to","the","model","are","simple","lists","or","saved","to","the","hard-drive",".","serialization_path",":","str",",","optional","Must","be","set","to","a","filepath",",","if","`","serialized","=","True","`","is","used",".","minimum_probability",":","float",",","optional","Controls","filtering","the","topics","returned","for","a","document","(","bow",")",".","random_state",":","{","int",",","numpy.random.RandomState","}",",","optional","Set","the","state","of","the","random","number","generator","inside","the","author-topic","model","."]
code: def __init__(
      self,
      corpus=None,
      num_topics=100,
      id2word=None,
      author2doc=None,
      doc2author=None,
      chunksize=2000,
      passes=1,
      iterations=50,
      decay=0.5,
      offset=1.0,
      alpha="symmetric",
      eta="symmetric",
      update_every=1,
      eval_every=10,
      gamma_threshold=0.001,
      serialized=False,
      serialization_path=None,
      minimum_probability=0.01,
      random_state=None,
  ):
      """
  
      Parameters
      ----------
      corpus : iterable of list of (int, float), optional
          Corpus in BoW format
      num_topics : int, optional
          Number of topics to be extracted from the training corpus.
      id2word : :class:`~gensim.corpora.dictionary.Dictionary`, optional
          A mapping from word ids (integers) to words (strings).
      author2doc : dict of (str, list of int), optional
          A dictionary where keys are the names of authors and values are lists of document IDs that the author
          contributes to.
      doc2author : dict of (int, list of str), optional
          A dictionary where the keys are document IDs and the values are lists of author names.
      chunksize : int, optional
          Controls the size of the mini-batches.
      passes : int, optional
          Number of times the model makes a pass over the entire training data.
      iterations : int, optional
          Maximum number of times the model loops over each document.
      decay : float, optional
          A number between (0.5, 1] to weight what percentage of the previous lambda value is forgotten
          when each new document is examined. Corresponds to :math:`\\kappa` from
          `'Online Learning for LDA' by Hoffman et al.`_
      offset : float, optional
          Hyper-parameter that controls how much we will slow down the first steps the first few iterations.
          Corresponds to :math:`\\tau_0` from `'Online Learning for LDA' by Hoffman et al.`_
      alpha : {float, numpy.ndarray of float, list of float, str}, optional
          A-priori belief on document-topic distribution, this can be:
              * scalar for a symmetric prior over document-topic distribution,
              * 1D array of length equal to num_topics to denote an asymmetric user defined prior for each topic.
  
          Alternatively default prior selecting strategies can be employed by supplying a string:
              * 'symmetric': (default) Uses a fixed symmetric prior of `1.0 / num_topics`,
              * 'asymmetric': Uses a fixed normalized asymmetric prior of `1.0 / (topic_index + sqrt(num_topics))`,
              * 'auto': Learns an asymmetric prior from the corpus (not available if `distributed==True`).
      eta : {float, numpy.ndarray of float, list of float, str}, optional
          A-priori belief on topic-word distribution, this can be:
              * scalar for a symmetric prior over topic-word distribution,
              * 1D array of length equal to num_words to denote an asymmetric user defined prior for each word,
              * matrix of shape (num_topics, num_words) to assign a probability for each word-topic combination.
  
          Alternatively default prior selecting strategies can be employed by supplying a string:
              * 'symmetric': (default) Uses a fixed symmetric prior of `1.0 / num_topics`,
              * 'auto': Learns an asymmetric prior from the corpus.
      update_every : int, optional
          Make updates in topic probability for latest mini-batch.
      eval_every : int, optional
          Calculate and estimate log perplexity for latest mini-batch.
      gamma_threshold : float, optional
          Threshold value of gamma(topic difference between consecutive two topics)
          until which the iterations continue.
      serialized : bool, optional
          Indicates whether the input corpora to the model are simple lists
          or saved to the hard-drive.
      serialization_path : str, optional
          Must be set to a filepath, if `serialized = True` is used.
      minimum_probability : float, optional
          Controls filtering the topics returned for a document (bow).
      random_state : {int, numpy.random.RandomState}, optional
          Set the state of the random number generator inside the author-topic model.
  
      """
      # NOTE: this doesn't call constructor of a base class, but duplicates most of this code
      # so we have to set dtype to float64 default here
      self.dtype = np.float64
  
      # NOTE: as distributed version of this model is not implemented, "distributed" is set to false. Some of the
      # infrastructure to implement a distributed author-topic model is already in place,
      # such as the AuthorTopicState.
      distributed = False
      self.dispatcher = None
      self.numworkers = 1
  
      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.num_terms = len(self.id2word)
      elif len(self.id2word) > 0:
          self.num_terms = 1 + max(self.id2word.keys())
      else:
          self.num_terms = 0
  
      if self.num_terms == 0:
          raise ValueError(
              "cannot compute the author-topic model over an empty collection (no terms)"
          )
  
      logger.info("Vocabulary consists of %d words.", self.num_terms)
  
      self.author2doc = {}
      self.doc2author = {}
  
      self.distributed = distributed
      self.num_topics = num_topics
      self.num_authors = 0
      self.chunksize = chunksize
      self.decay = decay
      self.offset = offset
      self.minimum_probability = minimum_probability
      self.num_updates = 0
      self.total_docs = 0
  
      self.passes = passes
      self.update_every = update_every
      self.eval_every = eval_every
  
      self.author2id = {}
      self.id2author = {}
  
      self.serialized = serialized
      if serialized and not serialization_path:
          raise ValueError(
              "If serialized corpora are used, a the path to a folder "
              "where the corpus should be saved must be provided (serialized_path)."
          )
      if serialized and serialization_path:
          assert not isfile(serialization_path), (
              "A file already exists at the serialization_path path; "
              "choose a different serialization_path, or delete the file."
          )
      self.serialization_path = serialization_path
  
      # Initialize an empty self.corpus.
      self.init_empty_corpus()
  
      self.alpha, self.optimize_alpha = self.init_dir_prior(
          alpha, "alpha"
      )
      assert self.alpha.shape == (
          self.num_topics,
      ), "Invalid alpha shape. Got shape %s, but expected (%d, )" % (
          str(self.alpha.shape),
          self.num_topics,
      )
  
      self.eta, self.optimize_eta = self.init_dir_prior(eta, "eta")
      assert self.eta.shape == (self.num_terms,) or self.eta.shape == (
          self.num_topics,
          self.num_terms,
      ), (
          "Invalid eta shape. Got shape %s, but expected (%d, 1) or (%d, %d)"
          % (
              str(self.eta.shape),
              self.num_terms,
              self.num_topics,
              self.num_terms,
          )
      )
  
      self.random_state = utils.get_random_state(random_state)
  
      # VB constants
      self.iterations = iterations
      self.gamma_threshold = gamma_threshold
  
      # Initialize the variational distributions q(beta|lambda) and q(theta|gamma)
      self.state = AuthorTopicState(
          self.eta,
          (self.num_topics, self.num_terms),
          (self.num_authors, self.num_topics),
      )
      self.state.sstats = self.random_state.gamma(
          100.0, 1.0 / 100.0, (self.num_topics, self.num_terms)
      )
      self.expElogbeta = np.exp(
          dirichlet_expectation(self.state.sstats)
      )
  
      # if a training corpus was provided, start estimating the model right away
      if corpus is not None and (
          author2doc is not None or doc2author is not None
      ):
          use_numpy = self.dispatcher is not None
          self.update(
              corpus, author2doc, doc2author, chunks_as_numpy=use_numpy
          )
  
imports: import logging
  from itertools import chain
  from copy import deepcopy
  from shutil import copyfile
  from os.path import isfile
  from os import remove
  import numpy
  from scipy.special import gammaln
  from gensim import utils
  from gensim.models import LdaModel
  from gensim.models.ldamodel import LdaState
  from gensim.matutils import dirichlet_expectation, mean_absolute_difference
  from gensim.corpora import MmCorpus
label_desc: Use image node_id 1 to create a new AuthorTopicModel object from inherited base classes: LdaModel with example: obj = AuthorTopicModel(corpus, num_topics, id2word, author2doc, doc2author, chunksize, passes, iterations, decay, offset, alpha, eta, update_every, eval_every, gamma_threshold, serialized, serialization_path, minimum_probability, random_state)