GC-301c · Module 3
Temperature & Sampling Parameters
3 min read
Temperature controls randomness in model output. Lower temperature (0.0-0.3) produces deterministic, conservative responses — the model picks the most likely token at each step. Higher temperature (0.7-1.0) produces more varied, creative responses — the model samples from a broader probability distribution. For code generation, lower temperature is almost always correct. Code has right answers and wrong answers; creativity in token selection means bugs. For brainstorming, higher temperature produces more diverse ideas.
Top-p (nucleus sampling) is temperature's companion parameter. While temperature scales the probability distribution, top-p truncates it — only tokens in the top p% of probability mass are considered. A top-p of 0.95 means the model considers tokens that collectively make up 95% of the probability, ignoring the long tail of unlikely tokens. For code, top-p at 0.9-0.95 paired with temperature at 0.1-0.3 produces reliable, correct output. For creative tasks, top-p at 0.95-1.0 with temperature at 0.7-0.9 produces diverse output.
{
"profiles": {
"precise": {
"model": "gemini-2.5-pro",
"temperature": 0.1,
"topP": 0.9,
"thinkingBudget": "auto"
},
"creative": {
"model": "gemini-2.5-pro",
"temperature": 0.8,
"topP": 0.95,
"thinkingBudget": "auto"
},
"deterministic": {
"model": "gemini-2.5-pro",
"temperature": 0.0,
"topP": 0.9,
"thinkingBudget": "auto"
}
}
}
Do This
- Use low temperature (0.0-0.3) for code generation, debugging, and structured output
- Use higher temperature (0.7-0.9) for brainstorming, naming, and creative writing
- Pair temperature with appropriate top-p — both parameters shape the output distribution
Avoid This
- Leave temperature at default for all tasks — code and creative writing need different settings
- Use high temperature for code generation — randomness in code means bugs
- Ignore top-p and only tune temperature — they are complementary controls that work best together