LLMscore
Sampling: temperature, top-k, top-p
How the next token is picked from the model’s probability distribution.
What it is and why it exists
At each step the model outputs a score (logit) per vocabulary token. Temperature rescales those scores (low = sharper, high = flatter), top-k keeps only the k most likely tokens, top-p (nucleus) keeps the smallest set whose probabilities sum to p, and min-p drops tokens below a fraction of the top token’s probability. Then one token is sampled.
Quick prototype
Leave the defaults; drop temperature to ~0 for extraction and classification.
In production, at scale
Pick settings per task (low for extraction, moderate for writing), pin them in the prompt version, and evaluate with them. Many reasoning models fix or ignore these parameters.
Vendors and tools
| OpenAI / Anthropic / Gemini APIs | temperature and top_p parameters; support varies by model |
|---|---|
| vLLM / llama.cpp | Full control: top_k, min_p, repetition penalties, seeds |
On AWS: Bedrock’s Converse API exposes temperature, topP and maxTokens in inferenceConfig.
How it fails
- High temperature on structured extraction → invalid fields and invented values
- Temperature 0 assumed to be deterministic (it isn’t, see determinism)
- Tuning temperature and top-p at the same time and not knowing which helped
What the interviewer asks next
What does temperature 0 actually do?
It approaches greedy decoding: always pick the highest-probability token. Output becomes repetitive but more stable — still not guaranteed identical across runs in production serving.
Top-k vs top-p?
Top-k keeps a fixed number of candidates regardless of confidence; top-p adapts — few candidates when the model is sure, many when it isn’t.