TL;DR
Standard variational inference approximates a hard posterior distribution by solving an optimization problem, but each update has to look at every data point in the set. Hoffman, Blei, Wang and Paisley showed how to replace that full pass with a stream of cheap updates. Each step samples one document, computes a local guess about it, and blends that guess into the global answer with a shrinking step size. The method fits Bayesian topic models to collections of 1.8 million New York Times articles and 3.8 million Wikipedia articles. The full-pass method was run only on subsets of these collections, and did worse.
Builds on: Variational Lower Bound (ELBO), Mean-Field Approximation, Natural Gradient Descent, Stochastic Gradient Descent, Posterior Distribution · Leads to: scalable Bayesian inference for large models with hidden structure
Why it mattered
The paper made large-scale Bayesian modelling practical for text. Topic models built on it can organize large archives without labels: the authors ran the method on 350,000 articles from the journal Nature, 1.8 million New York Times articles and 3.8 million Wikipedia articles, and reported that the older full-pass variational method, run on subsets of each collection, predicted held-out text less well. The same recipe (take a noisy natural gradient from a random subset, then step with a decreasing size) is the basis of many later ways to scale variational methods to data that does not fit in memory.
History
Variational methods for probabilistic models were pioneered in the mid-1990s and developed through the 2000s, in work surveyed by Jordan and colleagues (1999) and by Wainwright and Jordan (2008). These methods needed a full pass over the data for each coordinate update, so they were slow on large collections.
The stochastic optimization ideas came from much earlier work. Robbins and Monro showed in 1951 that noisy gradient steps with shrinking sizes converge under mild conditions. Applying that idea to the natural gradient of the variational objective was the step the paper took. Its arXiv version appeared in 2012, and the paper was published in the Journal of Machine Learning Research in 2013. It caught on because it reused the existing coordinate updates almost unchanged, so any implementation of classical variational inference could be adapted to it.
The problem
A Bayesian model has hidden variables, things we cannot see such as the topics in a collection or the cluster of each item. Given the observed data, we want the posterior distribution over those hidden variables. For most realistic models the exact posterior has an integral with no closed form, so we need an approximation.
Variational inference (see Variational Lower Bound (ELBO)) turns the approximation into optimization. We choose a family of simple distributions indexed by parameters, and we tune the parameters to make the simple distribution as close as possible to the posterior. The usual algorithm is coordinate ascent: update the local parameters for every data point, then update the global parameters from all of them, then repeat. When the data has a million documents, each round costs a full pass over the million documents before the global answer improves even once. The paper asks whether we can improve the global answer after looking at only a few documents, and still reach the same kind of solution.
How it works
The walkthrough below uses a toy model with one global hidden quantity and no local variables, so each step is easy to follow by hand. The full algorithm adds a local step per document, covered in the math section.
Setup: a coin has an unknown bias. Its hidden quantity is the probability of heads, and the global parameter is a pair of pseudo-counts that describe our belief about it. The prior is . We observe four flips, heads, tails, heads, heads, so and the data points are . The exact posterior counts are .
-
Start. Set the global parameter to the prior, . Its mean is , which says nothing about the data yet. Check: , and .
-
Sample one point. Pick one flip at random. Say it is heads, . We do not look at the other three flips yet.
-
Form an intermediate parameter. Ask what the global parameter would be if this one flip were repeated times. The prior counts plus four copies of the flip's counts give . Check: the heads count goes , the tails count stays .
-
Blend with the current value. Use a step size . We take here, so . The new value is . Check: the mean is , which moved up from toward the flip.
-
Repeat with a new point. Sample tails, . Its intermediate parameter is . The step size is , so . Check: both entries are , so the mean is .
-
Keep going. The steps shrink, so later points change the answer less and less. A point that is heads again gives , with mean . The exact answer for these four flips is with mean . The estimate is moving toward it, and the stream never needed a full pass.
The visual below shows the loop. The paper's Figure 4 gives the same loop as pseudocode.
flowchart TD
A["Current global parameter lambda"] --> B["Sample one data point"]
B --> C["Optimize its local parameters"]
C --> D["Form intermediate global parameter as if the point were repeated N times"]
D --> E["Blend: new lambda = (1 minus rho) times old lambda plus rho times intermediate"]
E --> A
The math
We start from the model class the paper requires. Observations come from local hidden variables , one per observation, and one set of global hidden variables shared across all of them. The joint distribution factorizes:
Here holds fixed prior settings. The paper assumes that the conditional distributions are in the exponential family (see Exponential Family), with natural parameters and sufficient statistics . The model is conditionally conjugate: the full conditional of the global variables has the same form as their prior, which is what makes the global update simple (see Conjugate Prior).
Step 1 in symbols: the variational family and the objective
The mean-field family factorizes the approximation completely:
The global parameter governs the global variables and each governs one local variable. The objective is the evidence lower bound
which lower-bounds by Jensen's inequality (see Jensen's Inequality). Maximizing it is the same as minimizing the Kullback–Leibler Divergence from the approximation to the posterior, up to a constant.
Step 2 in symbols: the coordinate updates
Holding the local parameters fixed, the objective as a function of is maximized when
In words, the global parameter is set to the expected natural parameter of its full conditional. The local update has the same form, , and depends only on the global parameter and the th data point. This is the classical algorithm. Its global step needs every local parameter, which is the cost the paper wants to avoid.
Step 3 in symbols: the natural gradient
Gradient ascent on uses the ordinary Euclidean gradient, which depends on parameterization. The natural gradient rescales it by the inverse Fisher information (see Fisher Information) and Natural Gradient Descent explains why this measures steps in distance between distributions. For the exponential family, the paper shows the natural gradient of the objective reduces to
A natural gradient step of size one lands exactly on the coordinate update. So coordinate ascent is a special case of natural gradient ascent with the largest possible step.
Step 4 in symbols: the stochastic update
Pick one data point at random. Its intermediate global parameter is the coordinate update computed as if were repeated times:
This is an unbiased noisy version of the full update. In the coin example the sufficient statistic of a flip is its counts , so a heads contributes , as in the walkthrough. The stochastic variational inference update is then
which is the same as a noisy natural gradient step with size . The step sizes follow
The forgetting rate controls how fast old information is discounted. The delay down-weights the first iterations. For in the sum of the diverges while the sum of their squares converges, which are the Robbins and Monro conditions for stochastic approximation (see Stochastic Approximation and Stochastic Gradient Descent). Under those conditions the global parameter converges to a local optimum of the objective. The paper sets throughout its experiments.
Step 4b: minibatches
Sampling points at a time and averaging their intermediate parameters reduces noise. The update keeps the same form with replaced by the average over the minibatch. The paper's experiments vary the minibatch size .
Step 5: the step-size check on the toy
In the coin example, gives , and . Their sum keeps growing, and their squares add to a finite number, so the step sizes satisfy the conditions.
Worked examples
Prior , data size , first flip heads so .
- Intermediate parameter: .
- Step size: .
- Blend: .
- Mean of the coin: .
Interpretation: one heads moved the belief from to . It did not jump all the way to the four-flip answer of , because the step size is only one half. The method changes its belief in proportion to the step size, not all at once.
Start from and continue with the next two flips, tails then heads.
- Tails: , so .
- Step size: .
- Blend: .
- Mean: .
- Heads: , so .
- Step size: .
- Blend: .
- Mean: .
Interpretation: after three of the four flips, the mean is . The exact answer for all four is . The estimate keeps moving toward the truth, and each update used one flip.
The paper's topic-model comparison uses forgetting rate and delay , with minibatches of 500 documents. Take the iteration .
- Shifted iteration: .
- Power: . Since and , we get .
- Step size: .
- Meaning: at iteration 1000 the global parameter moves about 0.2 percent of the way toward the intermediate estimate. That estimate comes from 500 documents, so each update is averaged over a lot of text and changes little.
Try it: with and , what is ? Answer: . The steps shrink much more slowly when is near , which is why the paper finds that values near work better.
Common mistakes and tradeoffs
It is tempting to think that stochastic variational inference is an approximation of an approximation, so it must be much worse than the classical method. In fact the intermediate parameter has the same expected value as the full coordinate update, because it is an unbiased estimate of that update. The noise is what you pay for speed, and the decreasing step size averages it out.
It is tempting to think that a larger step is always better, since it makes progress faster. In fact a step near one makes the global parameter follow the last few documents and forget the rest. The conditions require the step sizes to shrink, and the paper's experiments show that a forgetting rate near one reaches a better local optimum than a fast-forgetting one.
It is tempting to think that the method finds the true posterior. In fact it finds a local optimum of the lower bound, which is an approximation in two ways: the mean-field family ignores dependence between hidden variables, and the optimizer may stop at a local optimum. The paper's evaluation measures predictive likelihood on held-out documents, not how close the approximation is to the posterior.
When to use it: a model with a tractable exponential-family structure, and data too large for full passes. When not to use it: small data where a full coordinate pass is cheap, models whose conditionals are not in the exponential family, and problems that need calibrated posterior uncertainty. Alternatives include Markov chain Monte Carlo, which samples from the posterior instead of optimizing a bound.
Results
The experiments fit latent Dirichlet allocation (LDA) and the hierarchical Dirichlet process (HDP) topic model on three collections. Nature has 350,000 documents, 58 million observed words and a vocabulary of 4,200 terms. The New York Times collection has 1.8 million documents, 461 million words and 8,000 terms. Wikipedia has 3.8 million documents, 482 million words and 7,700 terms. Each collection holds out 10,000 documents as a test set.
The model is scored by predictive log likelihood: fit the topics on the training documents, observe part of a test document, and measure the log probability the model gives to the held-out words. A better model assigns them higher probability.
- Model comparison. With the forgetting rate at 0.9 and minibatches of 500, the HDP gives consistently better predictive performance than LDA. LDA overfits as the number of topics grows, while the HDP stays robust. Traditional variational inference on subsets of each corpus did not perform as well (Figure 11).
- Forgetting rate. For the HDP, a forgetting rate close to one leads to a better local optimum on all three corpora (Figure 12). For LDA, slower forgetting rates are also preferred (Figure 14).
- Minibatch size. Batches of ten documents do worse, and sizes of 500 and 1,000 differ little. The New York Times corpus is the most sensitive to batch size and Wikipedia the least (Figure 13).
Limits: the evaluation is predictive likelihood on held-out text, not accuracy against a known answer. Every result is on topic models, and the method needs the forgetting rate and batch size to be tuned. The guarantee is convergence to a local optimum of the lower bound, so different settings can land in different solutions.
Reading guide
- Introduction. The problem of scale and the topic-model motivation. Needs Topic Model and the idea of a posterior from Posterior Distribution.
- Section 2.1 and 2.2. The class of models with local and global hidden variables, and the mean-field objective. Needs Exponential Family, Variational Lower Bound (ELBO), Mean-Field Approximation and Kullback–Leibler Divergence.
- Section 2.3. The natural gradient and the Fisher metric. Needs Natural Gradient Descent and Fisher Information.
- Section 2.4 and 2.5. Stochastic optimization, the update in Figure 4, and minibatches. Needs Stochastic Gradient Descent and Stochastic Approximation.
- Section 3. The notation and the LDA and HDP derivations. Needs Dirichlet Distribution and Conjugate Prior.
- Section 4. The empirical study. Read the setup and Figure 11 first, then the sensitivity figures.
Recap
- Variational inference turns posterior inference into maximizing the evidence lower bound over a simple family of distributions.
- Mean-field coordinate ascent alternates local and global updates, and each global update needs every data point.
- The natural gradient rescales steps so they follow changes in the distribution rather than in its parameters, and a natural gradient step of size one equals a coordinate update.
- Stochastic variational inference samples one data point, forms the global parameter it would imply if repeated times, and blends that into the running estimate with a shrinking step.
- The step sizes follow the Robbins and Monro conditions, which give convergence to a local optimum.
Next, read Topic Model for the application, Dirichlet Distribution for the priors on topics and mixtures, and Markov Chain Monte Carlo for the main alternative to variational approximations.
Check yourself
QuestionWhy does the classical coordinate update for the global parameter require a full pass over the data?Show answer
The global update is the expected natural parameter of the global complete conditional, which sums terms over every data point. Each sum term needs its own local parameters, so every document must be analyzed before the global parameter can be set.
QuestionIn the coin example, the prior is , and the sampled flip is tails, so . Compute the intermediate parameter .Show answer
. The tails count is the one that grows by four, because the flip is repeated four times as if it were the whole data set.
QuestionA learner uses and the current value with intermediate . What is the next value of , and what is its mean?Show answer
The step size is , so . The mean is .
QuestionWhy might a forgetting rate close to one work better than one close to one half, according to the paper's topic-model experiments?Show answer
A forgetting rate near one shrinks the step sizes quickly, so each update changes the global parameter less and averages over more of the recent history. The paper's experiments found that rates close to one reach a better local optimum. A rate near one half keeps steps large for longer, so the parameter tracks the last few minibatches rather than averaging over many of them.
QuestionA researcher says stochastic variational inference finds the true posterior of a topic model. What is wrong with this claim?Show answer
The method maximizes the evidence lower bound over a mean-field family, so it returns the best member of that family, not the posterior itself. The mean-field family drops dependence between hidden variables, and the optimizer converges only to a local optimum.
Sources
- Matt Hoffman, David M. Blei, Chong Wang, John Paisley, "Stochastic Variational Inference", arXiv:1206.7051, 2012. https://arxiv.org/abs/1206.7051
- "Variational Bayesian methods", Wikipedia. https://en.wikipedia.org/wiki/Variational_Bayesian_methods