16 Generative Adversarial Networks
Suppose we draw a 100-dimensional random vector \(\mathbf{z} \sim \mathcal{N}(\mathbf{0}, \mathbf{I})\) and pass it through a neural network \(G(\mathbf{z})\) to generate an image. Writing down such a generator network takes only a few lines of code; training it is the challenge. Unlike classifiers or autoregressive language models, which maximize the log-likelihood of observed labels or tokens, a direct generator defines an implicit distribution over images without an explicit density \(q(\mathbf{x})\) to maximize. How can we train a generative model when we can sample from it, but cannot evaluate its likelihood?
We have already seen how a classifier can compare two distributions from samples alone. When correcting for covariate shift in Section 3.6.2, we trained a binary classifier to distinguish training inputs from test inputs, and its optimal logit recovered the log density ratio between the two distributions. Goodfellow et al. (2014) turned this two-sample comparison into a generative training principle: in a generative adversarial network (GAN), a discriminator (or critic) \(D\) is trained to distinguish real data from generated samples, while the generator \(G\) is trained to produce samples that the discriminator cannot tell apart from real data. Through the discriminator’s gradients, the generator learns where its samples are over- or under-represented relative to the data distribution, without either density ever being written down explicitly.
Although diffusion and flow-matching models (Chapter 17) have largely superseded standalone GANs for general-purpose image synthesis, adversarial objectives remain a core component of modern generative systems, training the latent autoencoders behind latent diffusion models, neural audio vocoders, and one-step generators distilled from multi-step diffusion teachers.
This chapter develops adversarial modeling in three stages. We begin with objectives and divergences: Section 16.1 derives the optimal log-loss discriminator, its Jensen–Shannon divergence, and the non-saturating generator loss; Section 16.2 generalizes this framework to \(f\)-divergences and integral probability metrics (Maximum Mean Discrepancy and Wasserstein-1 distance); and Section 16.3 introduces relativistic paired critics (RpGAN) based on Bradley–Terry ranking. Next, Section 16.4 studies minimax training dynamics on the Dirac-GAN, showing why unregularized updates rotate or spiral outward and how zero-centered gradient penalties (\(R_1\) and \(R_2\)) stabilize the R3GAN recipe (Huang et al. 2024). Finally, Section 16.5 and Section 16.6 scale convolutional and projection-conditioned architectures to image synthesis alongside feature-space evaluation metrics (FID, KID, and \(k\)-NN precision and recall), while Section 16.7 explains how adversarial critics prevent conditional-mean blurring in diffusion distillation, image tokenizers, and speech vocoders.
Notation
Table 16.1 summarizes the notation used across this chapter. Divergences and entropies are measured in nats and follow Chapter 37: \(D_{\textrm{KL}}\) denotes the Kullback–Leibler divergence, \(\mathrm{JS}\) the Jensen–Shannon divergence, \(H\) differential or discrete entropy, and \(H_b(t)\) the binary entropy of a Bernoulli distribution with parameter \(t\).
| symbol | meaning | first used | common alternative |
|---|---|---|---|
| \(p\), \(q\), \(m = \tfrac12(p + q)\) | data, generator, and balanced mixture densities | Section 16.1 | \(p_{\textrm{data}}\), \(p_g\) |
| \(x \sim p\), \(x' \sim q\); \(y \in \{0, 1\}\) | real sample, generated sample, and source label (\(1\) = real) | Section 16.1 | |
| \(z \in \mathbb{R}^{d_z}\), \(G\) | latent vector and generator network (\(x' = G(z)\)) | Section 16.1 | |
| \(D\); \(V(D)\) | critic/discriminator realness logit; minimax value function | Section 16.1 | |
| \(\rho = p/q\), \(\lambda = \log(p/q)\) | density ratio and log density ratio | Section 16.1 | |
| \(w_{\textrm{sat}}\), \(w_{\textrm{ns}}\), \(w_{\textrm{Rp}}\) | per-sample generator gradient weights (saturating, non-saturating, relativistic) | Section 16.1, Section 16.3 | |
| \(\eta = p/(p + q)\) | Bayes class posterior \(P(y = 1 \mid x)\) | Section 16.2 | |
| \(\ell\), \(L(\eta)\), \(\Delta_\ell(p, q)\) | margin payoff, conditional Bayes risk, and Bayes-risk gap | Section 16.2 | |
| \(D_f(p \,\|\, q)\); \(k(x, x')\) | \(f\)-divergence with convex function \(f\); positive-definite kernel | Section 16.2 | |
| \(\Phi(D)\), \(d_{\mathrm{Rp}}(p, q)\) | relativistic pairing objective and pairing divergence | Section 16.3 | |
| \(R_1\), \(R_2\); \(\gamma\) | zero-centered gradient penalties at real and generated samples; penalty weight | Section 16.4 | |
| \(c\), \(e_c\), \(\phi(x)\) | conditioning variable, condition embedding, and feature representation | Section 16.5, Section 16.6 |