Coding Now – Best AI & Full Stack Courses in Delhi NCR | 100% Placement
Limited Offer: Get 50% OFF on AI & Full Stack Courses
📞 Call Now: +91 9667708830
Back to Generative AI Notes
Topic #604

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.

Related Notes

Want to go beyond the notes?

Join CodingNow's Generative AI course — live mentorship, real projects, and 100% placement support.

Enroll Now — Free Demo Available
💬 Talk to Advisor
1
WhatsApp

Latest from Our Blog

Insights on AI, Data Science, Full Stack & Career

View All Articles →