Open this lesson in your favourite AI. It'll walk you through the why, explain the demo, and quiz you on the try-it list.
You ask the same question twice and get different answers. That's not a bug — it's sampling. Temperature and top-p control how adventurous the model is when picking each next token. Low = boring and consistent. High = creative and sometimes wrong.
At temperature 0, the model picks the highest-probability token every time. Deterministic-ish. Use for: code, extraction, summarization, classification.
At temperature 0.7, the model samples from a softened distribution. Varied. Use for: brainstorming, creative writing, multiple options.
Top-p (nucleus sampling) caps the distribution to the smallest set of tokens summing to probability p. Top-p = 0.1 means "only consider the very top options"; 0.95 means "consider almost everything."
Rule of thumb: change one at a time. Start at temperature 0.2 for work prompts, 0.7 for creative prompts. Don't touch top-p unless you know why.
If you're using an API or a playground, generate the same creative prompt at temperature 0, 0.3, 0.7, and 1.0. Paste the outputs side by side. Watch the word variety bloom.
Generate three 2-line poems about rain at temperature 0.8 (varied). Then, separately, generate one 2-line poem at temperature 0.1 (conservative). Label them. Tell me in one sentence which setting you'd use for a corporate tagline and why.