KatInterview

Variational Autoencoders: Theory and Training Dynamics

Machine LearningModel answer
HardModel answerMachine Learninggenerative-modelsvariational-inferencedeep-learning

Last updated

Derive the ELBO objective for VAEs, explain gradient estimation through reparameterization, compute the KL term analytically, and diagnose posterior collapse.

You are building a generative model for complex high-dimensional data x using a latent variable approach. Your architecture consists of:

  • A standard Gaussian prior over latent codes: p(z) = N(0, I)
  • A decoder network that models the likelihood: p_θ(x | z)
  • An encoder network approximating the posterior: q_φ(z | x) = N(μ_φ(x), diag(σ_φ(x)²))

The true posterior p_θ(z | x) is intractable to compute directly.

Address the following:

Part 1: Objective Function Starting from log p_θ(x), derive the Evidence Lower Bound and break it into its two components. Explain what optimization goal each component enforces and why tightening this bound is equivalent to fitting the approximate posterior to the true one.

Part 2: Gradient Estimation Describe why naive sampling from q_φ(z | x) blocks gradient flow to φ. Present the reparameterization technique for Gaussian distributions and explain how it enables Monte Carlo gradient estimates with lower variance.

Part 3: Analytic KL Write the closed-form expression for D_KL(N(μ, diag(σ²)) || N(0, I)) summed over all latent dimensions. Specify what each parameter contributes to the divergence.

Part 4: Training Pathology Define what happens during posterior collapse when using expressive autoregressive decoders. Describe two or three techniques practitioners use to prevent the latent code from being ignored during training.

Hints

Hint 1

The gap between log p(x) and the ELBO is exactly the KL divergence between the approximate and true posteriors

Hint 2

Express z as a deterministic transformation of the parameters plus independent noise, then differentiate through that transformation

Hint 3

The analytical KL for diagonal Gaussians has one term per dimension involving the mean squared, variance, and log-variance

Hint 4

KL annealing schedules, minimum information constraints per dimension, and limiting decoder expressiveness all help preserve latent information