Skip to main content
AI / MLLLM FundamentalsDiagramBeginner

Temperature & Top-p

KO: Temperature & Top-p·EN: Temperature & Top-p·JA: Temperature & Top-p

Decoding hyperparameters that control LLM output determinism versus creativity by reshaping token probability sharpness (Temperature) and truncating the cumulative probability mass (Top-p)

Table of Contents

Structure Diagram

Next-Token Probability Distribution by Temperature
Candidate Token Rank →Prob (
(60, 2)Rank 3 (2%)
Quick Answer

What is Temperature & Top-p?

Decoding hyperparameters that control LLM output determinism versus creativity by reshaping token probability sharpness (Temperature) and truncating the cumulative probability mass (Top-p). It is a core concept in LLM Fundamentals within AI / ML.

Core Principles

At every generation step, an LLM transforms raw vocabulary logits into a probability distribution via Softmax before sampling the next token. Temperature ($T$) divides logits by $T$ prior to Softmax: lower values sharpen the distribution toward the single highest-probability token, while higher values flatten it to encourage diversity.

Top-p (Nucleus Sampling) keeps only the smallest set of top tokens whose cumulative probability exceeds $p$ (e.g., 0.9), dynamically pruning low-probability tail tokens that cause incoherent or off-topic output.

Practical Takeaways

  • Tune one lever at a time: Adjusting both Temperature and Top-p aggressively makes behavior hard to predict. Most API providers recommend fixing top_p=1.0 and tuning temperature alone.
  • Match settings to task determinism: Use 0.0–0.2 for JSON extraction, code, and classification; 0.3–0.5 for RAG synthesis; and 0.7–0.9 for creative ideation.
  • Zero temperature is near-deterministic, not bitwise identical: GPU parallelism and MoE routing can still introduce minor variance; combine temperature=0 with schema validation for mission-critical flows.

Notable Examples

  • Structured Data Extraction: Setting temperature=0 ensures consistent JSON field values across batch document runs.
  • Creative Writing Assistants: Pairing temperature=0.85 with top_p=0.95 preserves fluency while surfacing varied phrasing.
  • Automated Evals (LLM-as-a-Judge): Locking temperature=0 minimizes scoring jitter across benchmark iterations.