Topic models (LDA)
Latent Dirichlet Allocation is a hierarchical latent-variable model fit with collapsed Gibbs sampling or variational EM. Every document is a mixture over latent topics.
Name things for the reader, not the writer.
Name things for the reader, not the writer.
Gaussian Mixture Models
The cleanest way to derive GMMs and EM is via latent variables. Introduce a categorical latent z_n in \{1, ldots, K\} for each data point, with prior p(z_n = k) = pi_k. Conditional on z_n = k, the observation is Gaussian: p(mathbf{x}_n mid z_n = k) = mathcal{N}(mathbf{x}_n; boldsymbolmu_k, Sigma_k).
GMMs are latent-variable models: a hidden cluster indicator chooses which Gaussian generates each point.
No latent-variable view → no VAEs, no diffusion models with implicit latent paths, no amortized inference.
The cleanest way to derive GMMs and EM is via latent variables. Introduce a categorical latent for each data point, with prior . Conditional on , the observation is Gaussian: . Marginalizing out recovers the mixture density .
The responsibility from the E-step is precisely the posterior of the latent: This is Bayes' rule for the hidden cluster indicator. The EM algorithm now has a clean interpretation: compute the posterior over hidden variables (E), then maximize the expected complete-data log-likelihood (M).
The complete-data log-likelihood is . Taking expectations with respect to the responsibilities replaces the indicators with , producing a sum of weighted log-Gaussians — decoupled and easy to maximize. This decoupling is why M-step closed-forms exist: conditional on knowing the soft assignments, the problem factorizes.
Once trained, responsibilities reveal soft cluster membership. A point near a cluster center has for that ; a point equidistant from two clusters splits mass. This is richer than -means' hard assignment — the model knows when it is uncertain. We can use responsibilities to detect outliers (points with low responsibility for every cluster have low ) or to visualize uncertainty in cluster boundaries.
This latent-variable framework generalizes far beyond GMMs. Hidden Markov Models use a sequence of latent states. Factor Analysis and Probabilistic PCA have continuous latents. Variational Autoencoders learn deep latent representations with neural-network likelihoods. Latent Dirichlet Allocation assigns topics to documents. Every time you see EM, variational inference, or sampling — there is a latent variable structure underneath, and the GMM is the canonical worked example.
Worked example — unequal priors reshape responsibility: Same two components and but now (cluster 1 is much more common). For we previously got . Now the joint numerators are and . Ratio: , so and . The strong prior flipped the assignment — Bayes' rule in action.
Python (in browser)
Expected: Each row sums to 1; component allegiance depends on x
Python runs entirely in your browser via Pyodide (~6 MB on first Run, cached after).
Worked example — complete-data vs observed-data log-likelihood: Suppose one point is assigned responsibility under two components with equal priors. Observed log-likelihood: (plus a constant). Expected complete-data log-likelihood: , cleanly decoupled across clusters — M-step can maximize each component independently.
Latent Dirichlet Allocation is a hierarchical latent-variable model fit with collapsed Gibbs sampling or variational EM. Every document is a mixture over latent topics.
Latent state sequence + emission distribution. Trained with Baum-Welch (an EM variant). Powered speech recognition pre-deep-learning.
Continuous latent , neural encoder , neural decoder . Maximizes the ELBO end-to-end with the reparameterization trick.
Put your understanding to the test. Score + streak + speed all count.
3 quick questions. Get 2 right to mark this lesson complete.