Back to Generative AI Notes
Topic #70

Temperature

Temperature controls how much randomness is introduced when the model selects its next token — low temperature favors the most likely token consistently; higher temperature allows more variety and creativity, at the cost of predictability.

What's Actually Happening

Given the same partial sentence, the model computes a probability
for many possible next tokens:

  "The weather today is" →
    " sunny"  (35% probability)
    " cloudy" (25%)
    " rainy"  (15%)
    " nice"   (10%)
    ...

Temperature = 0:    always pick the single highest-probability token
                     (deterministic-ish — "sunny", every time)
Temperature = 0.7:  sample from the distribution, weighted by
                     probability — usually "sunny" or "cloudy",
                     occasionally something else
Temperature = 1.5:  flatten the distribution further, giving lower-
                     probability tokens meaningfully more chance —
                     more varied, more unpredictable output

Choosing a Temperature for the Task

Task TypeTypical TemperatureWhy
Factual Q&A, data extraction, classificationLow (0-0.3)Consistency and reliability matter more than variety
General conversation, draftingModerate (0.5-0.8)Some natural variation is desirable without going off-topic
Creative writing, brainstormingHigher (0.8-1.2+)Variety and unexpected combinations are the actual goal

Important: Temperature 0 Isn't Always Perfectly Deterministic

Even at temperature 0, some providers' systems can produce slightly different outputs across identical requests due to infrastructure-level factors (like floating-point computation differences across hardware). Treat temperature 0 as "highly consistent," not as an absolute deterministic guarantee — if you need true reproducibility for testing, check your specific provider's documented guarantees.

Practical Use Case

A data-extraction feature pulling structured fields from documents should use low temperature (consistency matters, creativity doesn't help). A marketing-copy generator benefits from higher temperature to avoid repetitive, formulaic output across multiple generations.

Common Mistakes

  • Using a high default temperature for tasks needing consistency (classification, extraction), causing unpredictable, hard-to-test behavior
  • Assuming temperature 0 guarantees bit-for-bit identical output every time, and building tests that assume perfect reproducibility
  • Adjusting both temperature and top_p simultaneously without understanding they interact — see Top-p

Interview Relevance

"Why would you set temperature to 0 for a data extraction feature?" — consistency and predictability matter far more than variety for a task with one objectively correct output.

Practice Question

Recommend a temperature setting (with reasoning) for: (1) generating 5 varied ad headline options, (2) extracting a shipping address from an email.

Want to go beyond the notes?

Join Coding Now Tech Institute's Generative AI course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available

Temperature – FAQs

Quick answers about learning Temperature in Generative AI.

This free note from Coding Now Tech Institute explains Temperature in Generative AI — concept, syntax and worked code examples you can copy, run and revise before interviews.
Yes. Every Generative AI topic on Coding Now Tech Institute, including Temperature, is 100% free with no signup required.
With focused practice, most students grasp Temperature in 1–3 days from these notes; pairing it with Coding Now Tech Institute's mentor-led course takes you to job-ready depth faster.
Use the code examples in this note, then ask doubts for free on the Coding Now Tech Institute Community (/community) — expert instructors answer within 24 hours.
Call NowEnroll Now