Temperature and Sampling

Authors 6 articles 60 min total read
Definition
Temperature and sampling are parameters that control how a large language model selects its next token from a probability distribution, with temperature scaling logits before softmax to adjust the randomness of generated text.
Also called: LLM temperature, sampling temperature, temperature parameter

What temperature and sampling is

Every time a large language model generates text, it faces a decision: which word comes next? The model produces a raw score (called a logit) for every possible word in its vocabulary, then converts those scores into probabilities through a function called softmax. Temperature is the dial that shapes how those probabilities look before the model picks a word. If you care about how your AI tool responds — whether it gives you the same answer twice or surprises you each time — temperature is the parameter responsible.

Think of it like ordering coffee. At temperature zero, you always pick the same drink — the one you rated highest last time. At a higher temperature, you might try something unfamiliar, even something risky. The menu hasn’t changed. Your willingness to experiment has.

Mathematically, temperature divides each logit by a value T before softmax runs. When T is low (close to zero), the highest-scoring word dominates and the model becomes predictable. When T is high, the gap between word probabilities shrinks, so less likely words get a real chance of being selected. At T equals exactly zero, only the single highest-probability word is ever chosen — a behavior called greedy decoding.

Sampling is the broader term for the full set of strategies that determine which word actually gets picked from that shaped distribution. Temperature is one sampling parameter, but it works alongside others. Top-p (nucleus sampling) limits the selection pool to words whose combined probability reaches a threshold — say 90%. Top-k restricts the pool to a fixed number of top candidates. Together, these parameters form a toolkit for controlling the personality of any LLM response, from robotic consistency to unpredictable creativity.

Temperature only changes which words get picked from the same probabilities; the model's knowledge stays the same. · More AI cheat sheets
  • Temperature and top-p/min-p are separate filters on the same probability distribution — stacking them aggressively without understanding both is the most common sampling misconfiguration.
  • There is no universal safe setting: code generation, RAG, and creative writing each need different values, and porting settings between providers without checking their docs silently breaks.
  • Extreme settings fail predictably — too low collapses into repetition loops, too high drifts into hallucination — and the fix is diagnosing which extreme, not reverting to defaults.
  • Providers are moving fast: some proprietary APIs are locking parameters while open-source stacks adopt min-p as a smarter default, so configurations that work today may not next quarter.

How temperature and sampling are used in practice

Most people interact with temperature without realizing it. When you use ChatGPT, Claude, or Gemini through their chat interfaces, the application sets a default temperature behind the scenes. Developers working with these APIs adjust temperature directly — setting it low for tasks like code generation or factual Q&A where consistency matters, and pushing it higher for creative writing or brainstorming where variety helps.

According to Anthropic Docs, Claude’s temperature ranges from 0 to 1 with a default of 1.0. According to Google AI Docs, Gemini defaults to 1.0 but allows values up to 2. These different ranges mean a “temperature of 0.7” doesn’t produce identical behavior across providers — the scaling and implementation details vary between models.

A notable recent shift: reasoning-focused models have started disabling temperature altogether. According to OpenAI Community, models like GPT-5, o3, and o4-mini ignore temperature settings entirely, favoring a separate reasoning_effort parameter instead.

Start with temperature 0 for any task where you need reproducible results — data extraction, classification, structured JSON output. Only increase it when you specifically want variation, and go up in increments of 0.1 rather than jumping to high values. You’ll find the sweet spot faster.

The reading order: from the probability distribution to production defaults

Start with how softmax scaling controls text generation randomness — it opens the one mechanism every later article assumes you already understand: temperature reshapes the distribution before a single token is chosen. From there, the full sampling method comparison adds the filters that act after that reshaping — top-k, top-p, min-p, and beam search each keep a different slice of the ranked candidates. Read the hard limits of sampling parameter tuning next, before touching a production config — it shows exactly where the knobs stop helping and start producing loops or hallucination.

Once the mechanics are set, the per-use-case configuration guide turns them into settings for code, RAG, and creative workloads. For what is shifting under those settings, the piece on locked temperatures and min-p adoption tracks how providers are changing the defaults. Close with the argument about who controls those defaults if you want the stakes beyond your own config file.

MAX asks: 'I set temperature to 0.7 and top-p to 0.9 — why does the output still swing between flat and unhinged?' MONA answers: 'You gave the model two filters fighting over the same job. Pick one, let it actually do the work.' — comic dialog.
Temperature and top-p both reshape the candidate pool — stacking them blindly is the most common sampling misconfiguration.

Where sampling parameters end and the other inference levers begin

Sampling gets confused with the other two levers in this theme, and each confusion sends debugging in the wrong direction.

  • Sampling is not all of inference. Inference is the entire autoregressive decoding loop — memory management, scheduling, the forward pass. Sampling is the very last step of that loop: the rule that turns a finished probability distribution into one chosen token. Slow inference is rarely a sampling problem.
  • Sampling is not quantization. Quantization changes the model’s weights before generation ever starts; sampling changes the selection rule at generation time. They compose — a heavily quantized model still needs a sampling strategy — but degenerate or repetitive output right after quantizing is usually a precision problem, not a temperature problem, and vice versa.
  • Sampling is not continuous batching. Batching decides which requests share a GPU pass; it does not touch how a token is chosen within any one of them. The catch: batch composition can still affect output consistency at a fixed setting, which is why testing sampling only at low concurrency before shipping is a common blind spot.

When temperature and sampling fit — and when they don't

ScenarioUseAvoid
Extracting structured data from documents✅ Low temperature (near zero)
Creative brainstorming or story writing✅ Higher temperature
Code generation with strict syntax✅ Low temperature
Production chatbot giving factual answers❌ High temperature risks hallucinated details
Generating diverse test cases or variations✅ Moderate temperature
Summarizing legal or medical documents❌ High temperature introduces unwanted variation

Common questions about temperature and sampling

Q: Does setting temperature to 0 make an LLM’s output fully deterministic? A: Not automatically — temperature at 0 collapses selection to the single highest-probability token, but production serving conditions such as batching can still introduce variation at the same setting. How softmax scaling controls text generation randomness explains what zero temperature does and does not guarantee.

Q: Should temperature and top-p be tuned at the same time? A: No — treat them as one dial, not two. Setting both aggressively is a documented misconfiguration: the two filters compete over the same candidate pool, producing unpredictable swings between flat and erratic output. The per-use-case configuration guide recommends picking one control per request.

Q: Can a provider lock or remove a sampling parameter my application already depends on? A: Yes, and it is already happening — some proprietary APIs are locking reasoning-model temperature while open-source runtimes move toward min-p as the smarter default. The 2026 shift in sampling defaults tracks which knobs are disappearing and what replaces them.

Q: Does lowering temperature always fix repetitive or unreliable output? A: No — pushed too low, sampling can trap generation in loops instead of fixing them; the failure mode looks similar but the cause and the correction differ. The hard limits of sampling parameter tuning diagnoses both extremes.

Part of the inference optimization theme · closest neighbour: inference. Coming to sampling from a software background? Start with the story: Inference Optimization for Developers: What Transfers and What Breaks.

Sources

1

Understand the Fundamentals

Temperature and sampling sit at the boundary between a model's learned knowledge and the text it actually produces. Understanding how probability redistribution works reveals why the same prompt can yield wildly different outputs.

2

Build with Temperature and Sampling

These guides walk through choosing and configuring temperature, top-p, and min-p across real workloads, from deterministic extraction pipelines to open-ended creative generation.

4

Risks and Considerations

Opaque default settings and locked sampling controls raise questions about user autonomy, output accountability, and the hidden influence of provider-chosen parameters on downstream decisions.