Beta

Sync to cloud

Uses your current signed-in YoolVi account. A Learn profile is not required.

Upload a snapshot of this browser’s saved lesson work across all subjects, including notes, experiments, journal and review history. Existing guest work is included only when you confirm below. This does not upload account credentials or award XP.

Sync uploads to your private account; it does not automatically merge or replace this device’s work. On another device, download the cloud copy and use My Learning’s backup import. The previous cloud snapshot is retained when a new one replaces it.

Export or import this device’s work

No background uploads. Edits made after a snapshot need another sync. On shared devices, work is bound to the first account observed by cloud sync; another account must use a separate browser profile. Keep your own downloaded backup too.

Learning preferences

Make learning more comfortable. Changes apply immediately.

Enlarges page content, including diagrams and their labels. You can also use your browser’s zoom.

Choose the colours that are easiest for you to distinguish. Applies to lesson diagrams and lab plots. Labels, shapes, hatching and line patterns also distinguish meanings. Source photographs and raw image brightness stay unchanged; mask-only views are available for image overlays.

ExampleComparisonSample link

Saved in this browser on this device. Preferences are separate from progress backups.

Back to Generative Models Beyond Text

Generative Models Beyond Text · Lesson 1 of 2 in this module

Understand adversarial learning

Adversarial learningFixed teaching example — not your saved experiment.
  1. Starting information

    Generated examples and training examples

  2. Relationship or operation

    A discriminator distinguishes; a generator tries to fool it

  3. Consequence

    Two models change in response to each other

Adversarial training couples two objectives. A generator can improve one score while collapsing to a narrow set of outputs.

The idea in everyday terms

A generator proposes samples; a discriminator tries to distinguish them from reference data. The generator learns through the discriminator’s feedback instead of receiving a paired correct sample for each random input.

What to watch in the experiment

Inspect the two models and their changing losses together. Compare the complete generated cloud with the reference groups. A generator can concentrate on a few successful outputs and miss others, while the discriminator’s changing behavior affects the meaning of its score.

What this does not establish

One favorable loss or attractive sample does not establish quality and coverage. These small public coordinate experiments are not evidence of reliable real-image generation.

Full worked explanation, calculations and control definitions

Use this reference for the detailed mechanism and control meanings. Derivations explicitly marked optional are enrichment.

Make examples and learn to distinguish them

Imagine a generator that proposes two-coordinate points and a discriminator that tries to distinguish those proposals from a small reference dataset. A generative adversarial network, or GAN, trains these two models together. The generator does not receive a target point for each proposal. Instead, it receives a gradient through the discriminator’s current judgment.

Our reference has four groups, with 32 training and 32 distinct development points. The generator maps a random two-number Gaussian input z to a point G(z). Its 16 hidden tanh units and linear output contain 82 parameters. The discriminator reads a point and produces a score D(x) between zero and one through a sigmoid. Its 16 hidden units and single output contain 65 parameters. Both are real trained networks; the target centers are never used to snap generated points into place.

The discriminator’s job

The discriminator should score real training examples highly and generated examples low. Its loss uses binary cross-entropy. With N real points and N generated points, the lab minimizes:

LD=−12N∑i=1N[log⁡D(xi)+log⁡(1−D(G(zi)))]L_D=-\frac{1}{2N}\sum_{i=1}^N\left[\log D(x_i)+\log(1-D(G(z_i)))\right]

Here xᵢ is a real training point and zᵢ is a random input. Logs are natural logarithms, so loss is measured in nats. The denominator averages the 2N classification examples. If one real example scores 0.8 and one fake example scores 0.3, their average loss is −(log 0.8 + log 0.7)/2, about 0.290. Confidently wrong predictions cost more.

The implementation uses an algebraically equivalent stable logit calculation, avoiding log zero when sigmoid scores round to endpoints. A discriminator score is about real-versus-generated classification under this training setup. It is not an independent factuality, safety or artistic-quality judgment.

The generator’s job

The original GAN framework describes a minimax game. This lab uses the common non-saturating generator objective, which encourages high discriminator scores without using the minimax generator loss:

LG=−1N∑i=1Nlog⁡D(G(zi))L_G=-\frac{1}{N}\sum_{i=1}^N\log D(G(z_i))

A generated point scoring 0.2 contributes about 1.609; at 0.8 it contributes about 0.223. Minimizing this objective encourages the generator to produce examples that the current discriminator scores as real. The lab explicitly labels this objective rather than treating all GAN variants as identical.

The gradient travels backward through the discriminator to the generated coordinates, then through the generator to its parameters. The discriminator’s weights remain frozen during this generator update. The point inspector shows the gradient of the single-example generator loss with respect to the two generated coordinates. Negating that vector gives a local descent direction. Actual training changes shared generator weights, so it affects many generated points at once; it does not directly drag one displayed point.

Alternate the updates

Each cycle performs either one or five discriminator updates while the generator stays fixed. It then performs one generator update through the updated discriminator, with the discriminator now fixed. Within each update, gradients are computed from the same preceding parameters before any weight is changed. Both networks use Adam at rate 0.01, moment correction and norm clipping at five.

Fresh seeded random inputs are used for training. Fixed random inputs are reused for monitoring. Changing the update ratio restarts both networks from the same initial values, making comparisons easier to interpret. Five discriminator updates per cycle cost more than one; equal cycle counts are not equal training work. Controls cap calls at 25 cycles and the experiment at 2,000 cycles.

Why the loss curve can mislead

In ordinary supervised learning, a fixed evaluation objective makes a falling loss easier to interpret. Here the opponent changes. A stronger discriminator can raise generator loss even while generated examples improve. A weak discriminator can give flattering scores to poor samples. Even a score near one-half does not prove equilibrium: an uninformative discriminator can also output one-half.

Mode collapse means the generator concentrates on too few kinds of output. Our four target groups make this visible. Twenty-four points near one center can look individually plausible while missing three groups. Use the per-mode counts alongside proximity. The fixed-seed history lets you inspect temporary failure, recovery and changing losses without treating any one iteration as a guarantee.

Try the one-update ratio through 1,000 cycles and capture its output. Continue to 2,000 and compare. Then reset with five discriminator updates per cycle. These are exposed teaching cases, not a promise that a particular ratio is generally better. Repeat sampling seeds and report failures, including points outside the plot axes.

Compare a different mechanism honestly

The supplied diffusion reference uses the same training target but a 370-parameter denoiser trained for 1,000 updates. Its checkpoint is reproducible from the repository’s reference-generation script. Loading it does not mean you trained it. Sampling 24 points costs 768 denoiser evaluations, versus 24 generator evaluations for the GAN. Parameter counts, training updates, objectives, backward passes and sampling mechanisms differ, so raw call counts cannot establish equal compute or overall efficiency.

Both outputs are scored against the same four centers using radius 0.45. Count covered modes and failures as well as average distance. These checks do not measure the precise ring distribution, balanced frequencies, memorization or usefulness for another task. The supplied result is public comparison evidence, not an independent final test.

For a guided project, capture two GAN stages with the same seed and compare the diffusion reference. Explain why their losses and call counts cannot be directly ranked as a single quality score. For implementation practice, independently derive one discriminator weight gradient and one generator gradient through a frozen discriminator, then verify with central finite differences. For a decision brief, specify the missing-mode tolerance, failure handling and evidence needed before using a generator.

Return to diffusion training and sampling for its separate objective, or continue to judge a generated distribution.