TL;DR
Training a latent-variable model needs the posterior over the hidden causes of each data point, and that posterior is usually intractable. Kingma and Welling bound the log likelihood with a tractable objective, then rewrite the random latent sample as a deterministic function of noise. Gradients can now flow through the sample, so the bound is optimized with plain stochastic gradient ascent. Pairing this with a neural encoder gives the variational autoencoder (AEVB).
Where you'll see it: the generative half of most latent-variable image and audio models, and the Gaussian latent space behind many later encoders used for representation learning.
The problem
A generative model says that data is produced by a hidden variable . You draw from a prior, then draw from a conditional. Fitting such a model by maximum likelihood requires the marginal . When the likelihood is a neural network, that integral has no closed form. The posterior is intractable for the same reason, so EM cannot be applied.
The usual workaround is variational inference: pick a simpler distribution and fit it to the posterior. The paper names two problems with the standard route. Mean-field updates need closed-form expectations under the approximation, which are themselves intractable for a neural likelihood. The naive Monte Carlo gradient of the bound with respect to the variational parameters has very high variance. The paper also asks for a method that scales to large datasets, meaning minibatch updates, and does not need an expensive sampling loop for each data point, as Monte Carlo EM does.
Key idea
Two moves, and the second depends on the first.
First, the reparameterization trick. If a sample can be written as for some noise whose distribution does not depend on , then the expectation over becomes an expectation over . You can differentiate through the transformation and get a low-variance gradient.
Second, amortized inference. Instead of fitting a separate for each data point, use one neural network that maps any to the parameters of . The paper calls this the recognition model. Inference for a new point then costs one forward pass, with no per-point optimization.
flowchart LR X[Data point x] --> E[Encoder q phi of z given x] E --> MU[mu and sigma] EPS[Noise epsilon from N 0 I] --> Z[z = mu plus sigma times epsilon] MU --> Z Z --> D[Decoder p theta of x given z] D --> R[Reconstruction term] E --> K[KL term to the prior] R --> L[Lower bound] K --> L
The encoder and decoder are trained together by gradient ascent on the lower bound. The two terms of that bound have an intuitive reading, which the paper points out. The KL term keeps the encoder's output close to the prior, which acts as a regularizer. The reconstruction term rewards the decoder for explaining the input from the sampled code.
The method
The variational bound
For one data point, the log likelihood splits exactly into two parts:
Because the KL divergence is non-negative, is a lower bound on . Maximizing it pushes toward the true posterior and pushes the model toward higher likelihood at the same time. The bound can be rewritten as
The second form is the one used in practice. The expectation is the reconstruction quality, and the KL term is an explicit penalty. The paper's bound is the same quantity usually called the ELBO. The paper gets it directly from the KL split above; the same bound also follows from applying Jensen's inequality to the log of an integral.
The naive score-function gradient of the expectation is . The paper calls this estimator impractical because its variance is very high. It needs many samples to be useful, and the reparameterization below avoids it.
The SGVB estimator
Suppose with . Then for any function ,
Applied to the bound, this gives the SGVB estimator. The paper gives two versions. The generic one averages over samples. The second one integrates the KL term analytically whenever possible and samples only the reconstruction term. The second version typically has lower variance, and the paper uses it for the VAE. The paper also reports that sample per data point works well as long as the minibatch is large enough, with used in experiments.
For a minibatch of points drawn from a dataset of points, the full-data bound is estimated by
The gradients of this estimate are used with SGD or Adagrad. The paper's Algorithm 1 is the whole training loop: initialize, draw a minibatch, draw noise, compute the gradients of the minibatch estimator with respect to both and , update, repeat until convergence.
The reparameterization trick
The paper justifies the trick by change of variables. Since is deterministic given , the probability mass is conserved: . Integrals over therefore become integrals over , and appears only inside the integrand.
The paper gives three families of distributions where a suitable transformation exists. The first is the inverse CDF method: sample a uniform variable and apply the inverse CDF of . The second is the location-scale family, where with a standard . The Gaussian is in this family. The third is composition, where the variable is built from simpler ones, such as a log-normal as the exponential of a normal.
Let the approximate posterior be with and .
- Draw from . This is the only random step.
- Form .
- Derivatives: and .
If a downstream loss has derivative at this sample, the chain rule gives and . Both are ordinary derivatives of a deterministic function, so an optimizer can use them. The sampling noise is held fixed for this step.
The Gaussian case
The paper's worked model takes the prior and the approximate posterior , where and are outputs of an encoder network. The sample is with . Between two diagonal Gaussians the KL term has a closed form, given in the paper's Appendix B. For latent dimensions,
So the only term that needs sampling is the reconstruction term. The paper's per-point estimator is this closed form plus . The decoder is a Bernoulli network for binary data and a Gaussian network for real-valued data. The Frey Face experiments use a Gaussian decoder with means constrained to by a sigmoid.
Take and , so .
- Compute the bracket: .
- Multiply by one half: .
- This is , so .
The value is positive, as a KL divergence must be. It is zero only when and , which is the prior itself. The encoder pays this price for moving away from the prior, and the reconstruction term pays it back for keeping information.
Results
The paper is short on numbers. Its experiments are plots, not tables, and the text reports comparisons rather than headline scores. Read them as relative claims.
Setup. The models were trained on MNIST and the Frey Face dataset. The encoder and decoder each have one hidden layer, with 500 hidden units for MNIST and 200 for Frey Face, to limit overfitting on the smaller set. Parameters start from a N(0, 0.01) draw, and Adagrad sets the step size, with the global step chosen from 0.1 on the first few iterations. Minibatches have and each point gets sample. The prior is an isotropic Gaussian, and a small weight decay corresponds to a N(0, I) prior on the weights, making the optimization approximate MAP estimation.
Variational lower bound (Figure 2). AEVB was compared with the wake-sleep algorithm, using the same recognition network for both. The authors report that AEVB converged considerably faster and reached a better solution in all experiments, across the latent sizes they tried. They also report that adding latent variables did not cause overfitting, which they attribute to the regularizing effect of the bound. The paper gives no table of final bound values.
Marginal likelihood (Figure 3). For a 3-dimensional latent space, where an MCMC estimator is still reliable, AEVB and wake-sleep were compared with Monte Carlo EM using a Hybrid Monte Carlo sampler. The three methods were compared on convergence speed at a small and a large training set size, using networks with 100 hidden units. The text gives the result only as the curves in Figure 3 and does not state a winner in words, so treat any ranking as read off the plot. Monte Carlo EM is not online and cannot be applied efficiently to the full MNIST dataset. The authors note that the marginal likelihood estimates became unreliable for higher-dimensional latent spaces, which is why this experiment stops at 3 dimensions.
Cost. Figure 2's caption reports about 20 to 40 minutes per million training samples on a CPU with an effective 40 GFLOPS. This is an old machine, so the number is useful only as an order-of-magnitude reference.
Visualization. With a 2D latent space, the learned encoder projects MNIST and Frey Face onto a low-dimensional manifold that can be plotted directly. Appendix A has the visualizations.
Why it mattered
The paper turned variational inference from a per-data-point optimization problem into a training loop of the same kind as supervised learning. That made latent-variable generative models practical on large datasets with neural likelihoods. The variational autoencoder became a standard generative model, and its encoder-decoder structure with a probabilistic bottleneck is now used widely for representation learning.
The reparameterization trick is the more durable contribution. It became the standard way to get low-variance gradients through stochastic nodes, and it reappears in later variational and diffusion-style models. The paper's amortized encoder also set a pattern: fitting one network to approximate many posteriors at once is the basis of much later work on amortized inference.
The paper's own limits set the agenda. The Gaussian posterior is a restrictive choice, which the paper states is a simplification and not a limitation of the method. The reconstruction-based objective is known to produce blurry samples for images, and the paper does not address that. Later work on richer posteriors and on better decoders grew out of these gaps.
Reading guide
- Section 1, Introduction. Needs Latent Variable Model for the idea of hidden causes, and Maximum Likelihood Estimation for what is being optimized.
- Section 2.1, Problem scenario. Needs Bayes' Rule for the posterior and Monte Carlo Method for the sampling-based estimators the paper compares against.
- Section 2.2, The variational bound. Needs Kullback–Leibler Divergence and Variational Lower Bound (ELBO). Jensen's Inequality explains why the bound holds.
- Section 2.3, The SGVB estimator and AEVB algorithm. Needs Monte Carlo Method for the estimator and Stochastic Gradient Descent for the update rule. Read the minibatch scaling factor here.
- Section 2.4, The reparameterization trick. Needs Reparameterization Trick and Gaussian (Normal) Distribution for the location-scale example.
- Section 3, Example: Variational Auto-Encoder. Needs Feedforward Neural Network for the MLPs, and Gaussian (Normal) Distribution for both the prior and posterior. The closed-form KL term is in Appendix B.
- Section 4, Related work. Needs Encoder-Decoder Architecture for the autoencoder framing. Its discussion of the mutual information is optional and needs Entropy.
- Section 5, Experiments. Needs Stochastic Gradient Descent for the optimizer. The figures are self-explanatory once the bound from Section 2 is clear.
Check yourself
QuestionRecall: why can the sample z not simply be drawn from q and differentiated directly with respect to the encoder's mu and sigma?Show answer
Sampling is a random operation that the gradient cannot pass through. The derivative of a sample with respect to mu or sigma is undefined as an ordinary function. The reparameterization trick rewrites the sample as mu plus sigma times noise, where the noise does not depend on the parameters. The randomness is moved into a fixed input, and the remaining computation is differentiable.
QuestionComputation: with mu = 0.2 and sigma = 1.5 in one latent dimension, compute the KL term from the closed form, and say whether it is positive.Show answer
sigma squared is 2.25. The bracket is 1 + log 2.25 - 0.2 squared - 2.25. Here log 2.25 is about 0.8109, and 0.2 squared is 0.04. So the bracket is 1 + 0.8109 - 0.04 - 2.25 = -0.4791. Half of that is -0.2396. This is minus the KL divergence, so the KL divergence is about 0.240. It is positive, which it must be, because the approximate posterior is not equal to the prior.
QuestionWhy does the paper use a minibatch scaling factor of N over M in the estimator?Show answer
The reconstruction and KL terms are defined per data point, and the full-data bound is the sum over all N points. The minibatch contains only M points, so its sum is a fraction M over N of the full sum. Multiplying the minibatch sum by N over M gives an unbiased estimate of the full sum. Without this factor the gradient would be too small by a factor of N over M and the effective learning rate would depend on the batch size.
QuestionApplied: you want a generative model of a continuous signal with a latent space you can sample from. Why would the VAE objective be preferred over fitting a plain autoencoder with a reconstruction loss?Show answer
A plain autoencoder maps each input to a single code, and the codes need not fill the space, so sampling random codes often produces nonsense. The VAE objective adds a KL term that pulls each posterior toward the prior, so codes from different inputs overlap and cover the prior's region. The result is a latent space where a random draw from N(0, I) decodes to plausible data. The paper's Section 4 supports the first half of this: it says the reconstruction criterion alone is not sufficient for learning useful representations, and that its regularizer comes from the bound rather than being added by hand. The claim that random draws decode to plausible data is the standard consequence of matching the prior, illustrated by the paper's sample figures (Figures 4 and 5).
QuestionScenario: a colleague says the VAE result is just a regularized autoencoder. Using the paper, what is the strongest point in their favor, and what is the strongest point against?Show answer
In favor: the objective has a reconstruction term and a regularization term, and the paper says so explicitly. The KL term plays the role that noise or sparsity penalties play in regularized autoencoders. Against: the regularizer is derived from the variational bound, not added by hand, so it has no tuning hyperparameter. The paper also presents the method as inference in a directed probabilistic model, with the encoder as an approximate posterior. The generative interpretation is what licenses sampling from the prior.
Sources
- Kingma and Welling, "Auto-Encoding Variational Bayes", arXiv:1312.6114 (2013). https://arxiv.org/abs/1312.6114
- "Variational autoencoder", Wikipedia. https://en.wikipedia.org/wiki/Variational_autoencoder