Latent Dirichlet allocation (often called the LDA topic model) is a generative probabilistic model that represents each document in a collection as a mixture of latent topics, where each topic is a probability distribution over the vocabulary. Introduced by David Blei, Andrew Ng and Michael Jordan in 2003, it is one of the best-known probabilistic models for unsupervised text analysis and a standard example of a hierarchical Bayesian latent variable model.
LDA does not need labeled data. Given only word counts, it infers which themes exist in a corpus and how strongly each document expresses each theme. Its name reflects its structure: the topic assignments are latent (hidden), and the per-document and per-topic proportions are drawn from Dirichlet prior distributions. It should not be confused with linear discriminant analysis, a supervised classification method that shares the same abbreviation.
The generative process behind LDA
LDA assumes that every document was produced by a simple random generative story. The model fixes a number of topics K in advance. Each topic k receives a word distribution drawn from a Dirichlet prior with parameter beta, and each document d receives a topic proportion vector theta drawn from a Dirichlet prior with parameter alpha.
- For each topic, draw a word distribution phi from Dirichlet(beta).
- For each document, draw topic proportions theta from Dirichlet(alpha).
- For each word position, draw a topic assignment z from the document’s theta.
- Draw the observed word from the word distribution of topic z.
Learning reverses this story. Posterior inference asks which topics, proportions and assignments most plausibly generated the observed words. Because the model treats documents as bags of words, word order is ignored; only counts matter. The Dirichlet distribution is the conjugate prior of the multinomial, which makes the mathematics of inference considerably more tractable.
Key parameters and their effects
The behavior of LDA depends mostly on three hyperparameters: the number of topics and the two Dirichlet concentration parameters. Values below 1 favor sparse distributions, in which each document uses few topics and each topic concentrates on few words.
| Parameter | Meaning | Typical range | Effect of increasing it |
|---|---|---|---|
| K (topics) | Number of latent topics | 10 to 500 | Finer, more specific topics |
| Alpha | Document-topic concentration | 0.01 to 1 | Documents mix more topics |
| Beta (eta) | Topic-word concentration | 0.001 to 0.1 | Topics spread over more words |
| Iterations or passes | Amount of inference work | Hundreds to thousands | Better convergence, higher cost |
There is no universally correct K. Practitioners compare candidate values using held-out perplexity, topic coherence scores such as UMass or NPMI, and human inspection. Perplexity and human judgment often disagree: models with lower perplexity can produce topics that people find less interpretable, which is a well-documented finding in topic-modeling research.
Inference methods for LDA
Exact posterior inference in LDA is computationally intractable, so approximate methods are required. The two dominant families are Markov chain Monte Carlo sampling and variational inference, each with distinct trade-offs in accuracy, speed and scalability.
| Method | Principle | Strength | Limitation |
|---|---|---|---|
| Collapsed Gibbs sampling | Samples topic assignments with theta and phi integrated out | Simple and accurate | Slow on very large corpora |
| Mean-field variational Bayes | Optimizes a factorized approximation of the posterior | Deterministic and fast | Underestimates uncertainty |
| Online variational Bayes | Updates topics on mini-batches | Scales to streaming data | Sensitive to learning rate |
| Sparse or distributed samplers | Exploit sparsity across many machines | Handle billions of tokens | Complex implementation |
Variational methods maximize the evidence lower bound, while collapsed Gibbs sampling relies on the conjugacy between Dirichlet and multinomial distributions. Stochastic variational inference made LDA practical for corpora of millions of documents, and it is the approach behind many widely used library implementations.
LDA compared with related models
LDA sits between simple clustering and modern neural representations. Unlike a mixture model, which assigns each document to a single cluster, LDA gives every document a mixed membership across topics. Its predecessor, probabilistic latent semantic analysis, lacked a prior on document proportions and therefore could not generalize cleanly to new documents.
| Approach | Document representation | Key difference from LDA |
|---|---|---|
| Mixture of unigrams | One topic per document | No mixed membership |
| pLSA | Topic mixture without prior | Overfits and lacks a generative story for new documents |
| LDA | Dirichlet-distributed topic mixture | Reference model |
| Hierarchical Dirichlet process | Topic mixture with unbounded K | Learns the number of topics |
| Neural topic models | Encoder-inferred topic vectors | Amortized inference, richer features |
The hierarchical Dirichlet process extends LDA with Bayesian nonparametrics, so the number of topics grows with the data. Embedding-based methods often yield more coherent clusters on short texts, but LDA remains valued for its transparent probabilistic semantics and modest computing requirements.
Practical use, limitations and common mistakes
LDA is used for exploratory corpus analysis, document recommendation, feature extraction for classifiers and the study of how themes evolve over time. Success depends heavily on preprocessing: removing stop words, filtering very rare and very frequent terms, and lemmatizing tokens usually matter more than fine-tuning hyperparameters.
- Short texts such as tweets give too few words per document for stable topic proportions.
- Random initialization means different runs can produce different topics, so stability should be checked.
- Topics are word lists, not labels; naming them requires human interpretation and can introduce bias.
- The bag-of-words assumption ignores syntax, negation and word order entirely.
A frequent mistake is to treat inferred topics as objective ground truth. They are statistical regularities conditioned on the chosen K, priors and vocabulary, and should be validated with coherence metrics and domain experts before supporting decisions.
Put simply
Latent Dirichlet allocation is a way for a computer to find hidden themes in a large pile of documents. Nobody tells it what the themes are. It looks at which words tend to appear together and groups them.
Imagine sorting a box of newspaper clippings. One article might be mostly about sport and a little about money. Another might mix politics and health. LDA works the same way. It describes each document as a blend of themes, and each theme as a list of typical words. People still need to read the word lists and decide what each theme means.
In practice
A public health research team collects about 120,000 anonymized patient feedback comments from hospital surveys over five years. Reading them manually is impossible, and the team has no predefined categories, so it chooses LDA for unsupervised exploration.
After removing stop words and terms that appear in fewer than 10 comments, the team trains models with K between 20 and 60 using online variational inference. Coherence scores and expert review favor K = 35, with alpha set to 0.1 to keep each comment focused on a few themes. Topics emerge around waiting times, staff courtesy, parking, discharge instructions and food quality.
Tracking topic proportions by year shows that the share of comments about discharge instructions doubled after a change in the discharge process. Hospital management uses this finding to revise its written guidance, and the next survey cycle shows the topic share returning to its earlier level.