liveBook · Manning

Temperature

As explained in Generative AI in Action

Temperature is a model-generation setting that controls the degree of randomness in the model's output distribution.

Temperature is a text-generation setting that controls how much outputs vary between calls. Lower values tend to produce more predictable, repetitive responses; higher values tend to produce more diverse ones. Choose it for the task: marketing ideas may benefit from variety, while document automation may need consistency. section 2.8.5 section 3.2.4

Set temperature on each API call, so one workflow can use different values for different tasks. Illustrative starting points are 0.8 for creative output and 0.2 for more predictable output. There is no universally correct setting. Temperature and top_p both steer randomness; try adjusting one rather than both at once. section 3.2.4 section 2.8.5

response = client.completions.create(
    model="gpt-35-turbo",
    prompt=prompt_startphrase,
    temperature=0.8,
    max_tokens=100,
    n=3,
    stop=None)

This illustrative completions call sets temperature to 0.8 and requests three responses with n=3, making variation visible without three separate calls. section 3.2.4

Compare outputs before choosing a value

Three pet-grooming name suggestions generated at 0.8 varied more than three generated at 0.2. At 1.8, suggestions included nonsensical text. Compare repeated outputs against the task’s need for variety and reliability rather than treating a higher value as automatically better. section 3.2.4

Temperature does not replace output review or safeguards. Identical prompts can still yield different responses, especially at higher settings; very high settings can increase hallucinations. Assess output quality for the use case, and use content filtering where inappropriate or sensitive content is a concern. section 3.2.4 section 6.7

How Generative AI in Action covers it

How deep it goes
Defines the setting and compares outputs at three values, without deriving the underlying probability calculation.
Examples
Compares three pet-grooming naming outputs at 0.8 and 0.2, then shows nonsensical results at 1.8.
What it assumes
Introduces temperature as a model setting while using prompts and completion API calls for the applied comparison.
What you can do after
Operate/configure it per completion API call and compare repeated outputs against the task’s need for variety or consistency.
How it connects
Connects temperature to top_p, max_tokens, prompt engineering, hallucinations, and content filtering.

Also explained in

Compare how 17 books explain temperature →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Generative AI in Action. The section links point to the parts of the book it draws on.