Visual explainer
Variational Autoencoders
Trace Gaussian latent codes, reparameterized sampling and the reconstruction–KL objective, then see why prior sampling can still fail.
A variational autoencoder combines a latent generative model with an encoder that approximates its posterior. Training balances reconstruction likelihood with a KL term; generation draws a latent code from the prior and then uses the decoder.
The opening picture shows a plain autoencoder with known codes −2 and 2 rebuilding A and B. The question mark at zero is an unchecked output, not proof that it must be invalid. Reconstruction alone does not supply a sampling distribution. A VAE explicitly models a prior and likelihood , alongside an approximate posterior . The AEVB paper, sections 2–3 establishes this construction.
Encode A Gaussian Distribution
Use a one-dimensional illustrative posterior . Its mean is , standard deviation , and variance . An encoder can predict a log variance and transform it to a positive standard deviation. In multiple dimensions, a diagonal Gaussian is a modeling choice, not a requirement of every VAE.
The bracket spans one standard deviation on either side of the mean, from to . It is not a safe decoding interval or a hard boundary: Gaussian tails extend beyond the cropped drawing. The density outline interpolates checked Gaussian landmarks; it is a visual approximation between them. This encoder distribution approximates , not the prior itself.
Sample Through A Transformation
Draw and form . For the illustrative draw , . The displacement arrow is latent units long; the filled mint point is the sample, not a new mean.
Reparameterization puts the random draw outside the learned transformation. With the draw held fixed, the sample remains differentiable in encoder parameters. It does not remove randomness from training. Repeated draws from the same encoded input can yield different codes.
Compare Posterior And Prior
Choose prior . Both rulers use the same latent scale. The upper posterior has mean and one-standard-deviation span to ; the lower prior has mean zero and span −1 to 1. This ruler is a wider view of latent space than the density plot; its two rows share one scale.
The Gaussian KL has a closed form:
Here it is nats. Mean shift and spread mismatch both contribute. Matching the mean alone would still leave KL about ; matching both gives zero. This term encourages compatibility with the prior, not guaranteed useful outputs at every location.
Generate Without Encoding An Input
The two source whiskers use the same scale and mark one standard deviation, not a complete set of draws. Reconstruction samples , conditioned on an observed input. Generation samples without an input photo. Both paths use the same decoder D, which defines .
The output labels identify two uses of the model, not guarantees of exact copies or realistic new images. Evaluate held-out reconstruction and prior samples separately. A low reconstruction error at encoder-produced codes does not by itself establish prior-sample quality.
Weight The KL Cost
The standard negative evidence lower bound is , where . The beta-VAE variant uses . Here assume nats and hold the posterior fixed solely to compare the weighting.
At , total cost is . At , it is . The white segment stays fixed while the mint segment doubles in length. Retraining generally changes both terms. Beta does not promise a particular sharpness, disentanglement or reconstruction quality. The assumed is a separate objective illustration, not computed from the decoder example below.
Decode A Likelihood
For a concrete decoder, define the synthetic scalar likelihood . At , it has mean , standard deviation , and a one-standard-deviation span from to . The dot marks the mean; the whisker is not the full support and is not a sampled observation.
A decoder network generally predicts likelihood parameters. Returning its mean and sampling an observation from that likelihood are different operations. The target observation is unspecified here, so these numbers do not claim a reconstruction error or determine the preceding assumed expected NLL. Image blur depends on likelihood and decoder choices; randomness alone does not force it.
Hold Noise Fixed For Gradients
With , compare and while holding each illustrative noise value fixed. For , both codes equal : the old filled dot and new open ring coincide. For , the code moves from to . Both rulers share a latent scale; the lower shift is .
The pathwise derivatives are and . Reconstruction gradients therefore flow through the decoder and this transformation to the encoder. There is no need to differentiate the random-number generator. This compares controlled parameter changes for a fixed draw, not an averaged training gradient or an optimizer step.
Try A Fresh Noise Draw
Restore and draw . Predict the latent sample first: . The same decoder gives mean and standard deviation , so its whisker spans to .
This output ruler uses the same position scale as the previous likelihood view: the mean moves left by output units, from to . The input and learned mapping have not changed; only the noise draw has. The output distribution still needs an additional draw if a sampled observation is wanted.
Where It Breaks
Consider an ideal collapsed boundary case: and a decoder that ignores , for every code. Both input-conditioned distributions are identical, with KL zero. The flat decoder mean stays at when the latent code changes from −1 to 1; the cross marks the absent influence.
In this case neither the encoded code distribution nor the decoder distinguishes the inputs. The random codes need not be numerically identical on individual draws; their distributions are identical. Encoder matching alone does not prove the decoder ignores : He et al., section 2.2 distinguishes inference collapse from full posterior collapse. Inspect latent usage and decoder sensitivity alongside KL, likelihood and samples. Zero KL alone is not evidence of a useful representation.
The Quick Version
- A VAE defines a prior, likelihood and approximate posterior.
- Standard deviation and variance are different quantities.
- Reparameterization turns independent noise into a differentiable sample path.
- KL penalizes posterior departure from the chosen prior.
- Generation samples the prior, then uses the decoder.
- Beta changes the weighting of a competing objective term.
- Decoder parameters describe a likelihood, not necessarily one certain output.
- Fixed noise exposes gradients through mean and scale.
- Fresh noise can change the decoded distribution.
- Posterior collapse can erase input information despite zero KL.