DeepLatent is a unified latent variable modeling framework for analyzing large multimodal and multilingual datasets. It relies on variational inference using deep neural networks for estimation.
The package currently supports:
- Generic latent factor models
- Topic models: The latent variables are a mixture of topics within documents.
- Ideal point models: The latent variables are interpreted as ideological dimensions.
-
Multilingual and multimodal support
- Learn topics / ideal points across multiple modalities (e.g., texts and images, texts and votes, etc.)
- Learn the weight of each modality in determining the latent variables per observation
-
Flexible metadata handling:
prevalence: covariates that influence the latent variablescontent: covariates that influence the response variables conditional on the latent variables (e.g., topic-word distributions)labels: outcomes for classification or regression tasksprediction: additional predictors for the labels
-
Flexible input/output representations:
- Document embeddings (for texts, images, audio-visual data)
- Word frequencies (BoW)
- Raw images
- Discrete choice data
- Voting records
- Learns topics on the simplex
- Supports
dirichletorlogistic_normalpriors (optionally conditioned on covariates)
- Learns unconstrained latent variables (ℝ️ⁿ) for ideal point modeling
- Designed for political texts, images, audio and video recordings, surveys, and votes
- Uses a
gaussianprior (optionally conditioned on covariates)
pip install deeplatentgit clone https://github.com/PinchOfData/DeepLatent.git
cd deeplatent
pip install -e .git clone https://github.com/PinchOfData/DeepLatent.git
cd deeplatent
python setup_dev.pySupports text, embeddings, votes, and survey questions:
import sys
sys.path.append('../src/')
from corpus import Corpus
modalities = {
"text": {
"column": "doc_clean",
"views": {
"bow": {
"type": "bow",
"vectorizer": CountVectorizer()
}
}
},
"image": {
"column": "image_path",
"views": {
"embedding": {
"type": "embedding",
"embed_fn": my_image_embedder
}
}
}
}
my_dataset = Corpus(df, modalities=modalities)Optionally include metadata:
prevalence,content,labels,prediction
from models import GTM
model = GTM(
n_topics=20,
doc_topic_prior="logistic_normal",
ae_type="wae"
)from models import IdealPointNN
model = IdealPointNN(
n_ideal_points=1, # one-dimensional ideal point model
ae_type="vae"
)| Argument | Description |
|---|---|
ae_type |
"wae" (Wasserstein autoencoder) or "vae" (variational autoencoder) or "ae" (plain autoencoder) |
fusion |
"poe" (Product of Experts), "moe_gating" (Mixture of Experts), or "moe_average" (Simple averaging across modalities) |
update_prior |
Learn a structured prior conditioned on prevalence covariates |
w_prior |
Strength of prior alignment for wae |
w_pred_loss |
Weight of supervised loss predicting label |
kl_annealing_* |
Strength of prior alignment for vae. Helps preventing posterior collapse. |
get_topic_words()– top words per topicget_covariate_words()– word shifts bycontentcovariatesget_top_docs()– representative documentsget_topic_word_distribution()– topic-word matrixget_covariate_word_distribution()– word shift matrixplot_topic_word_distribution()– word clouds / bar plotsvisualize_docs()– document embeddings (UMAP, t-SNE, PCA)visualize_words()– word embeddingsvisualize_topics()– topic embeddings
get_ideal_points()– ℝ️ⁿ latent spaceget_predictions()– supervised outputget_modality_weights()– fusion weights (PoE or gating)
Check out the example notebooks to get started.
Download sample data to run some notebooks: Congressional Speeches CSV
-
Deep Latent Variable Models for Unstructured Data , Germain Gauthier, Philine Widmer, Elliott Ash (2025)
-
The Neural Ideal Point Model , Germain Gauthier, Hugo Subtil, Philine Widmer (2025)
This package is under active development 🚧 — feedback and contributions welcome!