Sampling playground
Turn temperature, top-k and top-p and watch the next-token distribution reshape.
Prompt: “The capital of France is …”
Faint bar: before this step (step 1: the model's own T = 1).
Low T → the top token wins almost every draw (repetitive, safe); high T → more variety, and more off-path picks. Truncation cut 9.9% of the mass here: the long tail where tokens like “pizza” live.
How it's calculated · assumptions
p = softmax(logits ÷ T) → top-k: keep the k best → top-p: smallest set with Σp ≥ top_p → min-p: keep p ≥ min_p × p_max → renormalize → draw
Illustrative: 8 hand-picked tokens with made-up logits; a real model scores its whole vocabulary (~128k tokens for Llama 3). Step order as in Hugging Face transformers (checked 2026-11-17). Common settings: top_p 0.9–0.95, min_p 0.05–0.1. OpenAI's API takes temperature 0–2, default 1 (openai-openapi spec, checked 2026-11-17). Anthropic's took 0–1, default 1, but newer Claude models (Opus 4.7+, Sonnet 5) return a 400 for non-default temperature, top_p or top_k (Claude API release notes, checked 2026-11-17).