← chapter

Topic models

You have a pile of documents and no labels. EM discovers the themes — which words hang together, which document is about what — without ever being told.

A mixture of multinomials fit by the same E-step/M-step engine as Gaussian mixtures. This is pLSA, the ancestor of LDA.

The generative story

We see only the word counts. We know neither the topics nor which one wrote each document. So we alternate.

The math

Generative story for document ii with word counts xix_i:

p(xiθ)=k=1Kπkw=1Vϕkwxiwp(x_i \mid \theta) = \sum_{k=1}^{K} \pi_k \prod_{w=1}^{V} \phi_{kw}^{\,x_{iw}}

E-step — posterior that topic kk wrote document ii:

Wik=πkwϕkwxiwjπjwϕjwxiwW_{ik} = \frac{\pi_k \prod_w \phi_{kw}^{\,x_{iw}}}{\sum_j \pi_j \prod_w \phi_{jw}^{\,x_{iw}}}

M-step — responsibility-weighted word counts, normalized per topic:

ϕkw=iWikxiwiWikwxiw\phi_{kw} = \frac{\sum_i W_{ik}\, x_{iw}}{\sum_i W_{ik} \sum_{w'} x_{iw'}}

Watch the topics emerge from noise

Three panels, one per topic. Every panel starts flat — all words at the chance rate — and sharpens onto its own five planted words. Bar color = the topic that truly planted each word.

The guarantee holds here too

Same monotone climb as every EM. The data log-likelihood rises from −16,365 at the random start to −11,648 at convergence, and never drops.

Scratch vs. library

Takeaways