TL;DR
Fitting a latent variable model means working out the hidden cause behind each observation. That hidden posterior usually has no closed form, because computing it needs an integral over every possible hidden value. The evidence lower bound (ELBO) gets around this. It is a score that is always at most the log probability of the data. You choose a simple distribution for the hidden variable, compute the score, and push it up. The better the score, the closer your simple guess is to the true posterior, and the score can be optimised with ordinary gradient methods.
Where you'll see it: in the training loss of a variational autoencoder, in the variational view of diffusion models, and in approximate Bayesian inference wherever the exact posterior is too hard to compute.
Intuition
A problem with one hard sum
Take a latent variable model. A hidden variable generates visible data . The model gives you two things cheaply: a prior over hidden causes and a likelihood for each cause. What you want is the posterior , the hidden cause given what you observed. Bayes' rule says that this equals the joint divided by the evidence , and the evidence is an integral over every value could take.
With two discrete values of that integral is a two-term sum. With a twenty-dimensional continuous and a neural network inside the likelihood, it has no closed form, and numerical integration is hopeless. You know how each cause would produce the data, but you cannot weigh every cause against the clue at once.
Guess, then score the guess
The trick is to stop computing the true posterior and instead pick a simpler distribution from a family you can work with, such as a Gaussian with a mean and a variance you can tune. You then need to know how good the guess is. The gap between your guess and the truth involves the unknown posterior, so you cannot compute it directly. What you can compute is a score that sits below the true answer by exactly that gap. Push the score up, and the gap must shrink.
- bound
- log p(x)
flowchart LR A[Observed data x] --> B[Pick a simple guess q of z] B --> C[Compute the ELBO] C --> D[Adjust q to raise the ELBO] D --> B D --> E[q approximates the hidden posterior]
The math
Definition
Let be a joint model of visible data and hidden variable , and let be any distribution over . The ELBO is
Here is the average over values of drawn from , and is the natural logarithm, so all scores are in nats. The ELBO depends on and on the fixed model , and nothing else.
The bound
Insert into the evidence and apply Jensen's inequality:
The inequality holds because is concave, and for a concave function the log of an average is at least the average of the logs (see Jensen's inequality).
The exact gap
The bound is tight in a precise way. Use and expand:
Here is the KL divergence, which is never negative and is zero only when its two arguments match. So the ELBO is the log evidence minus a KL term. Three consequences follow:
- The bound holds, because the KL term is never negative.
- The bound is exact when equals the true posterior, because then the KL term vanishes.
- does not depend on . Maximising over is therefore the same as minimising . The unknown quantity is a constant, so it can be ignored during optimisation.
The form used in practice
Expanding gives a second form:
The first term rewards guesses that explain the data well. The second penalises guesses that stray from the prior. This is the loss of a variational autoencoder: reconstruction error plus a KL penalty.
If the model has parameters , the same bound can be maximised over both and . Because never exceeds , raising it also pushes up the model's log likelihood. This is the variational version of maximum likelihood.
Worked examples
Let take the values 0 and 1, each with prior probability 0.5. For the one observed , the likelihoods are and .
- Evidence: , so .
- Joint values: and .
- True posterior: and .
- Guess a uniform : .
- Term for : .
- Term for : .
- ELBO: .
- Gap: . The KL check gives , as the identity predicts.
Interpretation: the uniform guess is too loose, and the bound sits 0.14 nats below the truth. Now set to the posterior, and . The ELBO becomes , which equals exactly. The gap is zero.
The model is and . Observe . The true posterior is : its mean is and its variance is . The marginal is , so .
Guess . Both terms of the second form have closed forms. The reconstruction term is , and the KL term is . With the ELBO is
- Exact guess : . This equals , so the gap is zero.
- Lazy guess, the prior : . The gap is , which matches .
- Optimise. Setting gives . Setting gives . The optimum recovers the posterior exactly.
Interpretation: this model is simple enough that the posterior is known in closed form, so the bound is not needed. The point is to see the recipe work. The plot shows the bound for as a function of . Its peak touches the true log evidence at .
Tradeoffs and failure modes
Variational inference trades exactness for speed and scale. The table lists the usual choices.
| Situation | Problem | Better choice |
|---|---|---|
| Conjugate model, posterior has a closed form | Approximation adds error for no gain | Compute the posterior exactly |
| Large model, many data points | Each gradient step needs the full data | Stochastic or minibatch ELBO |
| Need exact samples or guaranteed convergence to the posterior | Variational answers are biased | [[markov-chain-monte-carlo |
| Posterior has correlations between hidden variables | A factorised guess cannot represent them | Richer families, such as full-covariance Gaussians or normalising flows |
| Sampling inside the ELBO gives noisy gradients | High variance slows training | The [[reparameterization-trick |
The most common failure is an under-dispersed guess. The reverse KL term is mode-seeking: it prefers a guess that sits on one peak of a multimodal posterior and ignores the others. The result is a confident answer that is too narrow. Mean-field guesses, which assume hidden variables are independent, make this worse.
A second failure appears in VAEs. If the decoder can model the data well without using , the optimiser can drive the KL term to zero, so matches the prior and carries no information. This is called posterior collapse. Common fixes are KL annealing, which weights the KL term down early in training, and a weaker decoder.
History
Variational methods for approximate inference grew out of statistical physics, where a free energy plays the role of a bound. In machine learning, Hinton and van Camp (1993) used a related bound to fit neural network weights under a description-length penalty. Neal and Hinton (1998) recast the EM algorithm as maximising a free energy, which is the same kind of bound, so the ELBO is also called the free energy. Jordan, Ghahramani, Jaakkola and Saul (1999) gathered these ideas into a widely used introduction to variational methods for graphical models.
The name "ELBO" became common in the 2010s with variational autoencoders. Kingma and Welling (2013) and Rezende, Mohamed and Wierstra (2014) showed that the bound could be trained at scale with stochastic gradients and the reparameterisation trick. That made it a practical tool for deep generative models.
Check yourself
QuestionWhat does ELBO stand for, and what does it bound from below?Show answer
Evidence lower bound. It bounds the log evidence , the log probability of the observed data under the model, from below. The gap between them is the KL divergence between the guess and the true posterior .
QuestionPrior , likelihoods and . With a uniform guess , what is the ELBO?Show answer
The evidence is . The joint values are and . The ELBO is . The true log evidence is , so the gap is , which is the KL divergence from the uniform guess to the posterior .
QuestionWhy can you maximise the ELBO over without knowing or the true posterior?Show answer
The evidence does not depend on . It is a constant during optimisation. Maximising the ELBO over is therefore the same as minimising the KL divergence to the posterior, even though neither term is computed directly.
QuestionIn a VAE, the KL term has dropped to nearly zero and the reconstructions ignore the latent code. What went wrong, and name one fix?Show answer
This is posterior collapse. The guess has matched the prior, so the latent code carries no information. A strong decoder can model the data without it, so the optimiser has no reason to use . One fix is KL annealing, which weights the KL penalty down early in training. Another is a weaker decoder that cannot ignore the latent code.
Sources
- Blei, Kucukelbir and McAuliffe, Variational Inference: A Review for Statisticians (2017).
- Kingma and Welling, Auto-Encoding Variational Bayes (2013).
- Bishop, Pattern Recognition and Machine Learning, §10.1.
- Evidence lower bound, Wikipedia.