Diffusion Models and Brownian Motion
Diffusion Models for Image and Video Generation
1. The basic generation process
Modern image and video generators can transform a prompt into a realistic visual result by repeatedly refining a sample of random noise. In models such as WAN, generation begins by creating a video whose pixel or latent values are random. A neural network—often a transformer—then predicts how the current sample should change. A sampling algorithm applies that prediction, and the process repeats until the sample contains a coherent video.
The network’s prediction is not usually a finished image or video. Early in generation, the sample remains mostly noise, though hints of structure may appear. Over many iterations, these changes gradually produce the requested content.
A useful high-level description is:
Start with random noise.
Use a trained model to estimate a denoising direction or related update.
Apply a sampling rule to modify the current sample.
Repeat, gradually revealing an image or video.
The prompt influences this process through conditioning: information from the text is supplied to the model so that its updates favor content related to the prompt.
2. CLIP: a shared representation of images and text
Image and text encoders
CLIP is made up of two neural networks:
An image encoder, which maps an image to a vector.
A text encoder, which maps text to a vector.
In the described version, each output is a vector of length 512. These vectors lie in a shared high-dimensional space, often called an embedding space or latent space. The goal is to place an image near text that describes it and far from unrelated text.
Contrastive learning
CLIP learns this relationship from batches of image–caption pairs. Suppose a batch contains pictures of a cat, a dog, and a person, alongside captions describing each. The image encoder processes the pictures, while the text encoder processes the captions.
The training objective considers every image–caption pairing in the batch:
A matching pair—such as the cat image and “a photo of a cat”—should have high similarity.
A non-matching pair—such as the cat image and “a photo of a dog”—should have low similarity.
If image vectors form the columns of a matrix and text vectors form its rows, the matching pairs lie on the diagonal. The training objective raises similarity along the diagonal while lowering similarity for pairs off the diagonal. This is called contrastive learning because it teaches the model to distinguish matching pairs from non-matching pairs.
Cosine similarity and embedding geometry
CLIP measures vector alignment using cosine similarity, which is based on the angle between two vectors:
Vectors pointing in the same direction have a cosine similarity of 1. As their directions diverge, their similarity decreases. This lets CLIP represent semantic relationships as geometric relationships in the embedding space.
Concepts as vector directions
Because the embedding space has learned meaningful structure, vector arithmetic can correspond to changes in meaning. For example, let one image vector represent a person without a hat and another represent the same person wearing a hat. Subtracting the first vector from the second gives a vector that captures much of the difference between the images.
To interpret that difference, candidate words can be encoded with the text encoder and compared with the difference vector. In the example, “hat” ranks highly, followed by related terms such as “cap” and “helmet.” The model has encoded a visual change as a direction in its shared space.
This does not mean that every concept is represented as a perfectly isolated direction. Rather, the example illustrates how learned vector geometry can capture useful semantic relationships.
Image classification without a dedicated classifier
CLIP can classify an image by comparing its image vector with text vectors describing possible labels. For example, an image can be compared with captions such as “a photo of a cat” and “a photo of a dog.” The label whose text vector has the highest cosine similarity is selected.
This approach is powerful because the candidate labels can be expressed in language rather than being restricted to a fixed classifier trained for a specific set of categories.
What CLIP does not do by itself
CLIP’s encoders map images and text into a shared embedding space. They do not, by themselves, generate an image from an embedding vector. A generative model is needed to create images or video. Diffusion models provide one way to do this, while text embeddings can help guide their generation.
3. Diffusion as a process of adding and removing noise
Forward corruption and reverse generation
A diffusion model is trained using two related processes:
Forward diffusion: noise is added to training images or videos until their original structure is obscured.
Reverse generation: a learned model guides a noisy sample toward a sample resembling the training data.
In a simplified conceptual description, the forward process gradually corrupts an image, and the reverse process tries to undo that corruption. The reverse process begins from random noise, which is then refined into an image or video.
The forward process is often written conceptually as adding scaled Gaussian noise to a clean sample x0:
Here, xt is the noisy sample at time or step t, αˉt controls how much of the original sample remains, and ϵ is random Gaussian noise. As noise increases, the contribution of the original sample decreases.
Why “remove one step of noise” is an incomplete picture
A simple first guess is that the model is trained to undo the forward process one step at a time: given the sample at step t, predict the sample from step t−1. However, this is not the central training target in the influential DDPM approach.
Instead, DDPM training corrupts a clean training example and trains the model to predict the total noise that was added to it. The model learns a relationship between a noisy sample, the diffusion time, and the noise associated with that sample. At generation time, a sampling algorithm uses the model’s prediction to update the sample step by step.
This target may seem harder than predicting only a small change. A geometric perspective helps explain why it can work well.
4. The connection to Brownian motion and vector fields
Images as points in a high-dimensional space
An image can be represented as a point in a space with one dimension for each pixel value. A video can be treated similarly, with dimensions corresponding to the values across its frames. Real images occupy structured regions of this high-dimensional space rather than appearing uniformly at random.
A simplified example uses images with only two pixels. Each image becomes a point with coordinates given by the two pixel intensities. A collection of such images might form a spiral in a two-dimensional plot. The spiral stands in for the structured distribution of real images.
Adding noise as a random walk
Adding random noise changes pixel values by random amounts. In the two-dimensional example, that is equivalent to taking a random step in the plane. Repeated noise additions make the point follow a random walk.
This resembles Brownian motion, the random movement of particles associated with physical diffusion. The name diffusion model reflects this connection: the forward process spreads samples through random motion, and generation attempts to move samples back toward structured data.
The connection is more than an analogy. Thinking about diffusion through probability distributions and their motion gives useful ways to understand and design generation algorithms.
Learning a time-dependent direction
A model can be viewed as learning a vector field: for each current point, it predicts a direction in which the point should move. In image generation, the input is not literally a two-dimensional point, but the same idea applies in a much higher-dimensional representation space.
For the spiral example, the model sees noisy points produced from different starting locations. On average, those points have moved away from the spiral. The model can learn directions that guide them back toward regions where the original data is more likely.
The learned direction depends on how much noise has been added. Far from the original data distribution, the useful direction may point broadly toward its center. Closer to the data, the direction can reflect finer details of its structure.
Predicting total noise and reducing training variance
In the random-walk picture, predicting the total noise added across a long walk corresponds to predicting the displacement from the original point to the noisy point. Predicting the final small step of the walk and predicting the total displacement are related: under the described diffusion setup, the expected final-step prediction is mathematically equivalent to the total-noise prediction divided by the number of steps.
Predicting total noise can give the model a more stable learning target. Individual random steps vary substantially, but the overall displacement contains a clearer signal about how the noisy point relates to the original data. This helps explain why directly learning to predict noise can be more efficient than training only on isolated one-step changes.
The score function
A learned direction that points toward more likely, less noisy data is related to a score function. Informally, the score indicates how the probability of a sample changes as the sample moves through the space. In a diffusion model, it provides a way to guide noisy samples toward regions that better match the data distribution.
Why time must be an input
The useful direction for a noisy point changes as diffusion proceeds. A point at a high noise level may need a broad correction toward the data distribution, while a point at a low noise level may need a precise correction toward a particular feature or structure.
A model therefore receives both the current sample and a time variable. Denoting the model by f, its prediction can be written schematically as:
Conditioning on t lets the model learn different behavior at different noise levels: broad structure at high noise and increasingly refined detail as the sample approaches the data distribution.
5. Why DDPM adds random noise during generation
Sampling from a distribution, not just following a prediction
The DDPM generation procedure includes random noise at each reverse step. This may seem counterintuitive: if the goal is to remove noise, why add more?
The key is that the model’s prediction represents the mean of a distribution of plausible reverse updates, rather than a complete description of every possible update. In the stated setup, the reverse transition is Gaussian for sufficiently small steps. The model predicts the mean of that Gaussian, and added zero-mean Gaussian noise allows the sampler to draw a sample from the distribution around that mean.
The reverse process can therefore be thought of as combining two effects:
movement guided by the model’s learned direction;
random variation around the model’s predicted mean.
Why removing the random steps can blur results
If the random component is removed from the DDPM update while keeping the rest of that procedure unchanged, many samples can collapse toward an average region of the data.
In the spiral example, reverse trajectories without random steps move toward the center and then toward a similar part of the spiral. With random steps, the trajectories spread out and can reach different parts of the spiral.
In image space, averages of different plausible images often look blurry. If one region of a data distribution corresponds to varied desert-tree images, collapsing toward an average can produce an indistinct result rather than a specific, realistic tree.
The exact analogy between the two-dimensional spiral and image space is limited. In particular, landing on the spiral does not guarantee that an image-space sample has reached the manifold of realistic images. The toy example nevertheless shows why collapsing many trajectories toward an average can reduce variety and produce blur.
6. DDIM: deterministic generation with fewer steps
From a stochastic differential equation to an ordinary differential equation
The DDPM reverse process can be described using a stochastic differential equation (SDE). An SDE includes both a learned, directed movement and a random component. In schematic form:
Here, v(x,t) represents model-guided motion, while the term involving dWt represents random motion.
A result from statistical mechanics, expressed through the Fokker–Planck equation, describes how the distribution of many such points changes over time. The described theory shows that a deterministic ordinary differential equation (ODE) can produce the same evolving distributions as the stochastic process, even though individual trajectories need not be the same.
A schematic probability-flow ODE can be written as:
The important idea is that randomness does not have to be added at every generation step to obtain the same final distribution of samples. A different update rule can transport samples deterministically.
DDIM sampling
DDIM is a sampling approach with a similar overall structure to DDPM but without random noise addition at every step. It uses a different scaling for the step sizes. The size of each step matters: removing noise from the original DDPM update without changing the update rule can cause collapse, while DDIM’s update scaling helps trajectories follow the learned vector field and reach the data distribution more effectively.
DDIM has several practical properties:
It can generate high-quality images without adding random noise at each step.
It can use significantly fewer steps than the original DDPM sampling approach.
It does not require changing the model’s training procedure.
It is deterministic for a given starting sample and sampling configuration.
The deterministic and stochastic procedures are expected to reproduce the same distribution of final samples, not necessarily the same individual image. DDIM can also support faster sampling because it does not need to use as many iterative steps to achieve good results.
Flow matching
Flow matching is a related family of approaches that learns a vector field for transporting samples from a simple distribution, such as noise, toward the data distribution. It generalizes the idea of using a learned flow to move samples. The described WAN video model uses a generalization of DDIM called flow matching.
7. Using text to guide image and video generation
Conditioning with text
A text prompt can be encoded into a vector and supplied to a diffusion model alongside the noisy image or video sample. The model is trained on image–caption or video–caption pairs so that the text helps it predict how to update the sample.
This is called conditioning: the model’s output depends on additional information, such as the prompt or diffusion time. Conditioning on time is essential for handling different noise levels; conditioning on text helps steer the sample toward the requested content.
Text can be incorporated in different ways. For example, models may use:
Cross-attention, which lets image or video features interact with text features.
Directly added or appended text embeddings.
Multiple ways of providing text information at once.
Conditioning can improve prompt relevance, but it does not always ensure that every requested object or detail appears. The model still has to balance general image realism with the prompt’s specific instructions.
UnCLIP and DALL·E 2
One strategy combines a CLIP text encoder with a diffusion model trained to generate images consistent with CLIP image representations. In this approach, the text embedding guides generation toward an image representation associated with the prompt. This style of method was called unCLIP and is associated with the commercial model name DALL·E 2.
The broader principle is that a text encoder can provide a representation of the requested content, while a generative model turns that guidance into an image.
8. Classifier-free guidance
Separating general realism from prompt-specific direction
Conditioning alone asks one model to learn both:
how to generate samples that generally resemble the data; and
how to move toward a particular class or prompt.
These goals can compete. In the spiral example, different portions of the spiral represent different image classes. A class-conditioned model can point a sample toward the desired region, but the general tendency to move toward the data distribution may dominate. As a result, some samples do not reach the correct class-specific region.
Classifier-free guidance addresses this by using two model predictions:
An unconditioned prediction, produced without class or text information, which points toward the data distribution in general.
A conditioned prediction, produced with the desired class or prompt, which combines general data structure with a preference for the requested content.
The difference between these predictions isolates a direction more specific to the condition. Guidance amplifies that direction so the sample is pushed more strongly toward the requested class or prompt.
A common formulation for the guided prediction is:
Here, ϵuncond is the unconditioned prediction, ϵcond is the conditioned prediction, and s is the guidance scale. At s=1, this expression gives the conditioned prediction; larger values amplify the difference between conditioned and unconditioned predictions. Implementations may use different parameterizations or scale conventions.
Training without a separate classifier
The model need not be trained as two completely separate networks. During training, the class or text condition can be omitted for a subset of examples. The model then learns both conditional and unconditional behavior, allowing the two predictions to be obtained from the same model.
Guidance strength and trade-offs
As the guidance scale increases, the model follows the prompt-specific direction more strongly. This can make requested objects appear more clearly and with greater detail. For example, a weakly conditioned desert scene may contain a shadow but omit the requested tree; stronger guidance can make a tree appear and become more distinct.
Guidance is a means of steering generation, not a guarantee that every prompt will be followed perfectly. Increasing its strength changes the balance between general data realism and prompt-specific features.
9. Negative prompts
Some video-generation systems extend guidance by using a negative prompt: text describing features the user wants to avoid. The model encodes this unwanted content, and its prediction can be subtracted from or contrasted with the positively conditioned prediction. Amplifying the resulting difference steers generation away from the unwanted features.
A negative prompt might describe visual defects or actions that should not occur. This approach applies the same broad principle as classifier-free guidance: compare predictions with different conditions, then use their difference to control the direction of generation.
10. Core ideas to retain
Diffusion turns noise into an image or video through a sequence of model-guided updates.
The forward corruption process resembles Brownian motion, while generation learns to guide samples back toward structured data.
CLIP learns a shared embedding space for images and text through contrastive training.
Diffusion models learn noise-related predictions and use a time-dependent vector field to guide samples at different noise levels.
DDPM uses stochastic reverse steps; the added randomness allows sampling around the model’s predicted mean and helps preserve diversity.
DDIM uses a deterministic alternative with different step scaling and can generate high-quality images in fewer steps without retraining.
Text conditioning supplies prompt information to the generative model, while classifier-free guidance amplifies the direction that distinguishes a conditioned prediction from an unconditioned one.
Negative prompts extend this comparison to steer generation away from specified features.

Ask anything
We've read this whole study set, so questions about it get the best answers.