Explain Latent Dirichlet Allocation as a generative model: what do the document-topic and topic-word distributions look like, and how do you choose the number of topics?

The Problem: A support team fit LDA to 40,000 tickets with an 8,000-term vocabulary at , 40 and 150, and held-out perplexity kept falling from 1,420 to 1,050 while the 150-topic run began splitting refunds into near-duplicate topics. They need to know what the per-ticket and per-topic distributions should look like and which K to ship.
Answer
Latent Dirichlet Allocation (LDA) treats every document as a bag of words generated by a mixture of K topics, where each topic is a probability distribution over the whole vocabulary. To write document , the model draws topic proportions
, then for each word slot picks a topic
from
and a word from that topic’s distribution
. The document-topic vectors are points on the
-simplex, and with
below 1 they are sparse, so a typical document uses 2 to 4 topics. The topic-word vectors
are long-tailed distributions over all
words, where a few dozen words carry most of the mass. The number of topics is a hyperparameter the model does not learn. You sweep it and pick the value where topic coherence peaks and topics stay distinct, because held-out perplexity usually keeps improving long after topics stop being interpretable.
(1) Generative Story: Each topic draws a word distribution once for the whole corpus. Each document draws
, and each word slot draws a topic
from
and then the word from
.
(2) Plate Notation: A K plate repeats , a D plate repeats
, and an
word plate nested inside it repeats
and
. The word is the only observed node, so inference means running this story backwards to recover
,
and
.
(3) Document-Topic Distribution: lives on the
-simplex with prior mean
. With
below 1 it is sparse, so a real document loads on a handful of topics rather than spreading across all K.
(4) Topic-Word Distribution: gives every vocabulary word nonzero probability but is heavily skewed, and a small
sharpens the head. Its top words name the topic, and one word can rank high in several topics, which is how LDA handles polysemy.
(5) Admixture, Not Clustering: Topics are assigned per word, so documents mix topics. Shrinking toward 0 pushes LDA toward a one-topic-per-document mixture of unigrams, whose hard-assignment fit is k-means with KL divergence.
(6) Choosing K: Sweep K over several seeds and pick the peak of coherence (UMass, NPMI, ), backed by topic diversity and a human read of the top words. Held-out perplexity usually keeps falling and is a poor guide to interpretability.
Mathematical Formulation:
Where:
is the topic mixture of document
, and
is its concentration, either a symmetric scalar or a vector
.
is the word distribution of topic
,
is the vocabulary size,
is the topic-word concentration, and
stacks the
into a
matrix.
is the latent topic of word slot
,
is the observed word, and
is a categorical draw.
- The marginal word probability is a convex combination of topic rows, so the
matrix of word probabilities factorizes as
with rank at most
.
- In the collapsed Gibbs update,
and
are integrated out:
counts tokens of document
assigned to topic
,
counts corpus-wide assignments of word
to
, and
is all tokens in
, each excluding the token being resampled.
is held-out perplexity, where
is the marginal likelihood of an unseen document and
its length; lower is better, and the marginal must be estimated (importance sampling, left-to-right, or document completion).
scores one topic from its top-
words
ranked by
.
counts documents containing
,
counts documents containing both, the
avoids
, and scores closer to 0 mean more co-occurring top words.
What the two distributions look like is set by the concentration parameters and the data together. A symmetric Dirichlet with is uniform over the simplex, values below 1 push draws toward corners and edges, and values above 1 pull draws toward the even mixture
. The posterior mean
shows the prior acting as
pseudo-tokens. At
,
adds 4 pseudo-tokens to a 120-token ticket, while the older heuristic
adds 50 and visibly flattens every ticket’s mixture. On the word side,
over
words makes each
Zipf-like, which is why a topic is read and named from its top 10 to 20 words. Learning an asymmetric
helps in practice, because a few broad topics can then absorb greetings and sign-offs that would otherwise leak into every specific topic.

Figure 1: (a) Plate notation, with as the only observed node and
shared by every document. (b) One ticket’s
under
, where 3 of 40 topics hold 95% of the mass. (c) The billing topic’s
, whose top 12 words carry 0.395 while the other 7,988 words share a long tail of 0.605.
Choosing K is a model-selection problem that the likelihood answers badly. Held-out perplexity almost always keeps improving as K grows, because extra topics give the model more parameters to soak up residual co-occurrence. Human word-intrusion studies found that better perplexity often comes with less interpretable topics. Practitioners therefore sweep K on a grid such as 10, 20, 40, 80 and 150 with several seeds and score each run with topic coherence. UMass uses document co-occurrence in the training corpus, while NPMI and use sliding windows over a reference corpus and track human ratings more closely. Pair coherence with topic diversity (the share of unique words among all topics’ top 25) and seed stability, read the topics at the two or three best values, and let downstream accuracy break ties. The hierarchical Dirichlet process (HDP) infers the number of topics instead, though it moves the choice into its own concentration parameters.
Worked Example:
Score two candidate topics with UMass coherence on a 1,000-ticket reference sample, using each topic’s top three words in rank order and natural logs. Topic A is {refund, charge, card} with ,
, and co-document counts of 90 for charge with refund, 60 for card with refund, and 80 for card with charge. Its score is
. Topic B is {refund, password, shipping} with
and co-document counts of 4, 10 and 2. Its score is
. Topic A’s words genuinely appear together, Topic B is a mixed topic, and the average of this score over all K topics is what a K sweep compares.
The cleanest way to see what LDA adds is to compare it with clustering. A mixture of unigrams draws one topic per document and generates every word from it. Fitting it with hard assignments is k-means on word-count vectors with KL divergence in place of squared Euclidean distance, the same way a Gaussian mixture collapses to k-means as its variances shrink. LDA relaxes the one-topic constraint to a per-word assignment, so a ticket about a double charge after a password reset can be 60% billing and 30% login. In matrix terms LDA is a Bayesian, non-negative factorization of document-word probabilities into times
. pLSA is the same factorization without the Dirichlet priors, which is why it overfits and cannot score a new document without refitting.
| Property | LDA | Mixture of unigrams | k-means on word counts |
|---|---|---|---|
| Topics per document | A mixture over all K topics | Exactly one | Exactly one cluster |
| What gets assigned | Every word token gets its own topic | The whole document | The whole count vector |
| Document representation | Topic proportions on the simplex | Posterior over K topics | Nearest centroid index |
| Priors | Dirichlet on document mixtures and topic-word rows | Optional Dirichlet on mixing weights | None |
| Fit by | Collapsed Gibbs or variational Bayes | EM | Lloyd iterations |
| New document | Fold in its mixture with topics held fixed | Bayes rule over K topics | Assign the nearest centroid |
| Limit relation | Approaches the mixture of unigrams as alpha shrinks toward 0 | Hard-assignment EM becomes k-means with KL divergence | Euclidean special case of hard clustering |
Leave a Reply