Generative Vision: GANs & VAEs

variational autoencoder

A variational autoencoder keeps the encoder–decoder shape of an autoencoder but makes the latent space probabilistic and well-organized, so you can actually sample new images from it. Instead of mapping each image to a single point in code space, the encoder maps it to a little cloud (a probability distribution), and we insist that all those clouds together pile up into one smooth, simple shape (a standard Gaussian). Because the whole code space is then "filled in" smoothly, you can draw a random point, decode it, and get a plausible new image.

Precisely, a VAE is a latent-variable generative model with a prior p(z) = N(0, I), a standard multivariate Gaussian, and a decoder p_θ(x|z), a neural network that outputs the parameters of the per-pixel image distribution (Gaussian or Bernoulli). To train it by maximum likelihood we would need p_θ(x), the integral over z of p_θ(x|z) p(z), which is intractable. The VAE therefore introduces an approximate posterior q_φ(z|x) — the encoder, which outputs a mean μ(x) and variance σ²(x) for z — and maximizes the evidence lower bound (ELBO) instead of the true log-likelihood.

The ELBO is the expected reconstruction log-likelihood E[log p_θ(x|z)] minus the KL divergence KL(q_φ(z|x) || p(z)). The first term is reconstruction quality: encode x to a code distribution, sample a code, decode, and see how well it matches x. The second term, the KL divergence, pulls each per-image code cloud toward the standard-Gaussian prior — this is what makes the aggregate latent space smooth and samplable. Training uses the reparameterization trick so that gradients can flow through the random sampling of z. After training you generate by sampling z from N(0, I) and decoding once.

Train a VAE on faces, then walk along a straight line in latent space from the code of a smiling face to the code of a neutral face; decoding the intermediate points yields a smooth morph through gradually-fading smiles — evidence the latent space is continuous and semantically meaningful, unlike a plain autoencoder's.

VAEs tend to produce somewhat blurry images compared to GANs, because the Gaussian reconstruction loss rewards predicting the pixel-wise average of plausible outputs, and the latent bottleneck plus KL term discard high-frequency detail. Two common tuning knobs: posterior collapse (the model learns to ignore z) and the β in β-VAE (up-weighting the KL term trades reconstruction fidelity for more disentangled codes).

Also called
VAE