Multimedia & Machine Learning Algorithms · Multimedia Algorithms
Diffusion Models and Transformers
Explanation
Diffusion Models — DDPM
Idea: gradually destroy an image by adding Gaussian noise, then learn to reverse the process.
Forward process:
Shortcut — sample directly from :
where , .
Therefore:
As : so — pure noise.
Training objective:
The model learns to predict the added noise :
Sampling (Reverse): start from and iteratively denoise for .
Transformer — Self-Attention
Idea: each token asks "how relevant am I to every other token?".
Each token is represented in three spaces: Query , Key , Value .
Scaled Dot-Product Attention:
- : similarity score between every pair of tokens.
- : scale factor — prevents large scores from saturating the softmax.
- : converts scores to probabilities (weights summing to 1).
- : information values; the output is a weighted average of all Values.
Multi-Head Attention:
Run attention heads in parallel (in different subspaces) and concatenate:
Positional Encoding:
Transformers have no notion of order — Positional Encoding adds it:
At position : for all sine/cosine dimensions.
Diffusion + Transformer = Stable Diffusion / DALL-E
Modern models combine:
- U-Net/Transformer as the denoiser .
- CLIP for text conditioning: .
- Classifier-Free Guidance: .
Idea: gradually destroy an image by adding Gaussian noise, then learn to reverse the process.
Forward process:
Shortcut — sample directly from :
where , .
Therefore:
As : so — pure noise.
Training objective:
The model learns to predict the added noise :
Sampling (Reverse): start from and iteratively denoise for .
Transformer — Self-Attention
Idea: each token asks "how relevant am I to every other token?".
Each token is represented in three spaces: Query , Key , Value .
Scaled Dot-Product Attention:
- : similarity score between every pair of tokens.
- : scale factor — prevents large scores from saturating the softmax.
- : converts scores to probabilities (weights summing to 1).
- : information values; the output is a weighted average of all Values.
Multi-Head Attention:
Run attention heads in parallel (in different subspaces) and concatenate:
Positional Encoding:
Transformers have no notion of order — Positional Encoding adds it:
At position : for all sine/cosine dimensions.
Diffusion + Transformer = Stable Diffusion / DALL-E
Modern models combine:
- U-Net/Transformer as the denoiser .
- CLIP for text conditioning: .
- Classifier-Free Guidance: .
Interactive Visualization
Loading visualization
Worked Examples
Practice
Exercise 1 of 6
1
What happens to image after steps of the forward diffusion process (for large )?
★Quiz
Test your knowledge from this lesson
A mix of questions from the lesson — each attempt varies slightly
Answer at least 4 out of 5 questions correctly to pass (70%)