Generative AI
Diffusion Models
A reverse sampler generates by repeatedly estimating structure and updating a noisy sample.
Forward process at timestep 0 of 50. Signal power 1.000.
- Training shape
- Generated sample
- Denoiser's guess at x_0
- Variance added per step
- Cumulative signal power
Cursor on the timeline. Between reverse visits, the cloud holds at the last visited frame.
The clean spiral supplies the finite set of possible starting points. Scrub back to zero to see the inputs again.
- beta 0.000
- alpha_bar 1.000
- one closed-form hop
- x_t at t=0
Check your understanding
Diffusion models generate by repeatedly denoising a sample that starts as Gaussian noise. Use a spiral to compare forward noising with the separate reverse sampling process.
Scrub the forward marginal
The spiral is a finite set of clean 2D points. For each point, the lab holds one standard Gaussian draw fixed while you change the timestep. It uses the closed-form marginal from Denoising Diffusion Probabilistic Models.
Each displayed timestep has the correct conditional marginal. The smooth visual sweep is a coupling of those marginals through the same draw. A forward Markov trajectory would use independent innovations at successive transitions. Scrubbing to zero restores the original because the formula still has the clean point.
Compare the schedules
In The Noise Schedule, scrub to the endpoint and switch between Default and Gentle. Beta sets the per-transition noise variance. Alpha-bar is the cumulative multiplier on the clean signal's variance. The fraction of total variance carried by the signal also depends on the clean data's variance.
Gentle increases beta more slowly and retains more signal at the endpoint. Generation still begins with standard Gaussian draws under either schedule, so Gentle makes the starting distribution a poorer match for the forward endpoint.
Inspect the denoiser
The lab assigns equal prior mass to the spiral points. It weighs each candidate by the Gaussian likelihood of the observed noisy point, then uses the weighted mean as its clean estimate. This finite-prior computation stands in for a learned denoiser. The lab fits no network and runs no image model.
Each arrow points from the noisy input to the estimated clean point. Recovery error averages the distance from that estimate to the known original. Guess alignment averages cosine similarity between the implied and actual noise directions for comparable pairs. At zero noise the direction comparison is unavailable. At the default endpoint the input gives a strong clue about the noise direction even when the clean estimate is poor.
Generate from fresh noise
In Generating From Noise, the generated cloud begins with independent Gaussian draws. The spiral remains visible as a reference and supplies the denoiser's prior. Each hop estimates a clean point, blends it with the current point and may add a fresh Gaussian term. Step advances one actual hop. Scrubbing between visits holds the last visited frame. Denoise replays from the start and Resample cycles the starting and transition draws.
For a hop from to , the lab uses the Gaussian bridge coefficients for conditioning on a clean point and plugs in its estimated mean. With :
The exact reverse conditional given only the noisy point would mix over the possible clean points. The toy sampler uses one Gaussian and leaves out that extra spread. Its trajectories, predictions and scores are computed from the selected schedule, budget and seed. The finite spiral, schedule presets and seed cycle are authored teaching choices.
Find the smallest useful budget
Output coverage counts the fraction of spiral points within the lab's radius of a finished sample. Off-shape distance averages the distance from each finished sample to its nearest spiral point. The two scores describe the endpoint even while you scrub earlier frames. A small cluster near the spiral can have a short distance and poor coverage.
Try one hop with the default schedule. At , the fresh-noise scale and the weight on the current noisy point are zero. Each starting draw maps to its own conditional mean, which lands near the spiral centre. Intermediate hops give the sampler room to spread and revise its estimates before that final mean. This result applies to the lab's sampler and schedule. Other diffusion samplers use different updates.
Stage recap
The Clean Structure
The clean spiral supplies the finite set of possible starting points. Scrub back to zero to see the inputs again.
The Forward Process
Scrub the timestep to recompute a noisy marginal from each clean point and its fixed noise draw. Watch the cumulative signal power fall.
The Noise Schedule
Beta is the noise variance added per transition. Alpha-bar multiplies the retained coefficients (1 − beta). Compare the schedules at the same timestep.
The Denoiser's Guess
Each arrow connects a noisy point to its posterior mean clean point. Compare the implied noise direction and the clean-point recovery error separately.
Generating From Noise
Start from fresh Gaussian draws. Step advances to the next visited timestep and Denoise replays the path from the start. Output coverage and Off-shape distance always grade the finished cloud.
Skip the Steps
Compare budgets under the default schedule. One hop returns a conditional mean for each input, with zero fresh noise. Use the coverage challenge to find the cheapest budget that works here.
Reference
- Forward process q(x_t|x_0)
- N(sqrt(alpha_bar_t) x_0, (1 - alpha_bar_t) I). Closed form, so any t is one hop from t=0. Nothing is learned.
- Beta schedule
- Variance added per step. Both schedules rise linearly. Gentle uses a lower terminal beta and retains more structure.
- Alpha bar (alpha_bar_t)
- The running product of (1 - beta). It multiplies clean-data variance, while 1 minus alpha-bar sets the conditional noise variance.
- Optimal denoiser E[x_0|x_t]
- A softmax over the training set weighted by -||x_t - sqrt(alpha_bar) s||^2 / 2(1 - alpha_bar). This posterior mean minimises squared clean-point error under the empirical prior.
- Plug-in Gaussian reverse hop
- Mixes x_t and the guessed x_0, then adds fresh noise of size sigma. Written for any s < t, so a 5-step sampler is a real 5-step sampler over a strided subsequence.
- Why sigma matters
- On the last hop to t=0, sigma is 0 and the mixture weight on x_t is 0, so the output is purely the denoiser mean. One step means the mean is all you get.
Break it on purpose
With the default schedule, one reverse hop gives each input its own conditional mean near the spiral centre. The final coefficients are fromXt=0, fromX0=1, sigma=0. An average is not a sample from the conditional distribution. Two hops also fall short of the coverage target in this toy experiment.
Explore next
- Generative Adversarial Networks (GANs)Change how often the discriminator updates and inspect the loss gradient it sends to each generated output.
- Autoencoder (Bottleneck Compression)Change the bottleneck width and inspect how many shared templates the decoder can use to rebuild an image.
- Transformer DecodingChange the decoding settings and trace how the next-token distribution becomes a sequence.