Classifier-Free Guidance
A trick that makes diffusion models follow the prompt more closely by comparing a prompted and an unprompted prediction and pushing further in the difference.
Also CFG · guidance scale · negative prompt · conditional diffusion
Ho and Salimans, 2022
Ask an artist to draw 'a dog', then ask them to draw 'anything'. Whatever is different between the two sketches is the 'dog-ness'. Exaggerate that difference and the drawing becomes more clearly a dog.
Where it fits
+All relationships as a list
Try it
How it works
A diffusion model conditioned on a prompt sometimes produces images that only loosely match it. Classifier-free guidance sharpens the match.
During training, the prompt is randomly dropped for some examples, so the same network learns both:
- a conditional prediction: “how to denoise toward a corgi on a skateboard”, and
- an unconditional prediction: “how to denoise toward any image”.
At every denoising step, take the difference between the two. That difference points toward “more like the prompt”. Then move further in that direction, scaled by the guidance scale :
- : plain conditional generation.
- around 5 to 10: typical for text-to-image; much better prompt adherence.
- Very high : harsh, oversaturated images that all look alike.
The widget uses this exact formula on a toy 2D dataset: raise the guidance and watch the samples crowd into the chosen class.
It plays a similar role to temperature in sampling from language models: a dial between creativity and faithfulness. Negative prompts reuse the same formula with an unwanted description in place of the empty prompt.
Everyday use cases
- Case 01
The guidance slider in image generators
The "CFG scale" setting in Stable Diffusion tools is this technique.
- Case 02
Negative prompts
Telling the model what not to draw ("blurry, extra fingers") works by guiding away from that description.
Strengths, weaknesses and when to use it
Strengths
- Simple, needs no separate classifier, dramatically improves prompt following.
Weaknesses
- Two network evaluations per step; high scales reduce diversity and look over-processed.
When to use itStandard in text-to-image and text-to-video diffusion. Tune the scale per model.
Compare with
Check yourself
- Q01
What usually happens if you raise the guidance scale a lot?
Show answer
A: Images follow the prompt more but become less diverse and can look oversaturated