Lesson 8.8advanced3 h 30 min

Generative models I: VAEs and GANs

Learning p(x): latent variables, the ELBO, and the adversarial game

Everything in this phase so far generates text one token at a time. Images, audio and molecules need other ways to learn a distribution p(x)p(\mathbf{x}) and sample from it. Variational autoencoders introduce the latent-variable view and the ELBO — the same bound that reappears in diffusion (8.9 Generative models II: Diffusion and flow matching) — and GANs introduce adversarial training, which survives today in distillation and perceptual losses. The derivations lean on Bayes and MLE from 1.7 Probability II: Bayes, independence, MLE and MAP, KL from 1.9 Information theory: entropy, cross-entropy and KL divergence, and the encoder–decoder vocabulary from 4.10 Autoencoders, embeddings and representation learning.

You'll be able to

  • Explain the latent-variable formulation of generative modeling and why the likelihood is intractable
  • Derive the ELBO with Jensen's inequality and interpret its two terms
  • Implement the reparameterization trick and the closed-form Gaussian KL
  • Write the GAN minimax objective, derive the optimal discriminator and connect it to JS divergence
  • Describe mode collapse, WGAN, and where VAEs and GANs are still used in 2026

Key ideas

  1. Generative models learn p(x) to sample, score and represent data; families trade off quality, diversity, likelihood and speed.
  2. VAEs posit z ~ N(0, I) and a decoder p_θ(x|z); the marginal likelihood is intractable, so an encoder q_φ(z|x) approximates the posterior.
  3. ELBO = E_q[log p_θ(x|z)] − KL(q_φ(z|x) ‖ p(z)); the gap to log p(x) is KL(q ‖ true posterior), so maximizing the ELBO tightens both.
Show 4 more key ideas
  1. The reparameterization z = μ + σ ⊙ ε makes sampling differentiable; the Gaussian-to-standard-normal KL has a closed form.
  2. GANs play min_G max_D E[log D(x)] + E[log(1 − D(G(z)))]; D* = p_data/(p_data + p_g), so at optimum G minimizes JS divergence.
  3. Mode collapse and vanishing gradients plague GANs; WGAN's Wasserstein critic, spectral norm and StyleGAN's design were the main fixes.
  4. Today VAEs compress latents for diffusion models and tokenize images/audio; adversarial losses persist in distillation and perceptual training.

Suggested path through this lesson