Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

Chapter 20 — Assignment Project: Three Ways to Generate Digits

Open in Colab

Overview

A team needs synthetic handwritten digits to test a reading system. You will train the three families of this chapter on the same 1 797 digits, measure what each one produces, and recommend one. Each model trains in a minute or two on a CPU.

PartTaskPoints
AAn evaluation protocol15
BA VAE20
CA GAN20
DA diffusion model20
EComparison and recommendation25

Part A — An Evaluation Protocol (15 points)

Write evaluate(samples) for 1 000 generated digits (an array (1000, 64) in [0,1][0, 1]). It returns a dictionary with:

  1. recognisable: the share of samples that a logistic-regression classifier, trained on the real digits, labels with probability above 0.9;

  2. classes: the number of digit classes that receive at least 5% of the samples (diversity: a collapsed model covers few);

  3. balance: the entropy of the predicted class distribution divided by ln⁡10\ln 10 (1 = perfectly balanced);

  4. novelty: the median distance from each sample to its nearest real digit.

Check it on 1 000 real digits and on 1 000 copies of the mean digit.

What does each number catch, and what does it miss?


Part B — A VAE (20 points)

Train a VAE with an 8-dimensional code (encoder and decoder with one hidden layer of 128 units, 150 epochs, Adam 10-3). Generate 1 000 digits from z∼N(0,I)z \sim \mathcal{N}(0, I), show 12, and evaluate them.


Part C — A GAN (20 points)

Train a GAN (generator 16 → 128 → 128 → 64 with a sigmoid output; discriminator 64 → 128 → 128 → 1 with LeakyReLU; Adam 2×10−42 \times 10^{-4}, β1=0.5\beta_1 = 0.5; label smoothing 0.9; 6 000 steps of batches of 64). Generate, show and evaluate 1 000 digits. Then train it again with two other seeds and report how much the evaluation changes.

How stable is the GAN across seeds?


Part D — A Diffusion Model (20 points)

Train a denoiser (an MLP 65 → 256 → 256 → 64, the step t/Tt/T as an extra input) with T=100T = 100 steps, β\beta from 10-4 to 0.1, on digits scaled to [−1,1][-1, 1], for 8 000 steps of batches of 256. Generate 1 000 digits with the full DDPM sampler and with a 20-step DDIM sampler; show and evaluate both, and time them.


Part E — Comparison and Recommendation (25 points)

  1. One table: for each model, the four numbers of Part A, the training time and the time to generate 1 000 digits.

  2. Which model would you give the team, and why? What would change your answer if they needed 10 million digits a day? Digits of a chosen class?

  3. Name one risk of using synthetic digits to test a reading system.

Your recommendation:

Grading Rubric

CriterionExcellentAdequateInsufficient
A (15)four measures, sanity checks on real and constant data, limits discussedmeasures onlymissing
B (20)trained, samples shown, evaluated and interpretednumbers onlymissing
C (20)three seeds, instability discussedone seedmissing
D (20)both samplers, quality and time comparedone samplermissing
E (25)complete table, a justified choice, scenarios and a risktable onlymissing