Diffusion · Chapter 8 · Lesson 8.3

Forger vs Detective

Two little brains play a game. The forger makes fake dots. The detective tries to catch them. Each one gets better because of the other. First, you be the detective!

Hi! Pick a dot pattern on the right. Robo is getting the forgery lab ready…

1. You be the detective

Is this dot real or forged? round 1 / 10
Getting ready…
real example dotsthe mystery dot (the ringed one)

2. Watch them learn

The forger's dots practice 0
real dotsforged dotswhere the detective thinks "real"

Checkpoints

Tap a card to see the forger's earlier fakes.
Press Robo, train both! to save the first checkpoint.

What's happening inside

The detective

Shown real dots and forged dots. It has to say which is which.

The forger

Starts from random numbers and turns them into dots. It never sees the real ones!

The forger never peeks at the real dots. Its only teacher is the detective's opinion, shown as the hint arrows: "move this way to look more real."

3. When the game goes wrong

Each button starts a fresh run with a setting that provokes a famous GAN problem. The chart marks the moment it happens.

Pick a challenge. I will explain what to look for.

How it works

The forger makes fakes

It starts with random numbers and turns them into dots. At first they are just a smudge in the middle.

The detective guesses

It sees real dots and forged dots, says "real" or "fake" for each, and learns from its mistakes.

The detective gives hints

Its opinion slopes up towards "looks real". Those slopes are the arrows the forger follows.

Take turns, again and again

A better detective makes better hints. Better fakes make the detective work harder. Both improve together.

What just happened?

For grown-ups: what's really going on
  • A real GAN, in your browser. A generative adversarial network (Goodfellow et al., 2014) trained live in plain JavaScript with hand-written backprop. The generator is an MLP 4 → 24 → 24 → 2 (tanh hidden, linear output) that maps Gaussian noise z to a 2-D point. The discriminator is an MLP 2 → 24 → 24 → 1 with a sigmoid output giving P(real). Both use Adam (β₁ = 0.5, gradient clipping), batch 64 real + 64 fake.
  • The minimax game. minG maxD E[log D(x)] + E[log(1 − D(G(z)))]. With a perfect discriminator the generator minimises the Jensen-Shannon divergence between data and model. At the ideal equilibrium D = ½ everywhere, which is why the "detective right" line hovers near 50%.
  • Non-saturating loss. "Classic" minimises log(1 − D(G(z))), which has a vanishing gradient when D confidently rejects fakes. "Smarter" maximises log D(G(z)) instead (the non-saturating heuristic from the original paper): same fixed point, strong gradient early. In the super-strong challenge the forger starts far from the data; in our runs the classic rule stayed stuck while the smarter rule recovered. This is a demonstration on a toy, not a proof.
  • Mode collapse. With a fast generator and a slow discriminator the generator can hop between a few modes the discriminator currently under-penalises. The chart uses a fixed noise set, so you see the same fakes move over time. We report how many of the real blobs hold forged dots. It is seed-dependent, which is typical.
  • Instability. GAN training is a two-player game, not a single falling loss, so there is no number that just goes down. Real systems use tricks such as spectral normalisation, WGAN-GP, two-timescale updates and careful balance. Some datasets here (spiral, sometimes heart) are unreliable for this tiny network and are labelled.
  • Why the dist metric. "Fakes off by" is the mean distance from each forged dot to its nearest real sample (lower is better). It can look good during mode collapse, so coverage of the blobs is checked as well.
  • Deepfakes and diffusion. Face-swap and "deepfake" images of the late 2010s were largely GANs (StyleGAN and friends). Diffusion models largely replaced them for image generation because they train with a plain regression loss (no adversary, so no mode collapse or balancing act), cover the data distribution better, and scale well with text conditioning. GANs are still fast, since one forward pass makes a sample.