AI / A CONCEPT NOTE

Temperature & Sampling

why answers vary

~65 sec read

Overview · mechanism
pitfall · examples

01 / THE SHORT VERSION

The idea in a few sentences.

Temperature scales the token probability distribution. High temperature flattens probabilities (more creative/random); low temperature peaks probabilities (more deterministic).

02 / FOLLOW THE MECHANISM

How tokens are selected

  1. Output logits

    model computes raw math scores (logits) for potential next tokens.

  2. Temp scale

    divides logits by temperature. Temp=0 sets highest token probability to 1.

  3. Probability mapping

    runs softmax to get clean percentage probabilities per token.

  4. Selector

    samples next token from probability distribution.

04 / COMMAND NOTES

Read the command, then the result.

Inspect the flags and arguments before trying an example. Snippets can need local setup, replacement values, or resources in your own environment.

EXAMPLE 01 · REFERENCE

query local model with explicit temperature settings

curl -X POST -d '{\"model\":\"llama3\",\"prompt\":\"hi\",\"options\":{\"temperature\":0.0}}' http://localhost:11434/api/generate

Explore command anatomy in the CLI lab