class_docstr: Online Latent Dirichlet Allocation with Infinite Vocabulary.
  
  Latent Dirichlet allocation (LDA) is a probabilistic approach for exploring topics in document
  collections. The key advantage of this variant is that it assumes an infinite vocabulary,
  meaning that the set of tokens does not have to known in advance, as opposed to the
  [implementation from sklearn](https://scikit-learn.org/stable/modules/generated/sklearn.decomposition.LatentDirichletAllocation.html)
  The results produced by this implementation are identical to those from [the original
  implementation](https://github.com/kzhai/PyInfVoc) proposed by the method's authors.
  
  This class takes as input token counts. Therefore, it requires you to tokenize beforehand. You
  can do so by using a `feature_extraction.BagOfWords` instance, as shown in the example below.
  
  Parameters
  ----------
  n_components
      Number of topics of the latent Drichlet allocation.
  number_of_documents
      Estimated number of documents.
  alpha_theta
      Hyper-parameter of the Dirichlet distribution of topics.
  alpha_beta
      Hyper-parameter of the Dirichlet process of distribution over words.
  tau
      Learning inertia to prevent premature convergence.
  kappa
      The learning rate kappa controls how quickly new parameters estimates replace the old ones.
      kappa ∈ (0.5, 1] is required for convergence.
  vocab_prune_interval
      Interval at which to refresh the words topics distribution.
  number_of_samples
      Number of iteration to computes documents topics distribution.
  ranking_smooth_factor
  burn_in_sweeps
      Number of iteration necessaries while analyzing a document before updating document topics
      distribution.
  maximum_size_vocabulary
      Maximum size of the stored vocabulary.
  seed
      Random number seed used for reproducibility.
  
  Attributes
  ----------
  counter : int
      The current number of observed documents.
  truncation_size_prime : int
      Number of distincts words stored in the vocabulary. Updated before processing a document.
  truncation_size : int
      Number of distincts words stored in the vocabulary. Updated after processing a document.
  word_to_index : dict
      Words as keys and indexes as values.
  index_to_word : dict
      Indexes as keys and words as values.
  nu_1 : dict
      Weights of the words. Component of the variational inference.
  nu_2 : dict
      Weights of the words. Component of the variational inference.
  
  Examples
  --------
  
  >>> from river import compose
  >>> from river import feature_extraction
  >>> from river import preprocessing
  
  >>> X = [
  ...    'weather cold',
  ...    'weather hot dry',
  ...    'weather cold rainy',
  ...    'weather hot',
  ...    'weather cold humid',
  ... ]
  
  >>> lda = compose.Pipeline(
  ...     feature_extraction.BagOfWords(),
  ...     preprocessing.LDA(
  ...         n_components=2,
  ...         number_of_documents=60,
  ...         seed=42
  ...     )
  ... )
  
  >>> for x in X:
  ...     lda.learn_one(x)
  ...     topics = lda.transform_one(x)
  ...     print(topics)
  {0: 0.5, 1: 2.5}
  {0: 2.499..., 1: 1.5}
  {0: 0.5, 1: 3.5}
  {0: 0.5, 1: 2.5}
  {0: 1.5, 1: 2.5}
  
  References
  ----------
  [^1]: [Zhai, K. and Boyd-Graber, J., 2013, February. Online latent Dirichlet allocation with infinite vocabulary. In International Conference on Machine Learning (pp. 561-569).](http://proceedings.mlr.press/v28/zhai13.pdf)
  [^2]: [PyInfVoc on GitHub](https://github.com/kzhai/PyInfVoc)
class_docstr_tok: ["Online","Latent","Dirichlet","Allocation","with","Infinite","Vocabulary",".","Latent","Dirichlet","allocation","(","LDA",")","is","a","probabilistic","approach","for","exploring","topics","in","document","collections",".","The","key","advantage","of","this","variant","is","that","it","assumes","an","infinite","vocabulary",",","meaning","that","the","set","of","tokens","does","not","have","to","known","in","advance",",","as","opposed","to","the","[","implementation","from","sklearn","]","(","https",":","\/\/scikit-learn.org\/stable\/modules\/generated\/sklearn.decomposition.LatentDirichletAllocation.html",")","The","results","produced","by","this","implementation","are","identical","to","those","from","[","the","original","implementation","]","(","https",":","\/\/github.com\/kzhai\/PyInfVoc",")","proposed","by","the","method","'s","authors",".","This","class","takes","as","input","token","counts",".","Therefore",",","it","requires","you","to","tokenize","beforehand",".","You","can","do","so","by","using","a","`","feature_extraction.BagOfWords","`","instance",",","as","shown","in","the","example","below",".","Parameters","--","--","--","--","--","n_components","Number","of","topics","of","the","latent","Drichlet","allocation",".","number_of_documents","Estimated","number","of","documents",".","alpha_theta","Hyper-parameter","of","the","Dirichlet","distribution","of","topics",".","alpha_beta","Hyper-parameter","of","the","Dirichlet","process","of","distribution","over","words",".","tau","Learning","inertia","to","prevent","premature","convergence",".","kappa","The","learning","rate","kappa","controls","how","quickly","new","parameters","estimates","replace","the","old","ones",".","kappa","\u2208","(","0.5",",","1","]","is","required","for","convergence",".","vocab_prune_interval","Interval","at","which","to","refresh","the","words","topics","distribution",".","number_of_samples","Number","of","iteration","to","computes","documents","topics","distribution",".","ranking_smooth_factor","burn_in_sweeps","Number","of","iteration","necessaries","while","analyzing","a","document","before","updating","document","topics","distribution",".","maximum_size_vocabulary","Maximum","size","of","the","stored","vocabulary",".","seed","Random","number","seed","used","for","reproducibility",".","Attributes","--","--","--","--","--","counter",":","int","The","current","number","of","observed","documents",".","truncation_size_prime",":","int","Number","of","distincts","words","stored","in","the","vocabulary",".","Updated","before","processing","a","document",".","truncation_size",":","int","Number","of","distincts","words","stored","in","the","vocabulary",".","Updated","after","processing","a","document",".","word_to_index",":","dict","Words","as","keys","and","indexes","as","values",".","index_to_word",":","dict","Indexes","as","keys","and","words","as","values",".","nu_1",":","dict","Weights","of","the","words",".","Component","of","the","variational","inference",".","nu_2",":","dict","Weights","of","the","words",".","Component","of","the","variational","inference",".","Examples","--","--","--","--",">",">",">","from","river","import","compose",">",">",">","from","river","import","feature_extraction",">",">",">","from","river","import","preprocessing",">",">",">","X","=","[","...","'weather","cold","'",",","...","'weather","hot","dry","'",",","...","'weather","cold","rainy","'",",","...","'weather","hot","'",",","...","'weather","cold","humid","'",",","...","]",">",">",">","lda","=","compose.Pipeline","(","...","feature_extraction.BagOfWords","(",")",",","...","preprocessing.LDA","(","...","n_components=2",",","...","number_of_documents=60",",","...","seed=42","...",")","...",")",">",">",">","for","x","in","X",":","...","lda.learn_one","(","x",")","...","topics","=","lda.transform_one","(","x",")","...","print","(","topics",")","{","0",":","0.5",",","1",":","2.5","}","{","0",":","2.499","...",",","1",":","1.5","}","{","0",":","0.5",",","1",":","3.5","}","{","0",":","0.5",",","1",":","2.5","}","{","0",":","1.5",",","1",":","2.5","}","References","--","--","--","--","--","[","^1","]",":","[","Zhai",",","K.","and","Boyd-Graber",",","J.",",","2013",",","February",".","Online","latent","Dirichlet","allocation","with","infinite","vocabulary",".","In","International","Conference","on","Machine","Learning","(","pp",".","561-569",")",".","]","(","http",":","\/\/proceedings.mlr.press\/v28\/zhai13.pdf",")","[","^2","]",":","[","PyInfVoc","on","GitHub","]","(","https",":","\/\/github.com\/kzhai\/PyInfVoc",")"]
docstr: Calculates the vocabulary weighting according to the word distribution present in the
  vocabulary.
  
  The Psi function is the logarithmic derivative of the gamma function.
  
  Parameters
  ----------
  n_components
      Number of topics.
  nu_1
      Weights of the words of the vocabulary.
  nu_2
      Weights of the words of the vocabulary.
  
  Returns
  -------
  Weights of the words of the current vocabulary.
docstr_tok: ["Calculates","the","vocabulary","weighting","according","to","the","word","distribution","present","in","the","vocabulary",".","The","Psi","function","is","the","logarithmic","derivative","of","the","gamma","function",".","Parameters","--","--","--","--","--","n_components","Number","of","topics",".","nu_1","Weights","of","the","words","of","the","vocabulary",".","nu_2","Weights","of","the","words","of","the","vocabulary",".","Returns","--","--","--","-","Weights","of","the","words","of","the","current","vocabulary","."]
code: def _compute_weights(
      cls, n_components: int, nu_1: dict, nu_2: dict
  ) -> tuple[dict, dict]:
      """Calculates the vocabulary weighting according to the word distribution present in the
      vocabulary.
  
      The Psi function is the logarithmic derivative of the gamma function.
  
      Parameters
      ----------
      n_components
          Number of topics.
      nu_1
          Weights of the words of the vocabulary.
      nu_2
          Weights of the words of the vocabulary.
  
      Returns
      -------
      Weights of the words of the current vocabulary.
  
      """
      exp_weights = {}
      exp_oov_weights = {}
  
      for topic in range(n_components):
          psi_nu_1 = special.psi(nu_1[topic])
          psi_nu_2 = special.psi(nu_2[topic])
  
          psi_nu_1_nu_2 = special.psi(nu_1[topic] + nu_2[topic])
  
          psi_nu_1_nu_2_minus_psi_nu_2 = np.cumsum(
              [psi_nu_2 - psi_nu_1_nu_2], axis=1
          )
  
          exp_oov_weights[topic] = np.exp(
              psi_nu_1_nu_2_minus_psi_nu_2[0][-1]
          )
  
          psi_nu_1_nu_2_minus_psi_nu_2 = ndimage.shift(
              input=psi_nu_1_nu_2_minus_psi_nu_2[0], shift=1, cval=0
          )
  
          exp_weights[topic] = np.exp(
              psi_nu_1 - psi_nu_1_nu_2 + psi_nu_1_nu_2_minus_psi_nu_2
          )
  
      return exp_weights, exp_oov_weights
  
file_path: river/river/preprocessing/lda.py
imports: from __future__ import annotations
  import functools
  import typing
  from collections import defaultdict
  import numpy
  from scipy import ndimage, special
  from river import base
label_desc: Use image node_id 6 for calling the LDA obj's underlying member method code with example usage: obj._compute_weights(cls, n_components, nu_1, nu_2) and returns: exp_weights,  exp_oov_weights