VerifiedarXiv:1406.266133 min
Generative models · Theory

GAN: Generative Adversarial Networks

A generator learns to produce data by training against a classifier that tries to catch its fakes.

Goodfellow and colleagues’ 2014 method fits a generative model without ever writing down its probability density. The generator’s only training signal is the gradient of a second network’s verdict on its samples.

Explaining the paperGenerative Adversarial NetsGoodfellow, Pouget-Abadie, Mirza, Xu, Warde-Farley, Ozair, Courville, Bengio · Université de Montréal · NeurIPS 2014 · arXiv:1406.2661 ↗

The page derives the paper’s two main results with worked numbers and trains a small GAN in the browser, where you can switch between the paper’s two generator losses and watch one of them stall.

Why the density was the hard part

A generative model of images is a program that outputs new images resembling a training set. The standard way to fit one in 2014 was maximum likelihood: define a probability density p(x)p(\mathbf{x}) over images, then adjust its parameters so the training images get high probability. That requires computing p(x)p(\mathbf{x}), or at least its gradient, for every training image.

For the deep models of the time this was intractable. A restricted Boltzmann machine on 28×28 binary images defines p(x)p(\mathbf{x}) up to a normalizing constant, the partition function, which sums over every joint setting of its 784 visible and HH hidden binary units: 2784+H2^{784+H} terms. Its gradient can only be estimated with Markov chain Monte Carlo, and the paper’s related-work section notes that mixing (how fast the chain moves between modes) “poses a significant problem” for those methods. Directed models had the matching problem of inference over latent variables. The variational autoencoder, published a few months earlier, handled that with a learned inference network and a bound on the likelihood.

Generative Adversarial Nets (Goodfellow, Pouget-Abadie, Mirza, Xu, Warde-Farley, Ozair, Courville and Bengio, Université de Montréal) drops the density. The model is a network that turns random noise into a sample, and nothing ever evaluates how probable a sample is. The training signal comes from a second network, a classifier trained to tell real examples from generated ones. The paper proves that if both networks were unlimited in capacity and trained to their optima, the generator’s samples would follow the data distribution exactly. Training needs only backpropagation, and sampling needs one forward pass.

The sections below go in dependency order: the game and its value function; the generator as a warp of noise; the optimal discriminator; what the generator minimizes against it; how Algorithm 1 approximates the game; why the generator’s loss was changed; a live 1-D GAN; the failure modes; and what the experiments do and do not show.

Two networks, one value function

The paper’s own analogy is counterfeiters and police. The counterfeiters print fake currency and try to spend it without being caught; the police try to tell fake bills from real ones. Each side improves against the other, and the contest ends when the fakes are indistinguishable from real money. The analogy breaks in one place: the counterfeiters here never see a real bill. They learn only from how the police react to their fakes.

The generator GG is a neural network that takes a noise vector z\mathbf{z}, drawn from a fixed prior pzp_{\mathbf{z}}, and outputs a sample G(z)G(\mathbf{z}) in data space. The discriminator DD takes a data-space input x\mathbf{x} and outputs one number in (0, 1), its estimate of the probability that x\mathbf{x} came from the training data rather than from GG. Both are multilayer perceptrons. They share one objective, the value function VV, which DD maximizes and GG minimizes:

min⁡Gmax⁡D  V(D,G)=Ex∼pdata[log⁡D(x)]+Ez∼pz[log⁡(1−D(G(z)))]\min_G \max_D \; V(D,G) = \mathbb{E}_{\mathbf{x}\sim p_{\text{data}}}\big[\log D(\mathbf{x})\big] + \mathbb{E}_{\mathbf{z}\sim p_{\mathbf{z}}}\big[\log\big(1 - D(G(\mathbf{z}))\big)\big]min⁡Gmax⁡D  V(D,G)=Ex∼pdata[log⁡D(x)]+Ez∼pz[log⁡(1−D(G(z)))]\begin{aligned} \min_G \max_D \; V(D,G) &= \mathbb{E}_{\mathbf{x}\sim p_{\text{data}}}\big[\log D(\mathbf{x})\big] \\ &\quad + \mathbb{E}_{\mathbf{z}\sim p_{\mathbf{z}}}\big[\log\big(1 - D(G(\mathbf{z}))\big)\big] \end{aligned}
(1)

The first term is large when DD gives real examples a score near 1. The second is large when DD gives generated samples a score near 0, since then 1−D1 - D is near 1. Both logs are at most 0, so the best DD can do is push VV up toward 0. The generator appears only in the second term, and it lowers VV by making D(G(z))D(G(\mathbf{z})) larger.

With numbers: say on one real example DD outputs 0.9 and on one fake it outputs 0.2. That pair contributes

log⁡0.9+log⁡(1−0.2)=−0.105−0.223=−0.329\log 0.9 + \log(1 - 0.2) = -0.105 - 0.223 = -0.329

A sharper discriminator that scores them 0.99 and 0.01 gets −0.010 − 0.010 = −0.020, closer to the maximum of 0. A better generator whose fake now scores 0.9 drives the second term to log 0.1 = −2.303. All logs on this page are natural logs.

The paper calls this a “two-player minimax game”. Later writing, including Goodfellow’s own 2016 tutorial, describes the solution as a Nash equilibrium and a saddle point of VV: a minimum along the generator’s parameters and a maximum along the discriminator’s. Those terms are used below where they help, but they are not in the 2014 paper, which frames the solution as the global minimum of a criterion C(G)C(G) derived in a later section.

The generator warps noise

The generator is deterministic: the same z\mathbf{z} always gives the same output. All the randomness in its samples comes from z\mathbf{z}. The paper puts it this way: “The generator G implicitly defines a probability distribution pgp_g as the distribution of the samples G(z)G(\mathbf{z}) obtained when z∼pz\mathbf{z} \sim p_{\mathbf{z}}.” That distribution is the pushforward of the prior through GG. You can draw from it by sampling z\mathbf{z} and running the network, but no formula for pg(x)p_g(\mathbf{x}) is ever written down, which is what “implicit” means.

A smooth map shapes a distribution by stretching some regions of noise space and compressing others. In one dimension the standard change-of-variables rule makes this exact. It is background, not something the paper states, and a GAN never computes it:

pg(x)=pz(z)∣G′(z)∣,x=G(z)p_g(x) = \frac{p_{\mathbf{z}}(z)}{|G'(z)|}, \qquad x = G(z)

Take zz uniform on (0, 1) and G(z)=z2G(z) = z^2. Then

pg(x)=pz(x)∣G′(x)∣=12xp_g(x) = \frac{p_{\mathbf{z}}(\sqrt{x})}{|G'(\sqrt{x})|} = \frac{1}{2\sqrt{x}}

which is 5.0 at x=0.01x = 0.01 and 0.56 at x=0.81x = 0.81. Near z=0z = 0 the slope G′(z)=2zG'(z) = 2z is small, so a wide interval of zz lands in a narrow interval of xx and probability piles up. The paper’s Figure 1 caption says the same thing: “G contracts in regions of high density and expands in regions of low density of pgp_g.” Normalizing flows are generative models that use this rule directly, which forces them to be invertible with a computable Jacobian; a GAN’s generator needs neither property.

Figure 1 shows the warp. Evenly spaced noise values on the bottom line are carried by threads to their outputs on the top line. With the slider at 0, GG is a stretched identity and the output is as flat as the input. Drag it to the right and watch where the threads converge: under the two modes of the target, where the curve of GG is flat.

Figure 1 · noise pushed through G
matched
Evenly spaced noise samples z (bottom) map through x=G(z)x = G(z) to the top line. Drag training to bend GG from the identity toward the inverse CDF of the two-mode target: the ticks bunch where GG contracts and spread where it expands, and the teal histogram p_g comes to match the amber curve.

In the paper’s MNIST experiment the same idea runs in 100 dimensions. The released configuration draws z\mathbf{z} uniformly from [−3,3]100[-\sqrt3, \sqrt3]^{100} and passes it through two 1200-unit ReLU layers to 784 sigmoid outputs, one per pixel. So for a batch of 100, z\mathbf{z} is a 100×100 matrix and G(z)G(\mathbf{z}) is 100×784. Noise enters only at the bottom layer (§5). The uniform prior is the one in the paper’s Figure 1 caption and in that config; the paper’s text does not fix one prior for every experiment.

The optimal discriminator

Freeze the generator, so pgp_g is some fixed distribution, and ask which discriminator maximizes VV. The paper’s Proposition 1 answers exactly. First, rewrite VV as one integral over data space. Real examples arrive with density pdata(x)p_{\text{data}}(x) and fakes with density pg(x)p_g(x), and because pgp_g is defined as the distribution of G(z)G(\mathbf{z}), the expectation over z\mathbf{z} becomes an expectation over xx with no Jacobian factor:

V(G,D)=∫x[ pdata(x) log⁡D(x)+pg(x) log⁡(1−D(x)) ] dxV(G,D) = \int_x \Big[\, p_{\text{data}}(x)\,\log D(x) + p_g(x)\,\log\big(1 - D(x)\big) \,\Big]\,dxV(G,D)=∫x[ pdata(x) log⁡D(x)+pg(x) log⁡(1−D(x)) ] dx\begin{aligned} V(G,D) = \int_x \Big[\, &p_{\text{data}}(x)\,\log D(x) \\ &+ p_g(x)\,\log\big(1 - D(x)\big) \,\Big]\,dx \end{aligned}
(3)

The integrand at a point xx depends only on the single number D(x)D(x), so the whole integral is maximized by maximizing it separately at every xx. Write a=pdata(x)a = p_{\text{data}}(x) and b=pg(x)b = p_g(x). The function f(y)=alog⁡y+blog⁡(1−y)f(y) = a\log y + b\log(1-y) has derivative

f′(y)=ay−b1−y=0⟹y∗=aa+bf'(y) = \frac{a}{y} - \frac{b}{1-y} = 0 \quad\Longrightarrow\quad y^* = \frac{a}{a+b}

and its second derivative −a/y2−b/(1−y)2-a/y^2 - b/(1-y)^2 is negative, so this is a strict maximum. It lies inside (0, 1) whenever aa and bb are both positive, since ff goes to −∞-\infty at either end. Substituting back:

DG∗(x)=pdata(x)pdata(x)+pg(x)D^*_G(x) = \frac{p_{\text{data}}(x)}{p_{\text{data}}(x) + p_g(x)}
(2)

At each point, the best discriminator reports the share of probability there that belongs to the data. Pick a point where pdata(x)=0.4p_{\text{data}}(x) = 0.4 and pg(x)=0.1p_g(x) = 0.1. Then D∗(x)D^*(x) = 0.4/0.5 = 0.8. If the generator improves until pg(x)=0.4p_g(x) = 0.4 as well, D∗(x)=0.5D^*(x) = 0.5, because a sample landing at that point is equally likely to be real or fake. Where only data lives, D∗=1D^* = 1; where only fakes live, D∗=0D^* = 0. The paper adds that DD need not be defined outside the union of the two supports, where the integrand is zero anyway.

Rearranged, (2) is the density ratio between real and fake:

D∗(x)1−D∗(x)=pdata(x)pg(x)\frac{D^*(x)}{1 - D^*(x)} = \frac{p_{\text{data}}(x)}{p_g(x)}

At the example point, 0.8/0.2 = 4 = 0.4/0.1. The discriminator never learns either density, but its output encodes their ratio. The paper also reads D’s objective as logistic regression for P(real∣x)P(\text{real} \mid x). That reading holds because (1) weights real and fake examples equally, which amounts to a prior of one half on each class. A classifier trained on one real example for every three fakes would instead converge to

0.25⋅0.40.25⋅0.4+0.75⋅0.1=0.571\frac{0.25 \cdot 0.4}{0.25 \cdot 0.4 + 0.75 \cdot 0.1} = 0.571

at the same point. The ratio form above holds either way.

Figure 2 plots (2) for a two-mode data distribution and a generator distribution of the same shape, shifted to the right. The probe reads out pdatap_{\text{data}}, pgp_g and D∗D^* at one point; drag it across a mode and watch D∗D^* track the local mix. Then drag the training slider to 100% and the violet curve flattens onto the dashed line at one half.

Figure 2 · the optimal discriminator
x = -1.45
28%
The optimal discriminator D∗=pdata/(pdata+pg)D^* = p_{\text{data}}/(p_{\text{data}} + p_g) (violet) for data and a shifted generator distribution. Click or drag on the plot, or use probe x, to read the three values at one point. Training slides pgp_g onto pdatap_{\text{data}}; the readout C(G)C(G) reaches −log⁡4-\log 4 when they coincide.

A related idea already existed. Noise-contrastive estimation (NCE, Gutmann and Hyvärinen 2010) fits a density model by training it to classify data against samples from a fixed noise distribution. The paper points out that because NCE’s noise is fixed, learning slows sharply once the model is roughly right. In a GAN the samples being classified against the data come from the generator, and they move toward the data during training, so the classification stays informative.

What the generator minimizes

Substitute the optimal discriminator (2) into (1). What remains depends only on GG; the paper calls it the virtual training criterion C(G)C(G):

C(G)=max⁡DV(G,D)=Ex∼pdata ⁣[log⁡pdata(x)pdata(x)+pg(x)]+Ex∼pg ⁣[log⁡pg(x)pdata(x)+pg(x)]C(G) = \max_D V(G,D) = \mathbb{E}_{\mathbf{x}\sim p_{\text{data}}}\!\Big[\log \frac{p_{\text{data}}(\mathbf{x})}{p_{\text{data}}(\mathbf{x})+p_g(\mathbf{x})}\Big] + \mathbb{E}_{\mathbf{x}\sim p_g}\!\Big[\log \frac{p_g(\mathbf{x})}{p_{\text{data}}(\mathbf{x})+p_g(\mathbf{x})}\Big]C(G)=max⁡DV(G,D)=Ex∼pdata ⁣[log⁡pdata(x)pdata(x)+pg(x)]+Ex∼pg ⁣[log⁡pg(x)pdata(x)+pg(x)]\begin{aligned} C(G) &= \max_D V(G,D) \\ &= \mathbb{E}_{\mathbf{x}\sim p_{\text{data}}}\!\Big[\log \frac{p_{\text{data}}(\mathbf{x})}{p_{\text{data}}(\mathbf{x})+p_g(\mathbf{x})}\Big] \\ &\quad + \mathbb{E}_{\mathbf{x}\sim p_g}\!\Big[\log \frac{p_g(\mathbf{x})}{p_{\text{data}}(\mathbf{x})+p_g(\mathbf{x})}\Big] \end{aligned}
(4)

To see what this measures, introduce the average distribution M=(pdata+pg)/2M = (p_{\text{data}} + p_g)/2. The denominators in (4) equal 2M2M, so each log splits into a log-ratio against MM minus log⁡2\log 2. The expectation of log⁡(P/M)\log(P/M) under PP is the Kullback-Leibler divergence KL(P ∥ M)\mathrm{KL}(P\,\|\,M), which is zero when P=MP = M and positive otherwise. The two −log⁡2-\log 2 terms add to −log⁡4-\log 4:

C(G)=−log⁡4+KL ⁣(pdata ∥ pdata+pg2)+KL ⁣(pg ∥ pdata+pg2)C(G) = -\log 4 + \mathrm{KL}\!\Big(p_{\text{data}}\,\Big\|\,\frac{p_{\text{data}}+p_g}{2}\Big) + \mathrm{KL}\!\Big(p_g\,\Big\|\,\frac{p_{\text{data}}+p_g}{2}\Big)C(G)=−log⁡4+KL ⁣(pdata ∥ pdata+pg2)+KL ⁣(pg ∥ pdata+pg2)\begin{aligned} C(G) &= -\log 4 + \mathrm{KL}\!\Big(p_{\text{data}}\,\Big\|\,\frac{p_{\text{data}}+p_g}{2}\Big) \\ &\quad + \mathrm{KL}\!\Big(p_g\,\Big\|\,\frac{p_{\text{data}}+p_g}{2}\Big) \end{aligned}
(5)

The sum of those two KL terms is twice the Jensen-Shannon divergence (JSD), a symmetric measure of how different two distributions are, defined as the average KL of each to their mixture:

C(G)=−log⁡4+2⋅JSD(pdata ∥ pg)C(G) = -\log 4 + 2\cdot \mathrm{JSD}\big(p_{\text{data}}\,\|\,p_g\big)
(6)

The JSD is non-negative and zero only when the two distributions are equal. So Theorem 1 follows: the global minimum of C(G)C(G) is −log⁡4≈−1.386-\log 4 \approx -1.386, reached if and only if pg=pdatap_g = p_{\text{data}}. At that point (2) gives D∗=12D^* = \tfrac12 everywhere, and plugging one half into (4) gives log ½ + log ½ = −log 4 directly.

The other end of the range follows from a bound the paper does not state, JSD≤log⁡2\mathrm{JSD} \le \log 2 (Lin 1991). When the two distributions do not overlap at all, MM equals half of pdatap_{\text{data}} wherever the data lives, so log⁡(pdata/M)=log⁡2\log(p_{\text{data}}/M) = \log 2 there and the first KL term is exactly log⁡2\log 2. The second is the same, so

C(G)=−log⁡4+2log⁡2=0C(G) = -\log 4 + 2\log 2 = 0

and CC ranges from −1.386 (identical) to 0 (disjoint).

Figure 3 computes (5) for a Gaussian pdatap_{\text{data}} with standard deviation 0.5 and a Gaussian pgp_g you can shift and widen. At a shift of +1.5 (three standard deviations) each KL term is 0.527 and C=−0.333C = -0.333. Move the shift to 0 with the width at ×2 and CC stops at −1.201: matching the mean is not enough. Then push the shift past +3 and read the slope: at +4 the KL terms are both 0.693 (that is, log⁡2\log 2), CC is 0.000 to three decimals, and the slope along the shift is 0.001, against 0.796 at a shift of +0.5.

Figure 3 · the value at the optimal discriminator
+1.50
×1.00
Top: p_data, p_g and their dashed average MM, with the two KL terms of (5) in the readout. Bottom: C(G)C(G) against the shift of pgp_g for the current width, with the floor −log 4 and the ceiling 0. Drag shift and width; the floor is reached only at shift 0 and width ×1. The ceiling at 0 follows from JSD≤log⁡2\mathrm{JSD} \le \log 2, which the paper does not state.

A generator whose samples sit where the data has no mass gets almost no signal from this objective about which way to move, because CC changes very little as pgp_g slides. That observation is the starting point of Wasserstein GAN, discussed at the end.

Everything so far lives in the space of distributions. Proposition 2 states the convergence result: if GG and DD have enough capacity, if DD reaches its optimum at every step, and if pgp_g itself is updated to improve the criterion, then pgp_g converges to pdatap_{\text{data}}. The proof uses the fact that CC is convex in pgp_g with the unique minimum from Theorem 1. The paper then says what this does not cover: “In practice, adversarial nets represent a limited family of pgp_g distributions via the function G(z;θg)G(\mathbf{z};\theta_g), and we optimize θg\theta_g rather than pgp_g itself. Using a multilayer perceptron to define G introduces multiple critical points in parameter space.” The result guarantees that the distribution converges in function space; it says nothing about gradient descent on the weights.

Algorithm 1: alternate the updates

The theory assumes DD is at its optimum whenever GG moves. Solving the inner max⁡D\max_D to completion before every generator step would work in principle, and the paper gives two reasons not to: it is “computationally prohibitive, and on finite datasets would result in overfitting.” Algorithm 1 instead alternates kk steps of minibatch gradient ascent on D with one step of descent on G. D then stays near its optimum “so long as G changes slowly enough.” The experiments used k=1k = 1, “the least expensive option”, and SGD with momentum.

Alternating updates on a min-max objective do not behave like descent on a single loss. Figure 4 uses a two-parameter toy game from the later GAN literature: the generator’s parameter xx descends and the critic’s parameter yy ascends V(x,y)=xy−0.03 y2V(x,y) = xy - 0.03\,y^2. The equilibrium is the origin. Press Play and compare the two paths from the same start. Then raise kk, which gives the critic more steps to catch up with its best response y∗=x/0.06y^* = x/0.06 between generator steps.

Figure 4 · orbiting the saddle
step 240/240
k = 1
η = 0.12
A toy game, not a GAN: xx descends and yy ascends V(x,y)=xy−0.03 y2V(x,y) = xy - 0.03\,y^2. From the same start, simultaneous steps spiral away from the equilibrium. Alternating steps with k=1k=1 circle it many times; more critic steps per round tighten the spiral. On the pure bilinear game xyxy (no y2y^2 term) alternating steps orbit forever for every kk, so the tightening depends on the critic having an optimum to track.

The released code differs from Algorithm 1 as printed. In adversarial/__init__.py, the cost used by the MNIST config computes the discriminator’s and the generator’s gradients from the same minibatch and returns them together, so one SGD update moves both players at once. Figure 1’s caption in the paper also describes training as “simultaneously updating” D. With the non-saturating generator loss (next section) and a real network this worked; the toy game shows why simultaneous updates are not guaranteed to.

The swapped generator loss

Early in training the generator’s samples are poor, so the discriminator rejects them confidently and D(G(z))D(G(\mathbf{z})) is near 0. The generator’s loss in (1) is log⁡(1−D(G(z)))\log(1 - D(G(\mathbf{z}))), and near D=0D = 0 that function is nearly flat compared with the alternative below: its slope in DD is only 1/(1−D)1/(1-D), about 1, and through the discriminator’s sigmoid the gradient reaching the generator shrinks in proportion to DD itself. The paper says “log⁡(1−D(G(z)))\log(1 - D(G(\mathbf{z}))) saturates” and proposes training GG to maximize log⁡D(G(z))\log D(G(\mathbf{z})) instead:

minimize log⁡(1−D(G(z)))⟶minimize −log⁡D(G(z))\text{minimize } \log\big(1 - D(G(\mathbf{z}))\big) \quad\longrightarrow\quad \text{minimize } -\log D(G(\mathbf{z}))minimize log⁡(1−D(G(z)))⟶minimize −log⁡D(G(z))\begin{aligned} &\text{minimize } \log\big(1 - D(G(\mathbf{z}))\big) \\ \longrightarrow\quad & \text{minimize } -\log D(G(\mathbf{z})) \end{aligned}

The derivative of −log⁡D-\log D has magnitude 1/D1/D. The ratio of the two is (1−D)/D(1-D)/D. At D=0.01D = 0.01 the old loss gives 1.01 and the new one 100, a factor of 99. The discriminator’s output is a sigmoid of a logit ℓ\ell, and following the chain rule one step further gives the same factor in a cleaner form: the gradient each fake passes back is proportional to DD under the old loss and to 1−D1 - D under the new one. At D=0.003D = 0.003 that is 0.003 against 0.997.

Figure 5 · the non-saturating swap
0.10
The generator’s cost against D(G(z))D(G(z)), the discriminator’s score on a fake. Near 0, where early samples sit, the minimax cost log⁡(1−D)\log(1-D) is flat and the non-saturating cost −log⁡D-\log D is steep. Drag the marker to compare the two slopes at any score.

The paper states that the new objective “results in the same fixed point of the dynamics of G and D but provides much stronger gradients early in learning.” The two generator losses share that fixed point but differ at every other point, and with the swap the game is no longer one value function that one player maximizes and the other minimizes. The JSD result of the previous section was derived for the original loss. For the swapped loss, with the discriminator at its optimum, Arjovsky and Bottou (2017) showed the generator follows

Ez[−∇θlog⁡D∗(Gθ(z))]=∇θ[KL(pg ∥ pdata)−2 JSD(pg ∥ pdata)]\mathbb{E}_{\mathbf{z}}\big[-\nabla_\theta \log D^*(G_\theta(\mathbf{z}))\big] = \nabla_\theta\big[\mathrm{KL}(p_g\,\|\,p_{\text{data}}) - 2\,\mathrm{JSD}(p_g\,\|\,p_{\text{data}})\big]Ez[−∇θlog⁡D∗(Gθ(z))]=∇θ[KL(pg ∥ pdata)−2 JSD(pg ∥ pdata)]\begin{aligned} &\mathbb{E}_{\mathbf{z}}\big[-\nabla_\theta \log D^*(G_\theta(\mathbf{z}))\big] \\ &\quad = \nabla_\theta\big[\mathrm{KL}(p_g\,\|\,p_{\text{data}}) - 2\,\mathrm{JSD}(p_g\,\|\,p_{\text{data}})\big] \end{aligned}

The first term is the reverse KL divergence, Epg[log⁡(pg/pdata)]\mathbb{E}_{p_g}[\log(p_g/p_{\text{data}})]. It is large when the generator puts samples where the data has almost no mass, and it changes little when the generator skips a region the data does cover, because that region contributes almost nothing to an expectation under pgp_g. The JSD enters with a minus sign. The trained loss is therefore not a descent on the JSD, and its reverse-KL term tolerates dropped modes, which the collapse section below returns to.

The listing puts the pieces together. It follows Algorithm 1’s structure with the non-saturating generator loss, which is what the paper recommends in §3 and what its code trains:

# one round of Algorithm 1: k discriminator steps, then one generator step
for _ in range(k):                         # the paper used k = 1
    x = sample_data(m)                     # m real examples,  x ~ p_data
    z = sample_noise(m)                    # m noise vectors,  z ~ p_z
    fake = G(z).detach()                   # no gradient reaches G on this line
    loss_d = -(log(D(x)) + log(1 - D(fake))).mean()
    opt_d.zero_grad(); loss_d.backward()
    opt_d.step()                           # minimizing -V = ascending V

z = sample_noise(m)
# Algorithm 1 as printed (saturating):   loss_g = log(1 - D(G(z))).mean()
loss_g = -log(D(G(z))).mean()              # non-saturating (paper, section 3)
opt_g.zero_grad(); loss_g.backward()       # gradient passes through D into G
opt_g.step()                               # only G's weights move here

Two lines control where gradients go. detach() in the discriminator step stops gradients from reaching GG there. In the generator step the gradient flows backward through DD into GG; it also accumulates in D’s gradient buffers, which is harmless because only opt_g steps and opt_d.zero_grad() clears them before the next discriminator step. The generator never reads a real example: its only information about the data is the direction, in data space, that raises D’s score on its samples. For MNIST at batch size 100 the discriminator sees a 100×784 real batch and a 100×784 fake batch and outputs 100 probabilities for each.

A GAN trained in the page

Figure 6 is a real GAN, small enough to train in the browser in well under a second. It runs Algorithm 1 on 1-D data with two modes. The generator maps z∼U(−1,1)z \sim U(-1, 1) through 16 tanh units to a number; the discriminator maps a number through 24 tanh units to a sigmoid. Both use SGD with momentum 0.5, batch 64. The generator starts as a narrow spike to the left of the data, and the discriminator gets a 300-step head start against it, the situation in the paper’s Figure 1(b). The violet curve is the trained discriminator, not D∗D^*. The bottom readout, “push on each fake”, is the average size of the gradient each fake sample receives in data space.

At step 0 the discriminator scores the fakes at 0.0028, and the push on each fake is 2.71 under the non-saturating loss and 0.0077 under the saturating loss. Their ratio, 351, is (1−D)/D(1-D)/D at D=0.0028D = 0.0028, the factor derived above. Press Play with the non-saturating loss: within 10 generator steps the spike has moved onto the data; by step 1,500 the samples cover both modes and both traces in the lower strip sit near one half. Switch to the saturating loss and play again: for about 80 steps the spike creeps right while D(G(z)) stays under 0.01 and the push stays near 0.01. Once D(G(z)) starts to rise the push grows with it and the spike jumps onto the data. Raise kk to 5 and the stall lengthens to about 150 steps, because a discriminator trained more per round stays more confident.

Figure 6 · Algorithm 1, live
step 0
k = 1
A 1-D GAN trained with Algorithm 1: p_data (two modes), a histogram of the generator’s samples, and the current discriminator D(x)D(x). Toggle the generator’s loss, set kk, and Play or scrub. The lower strip traces mean D on real and fake batches. Seed retrains from different initial weights; seed 2 of 6 with the non-saturating loss and k=1k = 1 ends on one mode.

Across six seeds, the non-saturating run reaches the data by step 10 in every case. The saturating run takes 80 to 170 steps at k=1k = 1 and 110 to 290 at k=5k = 5. Both losses end near the same place, which is what “same fixed point” predicts. The saturating run is slower because its generator gets almost no gradient while D rejects its samples.

Mode collapse and other failures

Seed 2 in Figure 6 shows the paper’s main named failure. The generator is graded only on whether DD accepts the samples it produces. If it finds an output that the current discriminator scores highly, it can map many values of z\mathbf{z} to that output, and nothing in its loss charges it for the modes it never visits: DD only scores the generator’s samples and real examples, and a mode the generator never visits produces no samples to score. The paper calls this “the Helvetica scenario”, in which GG “collapses too many values of z\mathbf{z} to the same value of x\mathbf{x} to have enough diversity to model pdatap_{\text{data}}.” The later name is mode collapse. The paper lists it under keeping D and G synchronized: GG must not be trained too much without updating DD.

A supervised loss does not allow this, because every training example has its own target and a missed example raises the loss. In a GAN, a discriminator that eventually learns to reject the one favored output pushes the generator to another single output, so the samples can hop from mode to mode instead of spreading across them. Figure 7 animates the two regimes on eight modes.

Figure 7 · coverage and collapse
Eight data modes on a ring and the generator’s samples. Healthy: the samples spread from a blob to all eight modes. Mode collapse: they pile onto one mode and hop between modes. An animated illustration of the two regimes.

Mode collapse is one of three distinct failures, and each has a different cause. Oscillation comes from the game structure: gradient steps near a saddle point can circle it, as in Figure 4, and Mescheder, Geiger and Nowozin (2018) showed that when the data lies on a low-dimensional manifold, unregularized GAN training is not always convergent even locally. Vanishing generator gradients come from a discriminator that is too confident, through saturation (Figure 5) or through the flat region of Figure 3 where the two distributions overlap little. No single change to Algorithm 1 fixes all three, and much of the follow-up work targeted one of them.

The experiments and the metric

The paper trained adversarial nets on MNIST, the Toronto Face Database (TFD) and CIFAR-10. Generators used a mix of ReLU and sigmoid units. Discriminators used maxout units, each of which outputs the largest of several linear functions of its input, and were trained with dropout, which zeroes a random subset of units on every training step. In the MNIST config the discriminator has two maxout layers of 240 units with 5 pieces each, batch size is 100, the learning rate is 0.1, and momentum rises from 0.5 to 0.7.

Since a GAN has no likelihood to report, the paper estimated one. The procedure, a Gaussian Parzen window, places a Gaussian of width σ\sigma on each generated sample, averages them into a density, and reports the mean log-likelihood of the test set under that density. σ\sigma is chosen on a validation set. The paper says the method “has somewhat high variance and does not perform well in high dimensional spaces but it is the best method available to our knowledge.”

Figure 8 runs the estimator in one dimension on a generator that is perfect by construction: its samples are fresh draws from pdatap_{\text{data}}, so the right answer, −1.17, is known. With 30 samples the best score over σ\sigma is about −1.44. With 300 it reaches −1.17 at σ\sigma near 0.1. At σ=0.01\sigma = 0.01 and 30 samples it falls to about −101, because most test points are far from every sample in units of σ\sigma. In 784 dimensions the number of samples needed to cover the space the same way is far larger, which is the “does not perform well in high dimensional spaces” caveat.

Figure 8 · the Parzen-window estimate
σ = 0.23
n = 30
A Gaussian Parzen window built from nn samples of a generator that matches p_data exactly, and its estimate of the density. The lower panel plots the test-set score against σ\sigma, with the true value dashed. Drag σ and n: small σ\sigma or few samples score far below the truth.

Table 1 reports these estimates for the adversarial net and three earlier models whose sampling runs a Markov chain: a deep belief network (DBN), a stacked contractive autoencoder (CAE) and a deep generative stochastic network (GSN). The adversarial net has the best MNIST score, 225 ± 2 against 214 ± 1.1 for the Deep GSN. On TFD it is second, 2057 ± 26 against 2110 ± 50 for the stacked contractive autoencoder, and those intervals overlap: 2110 − 50 = 2060 is below 2057 + 26 = 2083. The error bars mean different things on the two datasets, standard error across test examples on MNIST and across folds on TFD, with σ\sigma chosen per fold.

Figure 9 · Table 1
Parzen-window log-likelihood (higher is better) with the paper’s error bars. The adversarial net is first on MNIST. On TFD the stacked CAE leads and the gap to GAN is inside the error bars. Toggle the dataset.

The paper claims only that its samples are “at least competitive” and makes “no claim that these samples are better than samples generated by existing methods.” Theis, van den Oord and Bethge (2015) later showed that Parzen estimates can rank models differently from other likelihood estimates and concluded they “should generally be avoided.” The paper’s stronger evidence is qualitative. Its Figure 2 shows samples that are “fair random draws, not cherry-picked”, with the nearest training example beside each to show the model has not memorized the training set. Because sampling is one forward pass rather than a Markov chain, the samples are uncorrelated. Figure 3 of the paper shows digits from linear interpolation between points in z\mathbf{z} space.

Limits and what came after

The paper names two disadvantages. There is no explicit representation of pg(x)p_g(\mathbf{x}), so a GAN cannot score how probable an image is. And DD must be kept synchronized with GG during training, the condition behind the Helvetica scenario. The advantages it lists are that Markov chains are never needed, only backpropagation is used to get gradients, no inference is needed during learning, and any differentiable function can serve as GG. It also suggests a possible statistical advantage from the generator being updated only through the discriminator’s gradients, never directly with data examples, and separately notes that adversarial nets can represent “very sharp, even degenerate distributions,” where Markov-chain methods need blurry ones so their chains can mix between modes.

Section 7 lists extensions, and the first became its own paper within months: a conditional model p(x∣c)p(\mathbf{x} \mid \mathbf{c}) obtained by feeding c\mathbf{c} to both G and D (Conditional GANs, November 2014). The others are an inference network that predicts z\mathbf{z} from x\mathbf{x}, models of every conditional p(xS∣xSˉ)p(\mathbf{x}_S \mid \mathbf{x}_{\bar S}) with shared parameters, semi-supervised learning from discriminator features, and better ways to coordinate G and D or better distributions to sample z\mathbf{z} from during training.

DCGAN (November 2015) found convolutional architectures and training settings that made image GANs train reliably. Wasserstein GAN (January 2017) replaced the implicit JS objective with the Earth-Mover distance, whose gradient does not vanish when the two distributions barely overlap, which targets the flat region of Figure 3. Progressive growing (October 2017) and StyleGAN (December 2018) scaled the same game to high-resolution faces. From 2021, diffusion models overtook GANs on many image benchmarks; Diffusion Models Beat GANs on Image Synthesis reported better FID than the best GANs on ImageNet, with a single network trained on a denoising objective and no second player. GANs remain in use where one-pass sampling speed matters.

Provenance Verified against primary literatureHow we verify
Goodfellow et al. (2014)Value function (1), optimal discriminator (2), C(G) = −log 4 + 2·JSD (4)–(6), Proposition 2, the non-saturating swap, Algorithm 1 with k = 1 and momentum, Table 1, the Helvetica scenario.
Official code (goodfeli/adversarial)mnist.yaml: 100-d uniform noise on [−√3, √3], G 1200-1200 ReLU to 784 sigmoid, D two maxout layers (240 units, 5 pieces), batch 100, lr 0.1, momentum 0.5 to 0.7. __init__.py 323-362: g_obj is −log D(G(z)); 382-427: both gradients returned for one update.
Goodfellow (2016 tutorial)The zero-sum / Nash equilibrium / saddle-point vocabulary and the V(x, y) = xy orbit.
Arjovsky & Bottou (2017)With an optimal D, the non-saturating generator gradient equals ∇[KL(p_g‖p_data) − 2·JSD(p_g‖p_data)] (Theorem 2.5).
Mescheder et al. (2018)Absolute continuity is necessary for local convergence; unregularized GAN training on manifold data is not always convergent.
Theis, van den Oord & Bethge (2015)Parzen-window log-likelihood estimates “should generally be avoided”.
Lin (1991)JSD ≤ log 2, which gives the ceiling C(G) ≤ 0. The paper states only the −log 4 minimum.
correctionFour common statements about this paper need correcting. (1) “GANs minimize the Jensen-Shannon divergence” holds for the original saturating loss against an optimal discriminator. The non-saturating loss that the paper recommends and its own code trains follows the gradient of KL(p_g‖p_data) − 2·JSD instead (Arjovsky & Bottou 2017). (2) Proposition 2 proves that the distribution p_g converges to p_data in function space, assuming unlimited capacity and an optimal D at every step. It does not prove that the network weights converge, and the paper says optimizing θ_g “introduces multiple critical points in parameter space”. (3) Algorithm 1 prints k alternating discriminator steps and a generator step on log(1 − D(G(z))). The released MNIST code trains the generator on −log D(G(z)) and applies both players’ gradients in one simultaneous update. Algorithm 1 also names the noise prior p_g(z); it is p_z(z). (4) The words “Nash equilibrium”, “saddle point”, “zero-sum” and “mode collapse” are not in the 2014 paper, which says “two-player minimax game” and “the Helvetica scenario”; they come from later work, cited above. Table 1 is also often summarized as a GAN win: GAN is first on MNIST only, and second on TFD.

Questions you might still have

?

If the generator never sees a real image, how does it learn?
Through the discriminator’s gradient. The discriminator is trained on real images and fakes. The generator’s loss is a function of the discriminator’s output on its fakes, so backpropagation through the frozen discriminator gives each fake a direction in pixel space that raises D’s score, and the chain rule carries that into G’s weights. The paper notes this means components of the training data are never copied directly into the generator’s parameters.

?

Does GAN training minimize the Jensen-Shannon divergence?
Only in the idealized case the paper analyzes: the original loss log(1 − D(G(z))), with D at its optimum before every generator step, in the space of distributions. The non-saturating loss used in practice has the same fixed point but a different gradient, equal to the gradient of KL(p_g‖p_data) − 2·JSD at an optimal D. The reverse KL term penalizes fakes in empty regions heavily and missing modes lightly, which fits the mode-dropping seen in practice.

?

Why not train the discriminator to convergence before each generator step?
The paper gives two reasons: it is computationally prohibitive, and on a finite dataset a discriminator trained to completion overfits. Algorithm 1 instead takes k steps on D (k = 1 in the experiments) and relies on G changing slowly enough that D stays near its optimum.

?

How is a GAN different from noise-contrastive estimation?
Both fit a generative model with a classification criterion. In NCE the model itself is the classifier and it separates data from a fixed noise distribution; the paper notes that learning slows once the model is roughly right. In a GAN the classifier is a separate network and the “noise” it separates from data is the generator’s output, which moves toward the data as training goes on.

?

Why does a discriminator that outputs one half everywhere mean success?
The optimal discriminator is p_data/(p_data + p_g). It equals one half at a point exactly when the two densities are equal there, so a best-possible classifier stuck at one half everywhere implies p_g = p_data. A trained, finite discriminator at one half is weaker evidence, since it may just be unable to see a difference that exists.

?

If a GAN has no likelihood, how do you evaluate it?
The paper fit a Gaussian Parzen window to generated samples and reported test log-likelihood, while saying the estimate has high variance and does poorly in high dimensions. Theis et al. (2015) recommended against it. Later work mostly scores samples instead, for example with FID (Heusel et al., 2017), which compares statistics of real and generated images in a pretrained network’s feature space.

Footnotes & further reading

  1. The paper: Goodfellow, Pouget-Abadie, Mirza, Xu, Warde-Farley, Ozair, Courville, Bengio, Generative Adversarial Nets (Université de Montréal, NeurIPS 2014). Original code (Pylearn2/Theano; see mnist.yaml and __init__.py).
  2. The zero-sum / Nash / saddle-point vocabulary and the V(x,y)=xyV(x,y)=xy orbit, and the description of the non-saturating game as “heuristically motivated, rather than being motivated by a theoretical concern”: Goodfellow, NIPS 2016 Tutorial: Generative Adversarial Networks.
  3. The non-saturating gradient as KL minus twice the JSD: Arjovsky & Bottou, Towards Principled Methods for Training Generative Adversarial Networks (2017), and Arjovsky, Chintala & Bottou, Wasserstein GAN (2017).
  4. When GAN training orbits instead of converging (the manifold, not-absolutely-continuous case): Mescheder, Geiger & Nowozin, Which Training Methods for GANs do actually Converge? (ICML 2018).
  5. Against Parzen-window evaluation: Theis, van den Oord & Bethge, A note on the evaluation of generative models (2015).
  6. Noise-contrastive estimation: Gutmann & Hyvärinen, Noise-contrastive estimation: A new estimation principle for unnormalized statistical models (AISTATS 2010). The JSD bound: Lin, Divergence measures based on the Shannon entropy (IEEE Trans. Information Theory, 1991).
  7. The lineage: Conditional GANs (2014), DCGAN (2015), Progressive growing of GANs (2017), StyleGAN (2018), and Diffusion Models Beat GANs on Image Synthesis (2021).