Skip to content

Temperature and top-p: Controlling the Creativity of a Neural Network

Cover: temperature and top-p

Why does the same model sometimes respond strictly to the point and other times spout unexpected ideas? It all comes down to two parameters: temperature and top-p.

What is Temperature

Temperature controls the 'boldness' of the model. At low temperatures, the model selects the most probable words — responses are strict and predictable. At high temperatures, it starts considering less probable options, making the text more varied but sometimes delving into nonsense.

Temperature Effect
0.0–0.3 Strict, predictable, to the point
0.5–0.7 Balanced
0.8–1.2 Creative, risky

What is Top-p

Top-p (nucleus sampling) limits the selection: the model considers not all tokens but the minimal pool that sums up to probability p. With top_p = 0.9, the tail of the least probable words is discarded.

How They Work Together

Temperature sets the overall level of chaos, while top-p trims the tail of the distribution. They are often used in tandem:

  • Facts and code: temperature 0.2, top-p 0.9.
  • Creativity: temperature 0.8, top-p 0.95.
flowchart LR
    A[Token logits] --> B[Temperature<br>amplifies/smoothes variance]
    B --> C[Top-p<br>trims the tail]
    C --> D[Token selection]

Practical Recipes

  • Summarization — temperature 0.2: important not to invent.
  • Idea generation — 0.9: let it propose boldly.
  • Dialogue — 0.7: naturally, but not chaotically.
  • Code — 0.1: predictability is key.

See Also