AI and Probability: Meaning and Selective Use of Temperature, top-p, top-k

AI Navigate Original / 4/27/2026

💬 OpinionIdeas & Deep AnalysisTools & Practical Usage
共有:

Key Points

  • LLMs sample from a probability distribution; temp/top-p/top-k control it
  • Low temp = deterministic (classify); high = creative (story)
  • Move only one of temperature/top-p; fix seed for reproducibility
  • Settings differ per model; check API defaults

The LLM Rolls Dice

An LLM may return different output every time for the same input. This is because the LLM, after computing "the probability distribution of the next word," samples (draws lots) from that distribution. Parameters like temperature, top-p, top-k control how probability is rolled.

Temperature

A value 0 to 2. Controls how much to "sharpen / flatten" the probability distribution.

Example: The Word After "Japan's capital is"

CandidateRaw probAfter T=0.5After T=2.0
Tokyo0.950.990.7
Kyoto0.030.0050.15
Osaka0.010.0010.10
Other0.010.0010.05

Temperature Guide

  • 0.0: fully deterministic (same every time). For tests/classification.
  • 0.0-0.3: nearly deterministic. Fact-check, extraction, summary.
  • 0.5-0.7: standard. Chat, Q&A, coding.
  • 0.8-1.0: creative. Novels, poetry, brainstorm, ad copy.
  • 1.0+: very diverse, quality-degradation risk.

top-p (Nucleus Sampling)

Collect top words until their probabilities sum to p, then choose within that range. 0.0-1.0.

  • 0.1: only the very top, nearly deterministic
  • 0.5: moderate
  • 0.9: standard (many models' default)
  • 1.0: choose from all candidates

Temperature and top-p can be used together, but it's common to move only one. OpenAI officially recommends "don't change both."

top-k

Choose only from the top k words by probability.

  • k=1: always the max-likelihood candidate (greedy)
  • k=10-50: standard
  • k=100+: diversity-focused

Compared to top-p, being a fixed number, it's harder to adapt to distribution sharpness by context. top-p is more mainstream now.

Other Parameters

frequency_penalty / presence_penalty

Suppress repetition of the same word. 0.0-2.0. Try around 0.5 when repetition stands out in text generation.

max_tokens

Max output tokens. For billing limits and preventing cut-offs.

stop sequence

Stop generation when a specific string like "###" appears. Useful for format control.

Recommended Settings by Use

Usetemperaturetop-p
Classification/extraction0.01.0
Fact-check Q&A0.1-0.31.0
Code generation0.2-0.50.95
Translation/summary0.3-0.51.0
Customer support0.5-0.70.9
Marketing copy0.7-0.90.9
Creative/story0.8-1.00.95
Brainstorm0.9-1.01.0

Probability-Control Pitfalls

  • Some models aren't fully deterministic even at temperature 0 (implementation-dependent)
  • Same parameters behave differently across models
  • Using without checking the API default causes variance
  • In production, fixing the seed raises reproducibility (OpenAI etc.)

2026 Tendencies

  • Reasoning models (thinking line) do multi-stage sampling internally
  • Many frontier models default to "auto-adjustment"
  • Training to keep consistency even above temperature 0 advances

Summary

Temperature/top-p are parameters controlling the LLM's "way of rolling dice." By use, classification at low temperature, creative at high is basic. Don't change both at once; fixing one and adjusting the other is recommended.