Stochastic variational inference
How to fit a variational approximation to data too large for full passes: global and local variables, conditional conjugacy, the natural gradient of the ELBO, minibatch updates with a Robbins–Monro step size, and online LDA.
Global and local variables
The topic Latent Dirichlet allocation ended with a cost problem. Mean-field VI for LDA updates the proportions and responsibilities of every document, and only then recomputes the topics . For a corpus of a million documents the topics move once per million local updates. This topic makes them move after every small batch.
The trick works for a whole class of models. Their joint density splits into a part shared by all objects and one factor per object:
Here are the global variables: every object depends on them. Each is a local variable: it belongs to object alone, and given the pair is independent of all other pairs. In LDA the topics are global, while the proportions and the assignments of a document are local; so in LDA the global variables are written , and the letter keeps its LDA meaning.
The running example is the two-component Gaussian mixture of the topic EM and Bayesian PCA, now with a prior on the means. The components have unit variances, and to keep the example small their weights are fixed at . Each mean gets a broad prior:
The means are global, the labels are local.
The mean-field family mirrors the split: , with a global variational parameter and local parameters (for the mixture, the responsibilities ). The ELBO splits the same way, into a global term and a sum of local ones:
Coordinate ascent from the topic Variational inference alternates two steps: update all local parameters, then update . The first pass is the most wasteful one: local updates are computed under a random initial , and all of them are used for a single global step.
Conditional conjugacy and the coordinate update
To write the global update in closed form we need one assumption, conditional conjugacy: the complete conditional of the global variables, their distribution given everything else, lies in an exponential family,
This is the general conjugate prior from the topic Conjugate priors and the exponential family, applied to the complete-data likelihood : is the natural parameter of the prior, the sufficient statistics of one object, and the log-partition function. Note what is not required: the prior need not be conjugate to with summed out. For a mixture it is not.
Take from the same family, with natural parameter ; then is the prior itself. The mean-field rule gives the coordinate update
The local update has the same shape with the local complete conditional , and it touches only object .
In the mixture, use the natural parameters of a Gaussian from that topic: , so and
where is the mean of and its precision. The prior gives , and object contributes . In plain terms the update reads
and the local step is . Precisions add, as in the Normal mean with known variance; the global sum runs over all objects.
The natural gradient of the ELBO
Now look at the same update as an optimization step. Fix the local parameters and keep only the terms of the ELBO that depend on . Using and writing ,
If the are themselves optimal for the current , the gradient through them vanishes, so this is also the gradient of the ELBO as a function of alone.
The matrix is the covariance of under , which is the Fisher information of . The natural gradient multiplies the ordinary gradient by :
Why ? An ordinary gradient is the steepest direction when a step is measured by the Euclidean length of , which depends on how we chose to write . The natural gradient is the steepest direction when a step is measured by how much the distribution changes: . That makes it independent of the parameterization of .
The payoff: a natural-gradient step of length is a convex blend, , and the step of length is exactly coordinate ascent. No Fisher matrix is ever formed or inverted.
A worked case without local variables: the Normal mean with known variance , prior , and ten points with mean . The data add to , so . Start from , that is . The natural gradient is , and the step of length lands on : the exact posterior, with precision and mean . The ordinary gradient has a different direction and length; the check below shows where it lands.
The minibatch update
The natural gradient still contains a sum over all objects. Replace it with an unbiased estimate. Draw a minibatch of objects uniformly at random, fit their local parameters under the current , and pretend the dataset consists of copies of the minibatch. This gives the intermediate global parameter
Each object enters with probability , so , and is an unbiased estimate of the natural gradient. A step of length along it is
One iteration of stochastic variational inference (SVI) is therefore: sample ; run the local updates for only; form ; blend it into ; forget the . An iteration costs instead of , and the local parameters of the other objects are never stored.
A worked update for component of the mixture. Since is linear in and , blending is the same as blending these two numbers. Let , , and let the current factor be , , so . The minibatch has with responsibilities , so and . With the intermediate values are
With : and , so . Blend natural parameters, never means and variances: the mean moves by a precision-weighted amount, not by times the gap.
Step sizes and the Robbins–Monro conditions
Unrolling the update shows what does. The estimate from step enters with weight .
- With every weight equals : is the plain average of all minibatch estimates so far. In a model without local variables (the Normal mean) the estimates are independent and unbiased, and their average converges to the exact posterior parameter.
- With a constant the weights decay geometrically: old minibatches are forgotten, the noise never averages out, and ends up jittering in a cloud around the optimum whose size grows with .
The general answer is the Robbins–Monro conditions:
The first lets travel any distance from a bad start; the second keeps the total injected noise finite. Under them, and mild regularity, SVI converges to a local optimum of the ELBO. The standard schedule is
with the forgetting rate and the delay . The delay damps the first steps: with the first step has and replaces entirely by one noisy minibatch estimate, so a component that the batch barely touched is reset to the prior.
A simulation on the mixture with points and true means : coordinate ascent needs full passes to come within nats per point of its optimal ELBO, while SVI with , , gets there after about of a pass, that is, half a dozen minibatches. With a constant the means keep jittering with a standard deviation of about , roughly seven times the posterior standard deviation ; the decaying schedule shrinks the jitter to the posterior's own scale.
SVI for LDA
SVI was introduced for LDA as online LDA (Hoffman, Blei and Bach). We keep the notation of the topic Latent Dirichlet allocation; the paper writes for the topics, for their prior and for the responsibilities. There are documents, topics , proportions , assignments and words . The global factor is , the local ones are and , and the prior parameter is the vector .
Local step for each document of the minibatch: starting from some , repeat until it stops changing
Global step: count the expected uses of word by topic in the minibatch, scale to the corpus and add the prior,
On the tiny corpus of that topic (, ), a minibatch of document 3 alone counts as three copies of it: if its token goal has , then .
Batch mean-field VI for LDA is the same pair of formulas with and . The difference is what SVI buys: memory for alone ( numbers) instead of and for the whole corpus, topics that improve from the first minibatch, and documents that can arrive as a stream and be seen once.
Where SVI falls short
SVI is coordinate ascent made stochastic, and it inherits every assumption of the closed-form update.
- Conditional conjugacy. must be computable. A logistic likelihood (the topic The Laplace approximation and Bayesian classification) or a neural-network decoder breaks it: the complete conditional is no longer in an exponential family.
- A cheap local step. Each minibatch object needs its own inner optimization; if that is expensive, it dominates the cost.
- Mean-field limits. Reverse KL is mode-seeking, so variances come out too small and local optima remain.
- Tuning. , and matter, and the full ELBO costs a pass over the data to evaluate, so in practice one monitors the predictive likelihood of held-out data.
The first limit is the deepest. The natural gradient exists in closed form only because of conjugacy. Without it, we can still write the gradient of the ELBO as an expectation under and estimate it from samples of , for any model whose we can evaluate. That is black-box variational inference, the next topic.
Check your understanding
The same questions as in Pulse. Answers are shared between modes.
Answers are saved on the server and tied to this browser until you sign in.