- class scvi.module.AmortizedLDAPyroModule(n_input, n_topics, n_hidden, cell_topic_prior=None, topic_feature_prior=None)#
An amortized implementation of Latent Dirichlet Allocation [Blei03] implemented in Pyro.
This module uses auto encoding variational Bayes to optimize the latent variables in the model. In particular, a fully-connected neural network is used as an encoder, which takes in feature counts as input and outputs the parameters of cell topic distribution. To employ the reparametrization trick stably, the Dirichlet priors are approximated by a Logistic-Normal distribution. The input feature counts tensor is a cell by features Bag-of-Words(BoW) representation of the counts. I.e. the model treats each cell’s feature vector as ordered, not as unordered as in a Multinomial distribution.
- n_input :
Number of input features.
- n_topics :
Number of topics/topics to model.
- n_hidden :
Number of nodes in the hidden layer of the encoder.
- cell_topic_prior :
Prior of cell topic distribution. If None, defaults to 1 / n_topics.
- topic_feature_prior :
Prior of topic feature distribution. If None, defaults to 1 / n_topics.
- n_input :
- AmortizedLDAPyroModule.dump_patches: bool = False#
This allows better BC support for
state_dict(), the version number will be saved as in the attribute _metadata of the returned state dict, and thus pickled. _metadata is a dictionary with keys that follow the naming convention of state dict. See
_load_from_state_dicton how to use this information in loading.
If new parameters/buffers are added/removed from a module, this number shall be bumped, and the module’s _load_from_state_dict method can compare the version number and do appropriate changes if the state dict is from before the change.
Model annotation for minibatch training with pyro plate.
A dictionary with: 1. “name” - the name of observation/minibatch plate; 2. “in” - indexes of model args to provide to encoder network when using amortised inference; 3. “sites” - dictionary with
- keys - names of variables that belong to the observation plate (used to recognise
and merge posterior samples for minibatch variables)
- values - the dimensions in non-plate axis of each variable (used to construct output
layer of encoder network when using amortised inference)
- AmortizedLDAPyroModule.get_topic_distribution(x, n_samples)#
Converts x to its inferred topic distribution.
Gets a Monte-Carlo estimate of the expectation of the topic by feature matrix.
Assumes the module has already been trained.