Latent Dirichlet Allocation (LDA)

Machine Learning
Introduced by
Blei, D. M.; Ng, A. Y.; Jordan, M. I.
Year
2003
Type
Generative probabilistic topic model (three-level hierarchical Bayesian)

What does it do?

Latent Dirichlet Allocation (LDA) is a generative probabilistic model for collections of discrete data, introduced by Blei, Ng, and Jordan in 2003.

It represents each document as a mixture of latent topics and each topic as a probability distribution over words, so thematic structure can be discovered from raw text without labels. It is most often applied to text corpora.

The intuition behind the method

Imagine reading thousands of academic papers. You notice some discuss 'genes' and 'proteins', others focus on 'elections' and 'policy', and still others blend several themes. LDA formalises this intuition: every document is a mixture of topics (say 60% biology, 40% ethics), and every topic is characterised by a probability distribution over words ('gene' and 'DNA' rank highly in a biology topic). LDA learns both mixtures simultaneously from the raw text, without any labelling, by asking: what hidden topic structure would make the observed word counts most probable?

History

LDA was introduced by David Blei, Andrew Ng, and Michael Jordan in 2003 in the Journal of Machine Learning Research. It builds on the probabilistic latent semantic indexing (pLSI) model, which Blei et al. (2003) use as a comparison, by placing Dirichlet priors on the topic and word distributions. This makes it a fully generative Bayesian model that can assign topic proportions to documents not seen during training. Later work has produced many extensions that add structure to the original priors. Blei's 2012 survey in Communications of the ACM gives an overview of the wider family of probabilistic topic models. Neural topic models have since been proposed as alternatives, while LDA remains a common baseline.

When to use it

Choose LDA when the goal is unsupervised discovery of thematic structure in a collection of text documents, and when it is plausible that each document mixes several topics. It suits corpus summarisation, exploratory analysis of literature or open-ended responses, and producing document-topic features for later supervised tasks. Do not use it when labelled categories already exist and the aim is prediction, since a supervised classifier is then more direct; when the collection is too small for stable topic estimates; or when word order and syntax matter to the question. The model assumes a bag-of-words representation, exchangeability of words within documents and of documents within the corpus, and a fixed number of topics K chosen by the analyst. Very short texts give few tokens per document, so their topic proportions are poorly determined. No validated minimum corpus size exists. Judge whether the collection is large enough by checking that the topics are stable across random seeds and data subsets before relying on the model.

Limitations and considerations

  • K must be fixed in advance; choosing it requires fitting several models and comparing coherence or held-out perplexity.
  • The bag-of-words assumption discards word order and syntax, so phrases, negation and local context are not represented.
  • Topics can be hard to interpret when texts are short or noisy, because word co-occurrence within documents is weak.
  • Variational EM depends on initialisation and can converge to a local optimum, so different runs may produce different topics.
  • Collapsed Gibbs sampling resamples a topic for every token on each sweep, so runtime grows with corpus length and with the number of topics.

Source conditions do not replace independent scientific review or validation by an analysis engine.

Strengths

  • Generative probabilistic model: it defines an explicit account of how documents are produced, so topic assignments and proportions carry posterior uncertainty rather than being reported as point labels.
  • Blei et al. (2003) give efficient approximate inference based on variational methods and an EM algorithm for parameter estimation. Scaling to very large corpora generally requires online or stochastic variants, which are not part of the original method. Collapsed Gibbs sampling offers an alternative route to inference for the same model.
  • Each topic is represented as a ranked list of words, which can be read and checked directly.
  • Document-topic proportions give a compact, dense vector per document that can feed downstream classification or retrieval.
  • Extensible: the basic structure has been adapted into many variants that modify or add structure to the original priors.

Applications

  • Discovering research themes and tracking their evolution in scientific literature.
  • Segmenting news corpora, social media streams, or parliamentary debates by topic.
  • Generating compact document representations for information retrieval and recommendation systems.
  • Exploratory analysis of qualitative interview data or open-ended survey responses.
  • Feature engineering: document-topic vectors as inputs to supervised classifiers.
  • Computational social science: studying agenda setting, framing, and public discourse over time.

How it works

How it works

1

Two Dirichlet distributions serve as priors. The first, parameterised by α, generates a per-document topic proportion vector θ_d — a point on the simplex over K topics. The second, parameterised by β, generates a per-topic word distribution φ_k — a point on the simplex over the vocabulary. Symmetric, low values of α encourage sparse topic mixtures per document; low β encourages each topic to concentrate on a small word set.

Formula
\theta_d \sim \mathrm{Dir}(\alpha), \quad \phi_k \sim \mathrm{Dir}(\beta)
2

For each word position (d, n) in document d, a topic label z_{d,n} is drawn from the categorical distribution defined by that document's topic proportions θ_d. This latent variable is unobserved and must be inferred.

Formula
z_{d,n} \sim \mathrm{Categorical}(\theta_d)
3

Given the topic label z_{d,n}, the observed word w_{d,n} is drawn from the corresponding topic's word distribution φ_{z_{d,n}}. This two-step generative story — choose a topic, then choose a word from that topic — connects the latent structure to the observable text.

Formula
w_{d,n} \sim \mathrm{Categorical}(\phi_{z_{d,n}})
4

The joint probability of the words, topic assignments, document-topic proportions and topic-word distributions factorises over documents and word positions, as in the formula. Because Dirichlet priors are conjugate to categorical distributions, θ and Φ can be integrated out analytically; this conjugacy is what makes the collapsed Gibbs sampler described below possible.

Formula
p(\mathbf{w}, \mathbf{z}, \theta, \Phi \mid \alpha, \beta) = \prod_{d=1}^{D} p(\theta_d \mid \alpha) \prod_{n=1}^{N_d} p(z_{d,n} \mid \theta_d)\, p(w_{d,n} \mid \phi_{z_{d,n}}) \cdot \prod_{k=1}^{K} p(\phi_k \mid \beta)
5

Exact posterior inference over θ and z is intractable because these latent variables are coupled. Blei et al. (2003) approximate it with a mean-field variational distribution q(θ, z; γ, φ) and an EM-style procedure that maximises the evidence lower bound (ELBO) with respect to the variational parameters γ and φ and the model parameters α and β. Collapsed Gibbs sampling is a widely used alternative: it integrates out θ and Φ and samples topic assignments directly.

Formula
\mathcal{L}(\gamma, \varphi; \alpha, \beta) = E_q[\log p(\theta, \mathbf{z}, \mathbf{w} \mid \alpha, \beta)] - E_q[\log q(\theta, \mathbf{z})]

Common pitfalls

  • Failing to preprocess text adequately — not removing stop words, not lemmatising, or not filtering very rare and very frequent terms — produces incoherent topics dominated by function words.
  • Choosing K by inspecting a single run rather than comparing coherence or perplexity across several K values.
  • Treating topic labels as stable without checking reproducibility across random seeds or data subsets, since topics can change between runs.
  • Keeping the default symmetric α and β without examining their effect: α governs how many topics each document mixes and β how concentrated each topic is on words, so these settings shape the topic structure and should be checked rather than assumed. Blei et al. (2003) estimate these priors from data with an empirical Bayes EM procedure, but commonly used default values are conventions rather than validated optima. Test a small grid of values, for example on a log scale, and compare coherence, held-out perplexity and topic stability across settings before choosing one.
  • Expecting reliable per-document proportions from short documents: with few tokens, θ_d is estimated from little evidence and should be interpreted cautiously.

Frequently asked questions

How do I choose the number of topics K?

There is no single correct answer. A common practice is to fit models across a range of K values and compare topic coherence (for example the C_v coherence score) and held-out perplexity, together with qualitative inspection of the top words per topic. The range of K and the selection rule depend on the corpus and should be justified by the analysis rather than fixed in advance.

What is the difference between LDA and probabilistic latent semantic indexing (pLSI)?

The pLSI model, which Blei et al. (2003) use as a comparison, is closely related but treats document-topic proportions as fixed parameters rather than random variables. LDA places Dirichlet priors on those proportions, making it a fully Bayesian generative model. As a result, LDA can assign topic proportions to documents not seen during training through predictive inference, whereas pLSI has no comparable prior-based mechanism for new documents without further estimation.

Does LDA work on languages other than English?

Yes. LDA is language-agnostic: it treats text as sequences of tokens and learns co-occurrence patterns in the vocabulary. The key preprocessing steps — tokenisation, stop-word removal, and stemming or lemmatisation — must be adapted for the target language, but the model itself is unchanged.

How should I evaluate whether my topics are good?

Evaluation combines quantitative and qualitative methods. Coherence measures such as C_v or UMass are commonly used as proxies for topic quality, and held-out perplexity measures predictive fit; perplexity does not always track human judgements of topic quality, so both should be read together. Qualitatively, inspect the top 10–20 words per topic, read representative documents assigned high probability to each topic, and confirm that topics are distinctive and non-redundant. Topics with many overlapping high-probability words across different topics indicate K may be too large.

Related methods

Sources

  1. Blei, D. M., Ng, A. Y., & Jordan, M. I. (2003). Latent Dirichlet allocation. Journal of Machine Learning Research, 3, 993–1022.

    Open DOI reference
  2. Blei, D. M. (2012). Probabilistic topic models. Communications of the ACM, 55(4), 77–84.

    Open DOI reference
  3. Bishop, C. M. (2006). Pattern Recognition and Machine Learning (Ch. 9). Springer.

    ISBN: 978-0-387-31073-2