跪拜 Guibai
← All articles
Artificial Intelligence

Temperature Doesn't Create Creativity — It Just Flattens the Odds

By 东风破_ ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

Misunderstanding temperature leads teams to crank it up expecting smarter output or down expecting zero hallucinations, when it controls neither. Getting the sampling parameters right is what keeps an agent from calling the wrong tool and a RAG pipeline from improvising over missing documents.

Summary

Every token a large language model generates is drawn from a probability distribution over its vocabulary. Temperature reshapes that distribution before sampling — low values sharpen it toward the most likely token, high values flatten it so long-shot candidates get drawn more often. Top-K then limits the pool to a fixed number of high-probability candidates, while Top-P (nucleus sampling) keeps the smallest set whose cumulative probability hits a threshold, adapting the pool size to how confident the model is.

These three knobs are the reason the same prompt can return different code, different facts, or different tool-call decisions. In agent and RAG pipelines, where deterministic tool selection and faithful retrieval matter more than variety, a temperature near zero is standard — not because it makes the model smarter, but because it suppresses sampling variance. The DeepSeek API docs even recommend tuning only one of temperature or top_p at a time, since both alter the sampling space and make it impossible to attribute output changes.

A practical tuning table maps tasks to starting ranges: 0–0.2 for tool calls and structured extraction, 0–0.3 for RAG Q&A, 0.2–0.6 for technical dialogue, 0.6–0.9 for headlines and copy, and 0.8–1.2 for story brainstorming. The core advice is to fix the prompt and test set, vary one parameter at a time, and measure accuracy, format stability, and diversity — not to copy a universal value.

Takeaways
Temperature divides logits before softmax, sharpening or flattening the probability distribution; it does not inject new knowledge or reasoning.
Low temperature (0–0.3) suits tool calls, structured extraction, and RAG because it favors the highest-probability token and reduces output variance.
High temperature (0.8–1.2) widens the candidate pool for creative tasks but also raises the risk of off-topic, low-quality, or factually wrong output.
Top-K keeps exactly the K highest-probability tokens and discards the rest, then re-normalizes; it is common in Hugging Face but not always exposed in cloud APIs.
Top-P (nucleus sampling) keeps the smallest set of tokens whose cumulative probability reaches P, so the candidate count adapts to the model's confidence.
DeepSeek's API docs recommend adjusting only temperature or top_p, not both, because simultaneous changes make output differences impossible to attribute.
Agent and RAG workflows default to temperature 0 for controllability, not because creativity is unwanted — wrong tool calls or parameter schemas break the pipeline.
Temperature 0 is a server-side convenience that minimizes randomness; it does not guarantee identical output across model versions, hardware, or context changes.
Before raising temperature, write a clear prompt with explicit goals, context, and output format; a vague prompt plus high temperature amplifies noise, not creativity.
Tune parameters on a fixed test set, changing one variable at a time, and measure accuracy, format stability, repeatability, and diversity against business needs.
Conclusions

Temperature is widely misunderstood as a creativity dial, but it's purely a sampling-distribution shaper — the model's knowledge and reasoning are frozen before sampling begins.

The advice to tune only temperature or top_p, not both, is a practical guardrail against the common reflex of twisting every knob at once and then being unable to reproduce or debug behavior.

Calling temperature 0 'deterministic' is misleading; server-side infrastructure, floating-point non-determinism, and context drift still produce variation, so pipelines that require bit-identical output need a different strategy.

The task-based temperature table is a useful starting heuristic, but its real value is the methodology: fix the prompt and test harness, vary one parameter, and let business metrics — not intuition — pick the value.

Concepts & terms
Logits
The raw, unnormalized scores output by a language model for each token in its vocabulary before a softmax function converts them into probabilities.
Softmax
A function that turns a vector of raw scores (logits) into a probability distribution where all values sum to 1, making higher scores exponentially more likely.
Top-K sampling
A decoding strategy that keeps only the K tokens with the highest probabilities, discards the rest, and re-normalizes before sampling, fixing the candidate pool size regardless of the distribution shape.
Top-P (Nucleus) sampling
A decoding strategy that keeps the smallest set of tokens whose cumulative probability reaches a threshold P, so the candidate pool size adapts dynamically to how concentrated or spread-out the distribution is.
Greedy decoding
Always picking the single token with the highest probability at each step; produces stable but often repetitive output and is equivalent to temperature approaching 0 with no sampling.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗