In collapsed Gibbs sampling for LDA, the topic zi of a word is resampled from p(zi=k∣z−i,w)∝(ndk−i+α) nkw−i+βnk−i+Vβ. Where does each factor come from? What is its value for K=2, V=3, α=0.1, β=0.5, with nd⋅−i=(3,1), n⋅w−i=(4,0) and n⋅−i=(10,6)?

Probabilistic models, Topic models (LDA)
Level L3 Intermediate. Length Long. Nature Th+Mat Both.

What's being asked

Whether you understand the Dirichlet–multinomial predictive that gives the collapsed conditional, and can evaluate it.

Key idea

With θ and ϕ integrated out, a Dirichlet prior acts as pseudo-counts: p(new count∣old counts)=(count+prior)/(total+prior total). The conditional is the product of a document factor and a topic–word factor.

Steps

  1. The joint after integrating out θd and ϕk is a product of Dirichlet–multinomial terms. The conditional for one token comes from the ratio of this joint with and without that token.
  2. Document factor: (ndk−i+α) is proportional to the chance that the topic is k given the other topics in the document d. The −i means we leave out the current token.
  3. Topic–word factor: (nkw−i+β)/(nk−i+Vβ) is the chance that topic k emits word w. The denominator adds Vβ because there are V words, each with a pseudo-count β.
  4. Numbers for topic 1: (3+0.1)⋅4+0.510+1.5=3.1⋅0.3913=1.213.
  5. Numbers for topic 2: (1+0.1)⋅0+0.56+1.5=1.1⋅0.0667=0.0733.
  6. Normalise: p(zi=1)=1.213/(1.213+0.0733)=0.943 and p(zi=2)=0.057. Topic 1 wins because the document is mostly topic 1 and topic 1 has used this word often.
  7. Sampling uses these probabilities, then increments the counts. Averaging θ^dk=(ndk+α)/(nd+Kα) and ϕ^kw=(nkw+β)/(nk+Vβ) over later sweeps gives estimates.

Common mistakes

How long your answer should be

A page. About 7 minutes.

Last checked on 4 December 2026.

Read this

Previous in Probabilistic models: For a bivariate Gaussian with zero means, unit variances and correlation ρ, derive the Gibbs conditionals. Show that the sequence of x1 values from a Gibbs sampler is an AR(1) process with coefficient ρ2. How many Gibbs steps per effectively independent sample are needed for ρ=0.9?
Next in Probabilistic models: The data are x1,…,xn∼N(μ,σ2) with known σ2=1, and the prior is μ∼N(0, 4). For n=4 and sample mean xˉ=2, what is the posterior of μ and what is the predictive distribution of a new observation? How do you show that the posterior mean is a precision-weighted average?