§20.10.3–20.10.5Variational Autoencoders · Generative Adversarial Networks · Moment Matching

Part III DL pp. 696–703 · ~4 min read

  • generative adversarial network (gan)
  • discriminator
  • generative moment matching network
  • maximum mean discrepancy (mmd)

Two differentiable generators dominate modern generative modeling. Both pair the generator g(z)g(\boldsymbol{z}) with a second network — an inference net, or an adversary.

§20.10.3 Variational autoencoders

The variational autoencoder (VAE) pairs the generator (a decoder p(xz)p(\boldsymbol{x}\mid\boldsymbol{z})) with a learned encoder q(zx)q(\boldsymbol{z}\mid\boldsymbol{x}), and trains both by maximizing the evidence lower bound:

The VAE objective (eq 20.77)

L(q)=Ezq(zx)[logpmodel(xz)]DKL ⁣(q(zx)pmodel(z))\mathcal{L}(q) = \mathbb{E}_{\boldsymbol{z}\sim q(\boldsymbol{z}\mid\boldsymbol{x})}\left[\log p_\text{model}(\boldsymbol{x}\mid\boldsymbol{z})\right] - D_{\mathrm{KL}}\!\left(q(\boldsymbol{z}\mid\boldsymbol{x}) \,\|\, p_\text{model}(\boldsymbol{z})\right)
Eq[logp(xz)]\mathbb{E}_{q}[\log p(\boldsymbol{x}\mid\boldsymbol{z})]the reconstruction term — decode the encoded z and score how well it reconstructs x (like any autoencoder)scalar
DKL(q(zx)p(z))-D_{\mathrm{KL}}(q(\boldsymbol{z}\mid\boldsymbol{x}) \| p(\boldsymbol{z}))pull the encoder's posterior toward the prior p(z)=N(0,I) — a regularizer that keeps the latent space smooth and samplablescalar

The whole thing is trainable by gradient descent because the reparametrization trick lets gradients flow through the sample zq\boldsymbol{z}\sim q. Training encoder and decoder together forces a smooth, predictable latent coordinate system — the VAE is an excellent manifold learner. Traverse a learned 2-D latent space (fig 20.6):

A VAE's learned 2-D latent manifold (fig 20.6). The decoder g(z) maps each code z to a face; sliding z moves smoothly along the manifold. Here the two latent axes became disentangled factors — z₁ ≈ head rotation, z₂ ≈ expression — which the VAE discovered on its own, with no supervision.
z₁ → head rotationz₂ → expression
z = (0.6, -0.4) → decoder g(z) → x

Training a decoder and an encoder together forces a smooth, predictable latent coordinate system. Sliding z moves along the manifold and the decoded face changes continuously — here z₁ became "rotation" and z₂ became "expression," two disentangled factors the VAE discovered on its own (fig 20.6).

VAEs are elegant, extend to almost any architecture (DRAW, variational RNNs, importance-weighted autoencoders), and give state-of-the-art likelihoods. Their weakness: samples are often blurry — an artifact of maximizing a likelihood lower bound (which, like DKL(pdatapmodel)D_{\mathrm{KL}}(p_\text{data}\|p_\text{model}), spreads mass onto in-between points; fig 3.6), aggravated by the Gaussian output that tends to ignore small-but-crucial features.

§20.10.4 Generative adversarial networks

A generative adversarial network (GAN) replaces inference with a game. The generator gg makes samples; a discriminator dd tries to tell real from fake; each fights the other:

The GAN minimax game (eqs 20.80–20.81)

g=argmingmaxd  v(g,d),v=Expdatalogd(x)+Expmodellog ⁣(1d(x))g^{*} = \arg\min_g \max_d\; v(g, d), \qquad v = \mathbb{E}_{\boldsymbol{x}\sim p_\text{data}} \log d(\boldsymbol{x}) + \mathbb{E}_{\boldsymbol{x}\sim p_\text{model}} \log\!\left(1 - d(\boldsymbol{x})\right)
maxdv\max_d vthe discriminator maximizes v — learns to output d≈1 on real data and d≈0 on generator samplesclassifier
mingv\min_g vthe generator minimizes v — learns to fool the discriminator. At equilibrium p_model = p_data and d = ½ everywhere (samples indistinguishable)generator

No inference network, no partition-function gradient — just two networks in competition. Play it: the generator chases the data while the discriminator hunts the gap; at convergence the densities coincide and d12d\to\tfrac12:

The adversarial game. The generator moves p_model toward the fixed p_data to fool the discriminator, whose optimal output is d(x)=p_data/(p_data+p_model). At equilibrium the two densities coincide and d ≈ ½ everywhere — samples are indistinguishable. The inset shows the catch: simultaneous gradient play on a minimax value can ORBIT the equilibrium (the v=ab game) instead of converging, because equilibria are saddle points, not minima.
d = ½p_datap_model (generator)d(x) = P(real)
step 0
v = E_data log d + E_model log(1−d)
why GANs can fail: v = ab game
params orbit, never reach equilibrium

The generator moves p_model toward p_data to fool the discriminator; the optimal d(x) = p_data/(p_data+p_model). At the equilibrium the two densities coincide and d ≈ ½ everywhere — samples are indistinguishable. But simultaneous gradient play can orbit an equilibrium (the v=ab inset) instead of converging: GAN training is a saddle-point problem, not a minimization.

That non-convergence — equilibria are saddle points of vv, not minima of a single loss — is GANs’ central difficulty (the best-performing generator uses a non-saturating heuristic loss instead of mingv\min_g v). When it works (DCGAN, LAPGAN, conditional GANs), it produces the sharpest samples of any method — a LAPGAN fooled human judges 40% of the time. The idea descends directly from noise-contrastive estimation (§18.6): “a good model should fool a classifier.” Uniquely, a GAN can place zero probability on the training points yet still trace a convincing data manifold.

§20.10.5 Generative moment matching networks

A third option drops the second network entirely. A generative moment matching network trains gg so the moments of its samples match the data’s — using the maximum mean discrepancy (MMD), a kernel cost that compares infinitely many moments at once and is zero iff the two distributions are equal.

Three generators, three ways to say “match the data”

All three train the same differentiable generator g(z)g(\boldsymbol{z}), differing only in the signal that says how well it matches the data. The VAE adds an encoder and maximizes a likelihood lower bound — stable, good likelihood, blurry. The GAN adds an adversary and plays a game — sharp samples, unstable training. The GMMN adds nothing extra but needs large batches to estimate moments. The GAN’s discriminator can be seen as automatically discovering which statistic the generator is matching worst — a learned, adaptive version of the GMMN’s fixed moment set.

Next: giving these generators convolutional structure, and the fully-directed autoregressive models and autoencoder-based samplers.

Check yourself — VAEs, GANs & moment matching

1.What are the two terms of the VAE objective, and what does each do?

2.Why are VAE samples often blurry?

3.In a GAN, what happens at the equilibrium of the minimax game?

4.Why is GAN training prone to non-convergence?

5.How does a generative moment matching network (GMMN) differ from a GAN, and what connects them?

5 questions