Labs

Sampling playground

Turn temperature, top-k and top-p and watch the next-token distribution reshape.

Prompt: “The capital of France is …”

Show the distribution after
“Paris” 5.078%
“a” 3.213%
“the” 2.99.5%
“located” 2.4✕ top-p
“known” 1.8✕ top-p
“Lyon” 0.8✕ top-p
“not” 0.4✕ top-p
“pizza” -1.5✕ top-p

Faint bar: before this step (step 1: the model's own T = 1).

Entropy0.99 bitsmax 3 bits for 8 tokens
Tokens kept3 / 8
P(“Paris”)78%
Tail cut9.9%mass removed by truncation

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).