4.5.3 · D5Generative Models

Question bank — Variational Autoencoders (VAE) theory

1,852 words8 min readBack to topic

This page is a set of conceptual traps: short questions built around the mistakes people actually make with VAEs. Each answer is real reasoning, not a bare yes/no. Cover the reveals one at a time and argue your case before you peek.

Reminder of the symbols (all defined in the parent note):

  • = a data point (e.g. an image), = a latent code (a short list of numbers).
  • = the prior, a standard bell curve centred at zero with spread one.
  • = the encoder distribution, with mean and variance .
  • = the ELBO, the quantity we maximize.
  • = KL divergence, a one-directional "distance" between distributions.

🇮🇳 Hinglish version of the parent: yahaan padho.


True or false — justify

TF1. "Maximizing the ELBO is exactly the same as maximizing ."
False. They differ by , which is ; the ELBO equals the log-likelihood only when the encoder matches the true posterior exactly, which almost never happens.
TF2. "A VAE with a perfect reconstruction loss of zero is the ideal VAE."
False. Zero reconstruction error usually means the encoder collapsed variance to near zero and behaves like a deterministic autoencoder; the latent space then has gaps and sampling from the prior gives garbage.
TF3. "The KL term is symmetric, so we could write it the other way round without changing anything."
False. KL divergence is not symmetric; in general. VAEs specifically use the "reverse" form , which is mode-seeking and lets ignore regions where has mass.
TF4. "The reparameterization trick changes the distribution of ."
False. Writing with produces the exact same Gaussian ; it only relocates the randomness so gradients can flow through and .
TF5. "Because , every individual encoded point must also be centred at zero."
False. The aggregate of all encoded points is pushed toward , but each single has its own mean that can sit far from zero — that spread is how the model distinguishes data points.
TF6. "If the KL term becomes exactly zero for a data point, the model is doing great on that point."
False. means exactly — the encoder ignored entirely. This is posterior collapse and the decoder gets no useful information.
TF7. "The ELBO is a lower bound, so making it larger can never hurt the true log-likelihood."
True in spirit, but subtle. Raising the ELBO raises the floor under , but the two can move apart if the posterior gap grows; you push a bound up, you do not directly observe the true value.
TF8. "A GAN and a VAE optimize the same objective, just with different networks."
False. A VAE maximizes a likelihood lower bound (ELBO); a GAN plays a minimax game against a discriminator with no explicit likelihood. This is why VAE samples are often blurrier but its latent space is smoother and more probabilistic.

Spot the error

SE1. "We predict directly from the encoder because variance is what the formula needs."
Error: we predict , not . A raw network output can be negative, but variance must be positive; guarantees positivity and is numerically stable.
SE2. "The integral is intractable because the decoder is nonlinear, so we just approximate the decoder with a linear model."
Error: the intractability comes from integrating over a high-dimensional , not from decoder nonlinearity. The fix is variational inference (introduce ), not linearizing the decoder.
SE3. "In the ELBO derivation we applied Jensen's inequality as ."
Error: the inequality goes the other way for the concave : . That direction is exactly what makes a lower bound.
SE4. "We can just sample and backpropagate through the sampling node."
Error: a sampling operation is not differentiable with respect to . You must apply the reparameterization trick to move randomness into an external .
SE5. "The reconstruction term measures how close is to the prior."
Error: that term measures how well the decoder rebuilds from . Closeness to the prior is measured by the KL term .
SE6. "Since always, we can drop it from the loss to speed up training."
Error: dropping the KL term removes the pressure that shapes the latent space into the prior. Without it you get an ordinary autoencoder with a disorganized latent space you cannot sample from.
SE7. "The closed-form Gaussian KL uses ."
Error: for , (variance plus mean-squared). Forgetting the term breaks the derivation.
SE8. "Using more Monte Carlo samples per data point changes the objective we are optimizing."
Error: more samples reduce the variance of the gradient estimate but the expected objective is the same; VAEs commonly use just one sample per point.

Why questions

WHY1. Why do we introduce an encoder at all, instead of using the true posterior ?
The true posterior requires in its denominator (via Bayes' rule), and that marginal is the very intractable integral we cannot compute. is a cheap, learnable approximation that sidesteps it.
WHY2. Why choose a Gaussian for the prior rather than, say, a uniform distribution?
A Gaussian has infinite support (no hard edges to fall off), a simple closed-form KL against a Gaussian encoder, and is smooth so nearby codes decode to nearby data — properties that make sampling well-behaved.
WHY3. Why is the KL term called a "regularizer"?
It penalizes the encoder for placing codes far from the prior, pulling all encodings toward one shared shape. This prevents the latent space from fragmenting into isolated islands, just as an L2 penalty prevents weights from blowing up.
WHY4. Why does maximizing the ELBO indirectly shrink the posterior gap?
Because and the left side is fixed for fixed ; raising (by tuning ) must lower the gap term, forcing closer to the true posterior.
WHY5. Why do VAE samples often look blurrier than GAN samples?
The reconstruction term is an average likelihood over the encoder distribution, and with a Gaussian decoder it rewards predicting the mean of plausible outputs, which averages out sharp high-frequency detail into smooth blur.
WHY6. Why does the -VAE (weighting the KL term by ) encourage disentangled representations?
A stronger KL pressure forces the encoder to use latent dimensions frugally and near-independently to stay close to the factorized prior, which tends to align individual latent axes with independent factors of variation.
WHY7. Why is the reparameterization trick specifically easy for Gaussians but harder for discrete latents?
A Gaussian is a smooth, invertible transform of (), so gradients pass cleanly. Discrete draws have no such differentiable transform, requiring workarounds like the Gumbel-softmax relaxation.
WHY8. Why can a very powerful, expressive decoder actually cause posterior collapse?
If the decoder can model well on its own (e.g. an autoregressive decoder), the model can drive the KL term to zero and ignore entirely, because it no longer needs the latent information to reconstruct.

Edge cases

EC1. What happens to a single encoder distribution as its predicted variance ?
It becomes a spike (a point mass) at , so the VAE degenerates into a deterministic autoencoder for that point; the KL term also blows up because a near-delta is far from the spread-out prior.
EC2. What does the loss do when and for every ?
The KL term is exactly zero everywhere, but the encoder carries no information about — the textbook posterior collapse failure where reconstruction must be handled by the decoder alone.
EC3. If you feed the trained decoder a latent point with a huge norm, say , what should you expect?
Since the prior almost never produces such extreme codes, the decoder was rarely trained there and will likely output an unrealistic or degenerate sample — the latent space is only reliable near the origin.
EC4. What is the value of when exactly?
Exactly zero, because everywhere. KL is zero iff the two distributions are identical, and is strictly positive otherwise.
EC5. In the limit where the decoder outputs a fixed image regardless of , what happens to the reconstruction term?
It flatlines at the likelihood of that one fixed output; it cannot improve by using , so the model has no incentive to keep informative — another route into collapse.
EC6. What happens to the ELBO's two terms if the KL weight is set to ?
The regularizer vanishes and only reconstruction remains, so you recover a plain autoencoder: great reconstructions but an unstructured latent space you cannot sample from meaningfully.
EC7. If the true posterior happens to be non-Gaussian (multi-modal), what limits a standard VAE encoder?
A Gaussian can only capture one mode with a single bump, so the posterior gap stays large; richer families like normalizing flows for are used to close it.
EC8. For a conditional VAE, what changes in the prior when we condition on a label ?
Everything becomes conditioned on : the encoder is and the prior/decoder use too, so sampling can be steered to produce data of a chosen class rather than a random one.

Recall Quick self-test

The three-way identity — which term is fixed and which two trade off? ::: For fixed , is fixed; raising the ELBO must shrink the posterior gap. Which single failure mode do TF6, EC2 and WHY8 all describe? ::: Posterior collapse — the encoder stops using and the KL term hits zero.