At each step a model outputs a probability for every possible next token. Sampling is how one is chosen — and the knobs control the trade-off between focused and creative. A deeper companion to Temperature & Sampling: Determinism vs Creativity.
The knobs
| Setting | What it does |
|---|---|
| Greedy (temp 0) | Always pick the single most likely token — deterministic, repetitive |
| Temperature | Flattens/sharpens the distribution. Low = safe/focused, high = wild/creative |
| Top-k | Only consider the k most likely tokens |
| Top-p (nucleus) | Consider the smallest set whose probability sums to p (e.g. 0.9) |
| Repetition penalty | Discourage repeating recent tokens |
How temperature reshapes choices
temp 0.2 → [the 0.85] [a 0.10] ... → almost always "the" (focused)
temp 1.2 → [the 0.40] [a 0.25] ... → more variety (creative)
Sensible defaults
| Task | Settings |
|---|---|
| Code / facts / extraction | temp 0–0.3 |
| General chat | temp 0.7, top-p 0.9 |
| Brainstorm / fiction | temp 1.0+ |
Set these per task — see Ollama Parameters Guide for where they live.
Related: Temperature & Sampling: Determinism vs Creativity · Ollama Parameters Guide · Why LLMs Hallucinate