Machine learning · extension lesson
Diffusion: from noise to samples
How can AI make a new image starting with random noise? Begin with a smaller example: a scattered cloud of dots. Repeated small adjustments can turn it into a new cloud with a familiar pattern.
No coding or equations needed for the first experiment. This browser lab uses a known mathematical rule, not a trained image model. Each dot is a pair of numbers, not a pixel.
The image-making story
Illustrative A storyboard of a common diffusion approach; no images are generated here.
- 1. Practise with examples
Add different amounts of noise to training images. Use the added noise as a known target for the model’s predictions.
- 2. Start a new sample
Begin with fresh random noise. There is no original clean image hidden inside it waiting to be restored.
- 3. Apply small updates
Use the model’s predictions repeatedly to form a new image. Resemblance to training patterns does not guarantee accuracy or originality.
Can scattered dots form three groups?
The example cloud has three groups. Predict what will happen to a fresh cloud as we apply more adjustments: will it copy every example dot, or form a similar overall pattern?
Compare the example with the new cloud. Choose “Apply more adjustments” and watch the new cloud change. The example stays fixed.
Known mathematical rule · no neural network is trained here. This simplified three-group pattern cannot demonstrate image quality. Finite steps and a random starting cloud leave some error.
Live · 0 of 80 adjustments applied. The fresh cloud starts scattered around the middle.
Synthetic · 240 dots arranged in three soft groups.
Live · A separate cloud, adjusted by a fixed mathematical rule.
The dashed rings mark the three example groups; dots can fall outside them. The plotting area stays fixed. Optional details include counts and any dots outside the plot.
The takeaway: forming a similar pattern is different from recovering the original dots. More adjustments change this sample; they do not provide more training.
Explain it to someone else
Imagine using new starting noise for a picture of a bicycle. Why could the resulting bicycle look different, even with the same model and instructions? Explain why the process is not simply uncovering one hidden photograph.
Compare your explanation
Different starting noise can lead to different samples. Repeated updates use patterns from training; they do not have a particular original photograph to recover. Training data can still be memorised or reproduced, so this mechanism alone is no guarantee of originality.
Optional: the maths and what real training adds
To add noise here we use xₜ = √a x₀ + √(1 − a) ε, where a = exp(−t). The original point is x₀, ε is standard Gaussian noise, and t is noise time. The optional slider keeps the same noise draw at every level; it is not a random-walk trajectory.
A direction for each noise level
A score is the gradient of log probability density: a direction in coordinate space toward increasing density at the current noise level. It is a vector, not a confidence percentage. At high noise, the three clusters overlap heavily. As noise decreases, separate regions emerge.
Our three-cluster distribution is known, so its score can be calculated directly. For each point, the calculation weights each cluster’s pull by how much that cluster contributes to density there. This is an illustrative analytic denoiser, not a trained neural network.
The reverse sampler follows a probability-flow ordinary differential equation. For this noise schedule, dx/dt = −(x + score(x,t))/2. We integrate backwards, so a step of size h updates x ← x + h(x + score)/2. This deterministic sampler adds no new random noise after its initial draw. Other diffusion samplers use stochastic reverse updates.
The exact continuous flow has the corresponding diffusion marginals when started from the correct terminal distribution. Our finite Euler steps and approximate Gaussian start introduce error. Source: Song et al., Score-Based Generative Modeling through Stochastic Differential Equations.
What learning adds
For real images, the data density is unavailable as a simple formula. A common training procedure samples a clean image, chooses a noise level, adds known Gaussian noise and asks a neural network to predict that noise from the noisy image and its noise level. Squared prediction error supplies a training loss; backpropagation updates the weights over many examples.
Under this Gaussian corruption, the optimal noise prediction corresponds to a score through score = −predicted noise / √(1 − a) at positive noise levels. The training target is known because the noise was generated during training. At generation time there is no clean target image to compare against: a sampler repeatedly uses the trained predictions.
Image systems may use convolutional networks or transformers, and may operate on compressed representations. Conditioning can guide generation using text or other inputs. None of those capabilities, or evidence of image quality, is demonstrated by this point-cloud lab.
Source: Ho et al., Denoising Diffusion Probabilistic Models.