# What is classifier-free guidance?

The trick that makes image generators follow the prompt. At each step the model predicts with and without the prompt, and the difference is pushed further, by an amount called the guidance scale.

- Page: https://tecyfy.com/concepts/classifierfree-guidance
- Subject: How AI works (https://tecyfy.com/concepts)
- Level: advanced
- Also called: CFG, Classifier-Free Diffusion Guidance

A [diffusion model](https://tecyfy.com/concepts#diffusion-model) makes an image by starting from pure noise and removing a little of it at each of many steps, guided by your prompt. Left to itself, though, it follows the prompt only loosely. Classifier-free guidance is the reason "a red bicycle against a blue wall" actually comes out red and blue. Nearly every text-to-image model uses it, and the "guidance scale" or "CFG scale" setting in image tools controls it.

## The idea in 3 steps

At every denoising step the model makes 2 predictions:

1. What the noise looks like **with** your prompt.
2. What it looks like **without** any prompt.

The gap between them is the effect of the prompt: the direction in which the prompt pulls the image. Guidance takes the prompt-free prediction and moves from it along that direction, and then further, multiplied by the [guidance scale](https://tecyfy.com/concepts#guidance-scale). At a scale of 1 you get the plain prompted prediction. Above 1 the prompt's influence is exaggerated.

## Why "classifier-free"

An earlier method steered images with a separate classifier model that judged, at each step, how much the noisy image looked like the target class. That meant training an extra model that could read noisy images. In 2022 Jonathan Ho and Tim Salimans at Google showed you could skip it. During training, the prompt is simply dropped some of the time, so one model learns both the prompted and the unprompted prediction. At generation time you ask it for both and combine them.

## Turning the dial

- **Low scale:** more varied, natural images that may drift away from what you asked.
- **Medium scale:** what most tools default to, a balance of following the prompt and looking natural.
- **High scale:** follows the prompt closely, but colours oversaturate and odd artefacts appear.

It is a trade between faithfulness and quality, much as [Temperature](https://tecyfy.com/concepts/temperature) is for text.

## Negative prompts ride on it

A [negative prompt](https://tecyfy.com/concepts#negative-prompt) replaces the "without any prompt" prediction with a prediction for the things you do not want, such as "blurry, extra fingers". Guidance then pushes away from those as well as towards your prompt. That is why negative prompts only work in models that use this kind of guidance.

## What it costs

2 predictions per step means about twice the compute per image. Some newer models are trained ("distilled") to give guided results in a single prediction, which is why their tools ask you to keep the guidance scale at a low, fixed value.

## Related

- [Diffusion Model](https://tecyfy.com/concepts#diffusion-model): A generative model that iteratively denoises data starting from random noise
- [Guidance Scale](https://tecyfy.com/concepts#guidance-scale): A hyperparameter controlling the strength of conditional guidance in diffusion sampling.
- [Negative Prompt](https://tecyfy.com/concepts#negative-prompt): Text describing what the model should avoid generating, used in diffusion or text‑to‑image pipelines.
- [Stable Diffusion](https://tecyfy.com/concepts#stable-diffusion): An open‑source latent diffusion model for text‑to‑image generation
- [Latent Diffusion](https://tecyfy.com/concepts#latent-diffusion): A diffusion process applied in compressed latent space.

## Sources

- [Classifier-free diffusion guidance](https://arxiv.org/abs/2207.12598)
- [Text-to-image, guidance scale and negative prompt](https://huggingface.co/docs/diffusers/using-diffusers/conditional_image_generation)
