Skip to content
AI360Xpert
Beta
Playgrounds

Generative AI

Generative Adversarial Networks (GANs)

The generator never sees the real data. Everything it learns arrives as a gradient from the discriminator, and that signal is the whole channel between them.

Stage 1 of 6: The Real Distribution

Data space (x, y)

Round 0. The generator populates 0 of 2 real clusters, with mean distance 1.002 to the nearest real sample and 63 percent of its samples nearer the left cluster.

  • Real sample
  • Generated sample
  • Field: scored as real
  • Field: scored as fake
  • Gradient sent to the generator
  • Discriminator loss
  • Generator loss
Modes covered0Modes covered: 0
Realism1.002Realism: 1.002

Two clusters, one at x = -0.5 and one at x = +0.5. Modes covered counts how many of them the generator currently populates, and it starts at 0 of 2 — the generator has not been trained.

  1. real vs fake
  2. D updates ×1
  3. signal 0.026
  4. G follows it
  5. 0 of 2 clusters

Check your understanding

A forger who has never seen a real banknote, learning only from what a critic tells it. Watch the gradient that carries every lesson between them, then cut the wire and see the whole thing stop.

The asymmetry that makes a GAN strange

Two networks, and only one of them ever sees the data.

The discriminator gets both batches — 40 real samples and 40 fakes — and learns to tell them apart. Ordinary supervised learning.

The generator gets nothing. It is handed 40 Gaussian latent codes, turns them into 40 points, and is never told where the real clusters are, how many there are, or whether it is close. Everything it will ever learn about the data arrives as one vector per sample: ∂L/∂x\partial L / \partial x at its own output, backpropagated through the critic.

That vector is the whole channel, and it is what this lab draws.

The critic's field

At the Discriminator stage the shaded background is a real forward pass at 400 grid positions — the critic's score for how real each point in the plane looks. Pale shading is a near coin flip; strong shading is confidence.

Press Step and watch it sharpen. It is doing the easy job: the fakes start in a blob well below both clusters, and separating them takes a couple of rounds.

The signal

At the Signal stage every second generated point sprouts an arrow. That arrow is the direction the critic's score rises fastest at that point — the direction the generator will move it, and the only instruction it receives.

Signal to G is the mean length of those arrows. Two things about it are worth watching:

It is not constant. Early on the arrows all point the same way, up towards the clusters, because the critic has learned little more than "real things are up there". As training proceeds they fan out and shorten, because the critic starts caring about which cluster and how far in.

It can be exactly zero. Not small — zero. The critic's four hidden units are ReLUs, and a ReLU that is off passes nothing back at all. When all four are inactive at a generated point, the chain of products contains a literal 00, and that sample receives no instruction whatsoever. Its arrow does not shrink; it disappears.

What a tie looks like

At the Adversarial Loop stage both networks train, one round at a time, and the second panel shows both losses.

They do not go to zero. They converge on 0.693, which is ln⁡2\ln 2, which is −log⁡(0.5)-\log(0.5) — the loss of a coin flip. That is the point of the whole construction: the objective

min⁡Gmax⁡D  Ereal[log⁡D(x)]+Ez[log⁡(1−D(G(z)))]\min_G \max_D \; \mathbb{E}_{\text{real}}[\log D(x)] + \mathbb{E}_z[\log(1 - D(G(z)))]

is a saddle point, not a minimum. Neither player is trying to win. A discriminator loss near zero is not success, it is one player having run away with the game, and the quiz asks you about exactly that.

Two readouts grade the generator, and it takes both:

Modes covered is how many of the two clusters actually have samples on them — a diversity measure. Realism is the mean distance from each fake to the nearest real point. Neither works alone: a generator piled entirely onto the left cluster scores excellent realism and covers one mode, and an untrained one also covers one or zero modes but sits nowhere near the data. One number could not tell those two apart.

Expect a detour on the way. The generator usually overshoots past the clusters before settling — far enough that some samples leave the frame, which the scene shows by pulling them onto the edge and dimming them rather than letting them vanish.

Break it: starve the generator

Algorithm 1 of the original GAN paper runs kk discriminator steps for every one generator step, and sets k=1k = 1. That looks needlessly timid. The critic is the easier network to train, and letting it get good first sounds like it ought to help.

The Discriminator steps per round slider is that kk. Take it up.

At 12 steps per round the generator never populates the second cluster — not on any of the eight seeds available through Reseed. Signal to G falls to 0.0000 and the arrows go out. The generator is not losing the game; it has been disconnected from it. A critic that is already certain about every fake has no gradient left to hand back, and a teacher who is always right teaches nothing.

The boundary is sharper than it looks. At 1 and 2 steps every seed ends up covering both clusters. At 3, one of the eight never does — which is worse than a clean failure, because it looks like luck. That is the honest reason the paper picked 1.

Reference

Objective
min_G max_D V(D,G) = E_real[log D(x)] + E_z[log(1 - D(G(z)))]. A saddle point, not a minimum — which is why neither loss falling is good news on its own.
Discriminator loss
Binary cross-entropy over the real batch (target 1) and the fake batch (target 0), averaged over both. Near 0 means it is winning; near ln 2 means it cannot tell.
Generator loss (non-saturating)
Minimise -log D(G(z)) rather than maximise log(1 - D(G(z))). Same fixed point, but the gradient does not vanish while the generator is still bad.
The signal
dL/dx at each generated point, backpropagated through the discriminator. The generator never touches the real data; this vector is all it gets.
ln 2 = 0.693
The equilibrium value for both losses. D outputs 0.5 everywhere because the two distributions have become indistinguishable.
k, steps per round
Discriminator updates per generator update. Algorithm 1 of Goodfellow et al. sets k = 1; this lab lets you raise it and watch why they did not.

Break it on purpose

Raise Discriminator steps per round. At 12 steps the generator never populates the second cluster on any of the eight seeds, and at 3 it already loses one of them; at 1 or 2 steps every seed ends up covering both. The mechanism is the signal, and it is exact rather than gradual. Given several updates between the generator's turns, the discriminator becomes confident enough that every one of its hidden ReLU units is inactive at the generated points — so the gradient it hands back is not small, it is exactly zero. Watch Signal to G reach 0.0000 and the arrows disappear. A generator receiving nothing cannot move, so whichever cluster it happened to be nearest is where it stays. This is why the original GAN paper sets k = 1.