Skip to content

VersusGPU

Temperature vs Top-p vs Top-k in Ollama: Which Setting to Change?

What Ollama's sampling settings do: temperature controls creativity, top_k and top_p limit which tokens are considered, min_p is a relative alternative to top_p, and seed makes output repeatable, with Ollama's documented defaults and how to set them.

By , Senior Hardware Editor

3 min read

Temperature vs Top-p vs Top-k in Ollama: Which Setting to Change?

If a local model's answers feel too random, too repetitive or too bland, the fix is often a sampling setting rather than a different model. Ollama exposes several of these: temperature, top_k, top_p and min_p, plus seed and repeat_penalty. They all affect how the model picks each next word (token), but in different ways. This comparison is based on Ollama's Modelfile and API documentation. It hasn't involved testing particular models on our hardware, and the right values depend on the model and the task, so treat the numbers below as Ollama's documented defaults and examples, not recommendations.

The short version

Setting

What Ollama says it does

Documented default

temperature

Increasing it makes the model answer more creatively

0.8

top_k

Reduces the probability of generating nonsense; higher (e.g. 100) gives more diverse answers, lower (e.g. 10) is more conservative

40

top_p

Works together with top_k; higher (e.g. 0.95) gives more diverse text, lower (e.g. 0.5) more focused, conservative text

0.9

min_p

An alternative to top_p, aiming to balance quality and variety

0.0

seed

A fixed number makes the model generate the same text for the same prompt

0

repeat_penalty

How strongly to penalise repetition; higher (e.g. 1.5) is stricter, lower (e.g. 0.9) more lenient

1.0 (disabled)

One caveat: a model's own Modelfile can set its own PARAMETER values, so the settings a particular model actually uses may differ from these general defaults.

Temperature: the creativity dial

Temperature is the setting most people reach for first. Ollama's description is simple: increasing it makes the model answer more creatively. Lower it for tasks where you want consistent, predictable answers, such as extracting data or answering factual questions about a document. Raise it for brainstorming or creative writing, where variety matters more than consistency.

Top-k: limit the shortlist

Top-k caps how many candidate tokens the model considers at each step. A low value such as 10 keeps the model to its most likely choices, which Ollama describes as more conservative. A high value such as 100 lets it consider more options, giving more diverse answers.

Top-p: limit by probability

Top-p (sometimes called nucleus sampling) works with top-k. In general terms, rather than a fixed number of candidates, it keeps the most likely tokens until their combined probability reaches the top_p value. Ollama's examples: 0.95 leads to more diverse text, while 0.5 leads to more focused, conservative text.

Min-p: the newer alternative

Min-p is described by Ollama as an alternative to top_p. It sets a minimum probability for a token to be considered, relative to the most likely token. Ollama's example: with min_p at 0.05 and the most likely token at a probability of 0.9, tokens with a value below 0.045 are filtered out. Because it scales with how confident the model is, it can keep more options when the model is unsure and fewer when it's confident.

Seed and repeat penalty

Two other settings are worth knowing. seed makes output repeatable: Ollama says setting a specific number makes the model generate the same text for the same prompt, which is useful when you're comparing other settings. repeat_penalty discourages the model from repeating itself, and repeat_last_n sets how far back it looks (default 64 tokens).

How to change them

You can set any of these in two places:

If answers are cut short or lose track of earlier text, the problem may be context length rather than sampling; see how to set Ollama's context length.

Our verdict

Change temperature first: it's the clearest way to make a model more focused or more creative. Reach for top_k, top_p or min_p only if you want finer control, change one at a time, and fix the seed while you compare so you can see what each change actually does.

The bottom line

Change temperature first: it's the clearest way to make a model more focused or more creative. Reach for top_k, top_p or min_p only if you want finer control, change one at a time, and fix the seed while you compare so you can see what each change actually does.

Sources

  1. 01Ollama, Modelfile reference (valid parameters and values)
  2. 02Ollama, API reference: Generate a response

About the author

Callum Reid

Senior Hardware Editor

Callum leads GPU, CPU and platform architecture coverage at Forge PC. Before joining the editorial desk, he spent nine years specifying, assembling and stress-testing custom gaming and workstation systems in the UK, with a focus on PCIe bandwidth, VRM thermal design, DDR5 memory tuning and 1440p/4K frame-time consistency.

More from Callum Reid

Read next

How to Use Tool Calling in Ollama

How-To

How to Use Tool Calling in Ollama

How to use tool calling (function calling) in Ollama: describe functions in a tools list on /api/chat, read the model's tool_calls, run them and send results back as tool messages, plus parallel calls, agent loops and streaming, based on Ollama's documentation.

Marcus Thorne3 min

Ollama /api/generate vs /api/chat: Which Endpoint Should You Use?

Versus

Ollama /api/generate vs /api/chat: Which Endpoint Should You Use?

Ollama's /api/generate takes a single prompt and suits one-off tasks, with extras such as suffix for fill-in-the-middle and raw mode; /api/chat takes a list of role-based messages and supports tool calling, so it's the one for chatbots and agents.

Callum Reid3 min

How to Fix Slow Token Generation in llama.cpp

How-To

How to Fix Slow Token Generation in llama.cpp

How to fix slow llama.cpp text generation by confirming GPU offload with -ngl and setting -t to your physical core count or lower, with the llama.cpp developers' own example showing the effect of each setting.

Marcus Thorne2 min