LLM Sampling Visualizer

Every token an LLM writes is picked from a probability distribution. Drag the sliders below and watch how temperature, top-p, and top-k reshape a real softmax distribution, then hit Sample to draw a token the same way a model does.

The capital of France is ___

Temperature divides every logit before the softmax. Low values sharpen the distribution so the most likely token dominates (at 0 it becomes pure argmax, always "Paris"). High values flatten it, giving unlikely tokens a real chance, which reads as more creative but also more error-prone.

Top-p keeps only the smallest set of tokens whose probabilities add up to at least p, then renormalizes and samples from that "nucleus". At p = 1 nothing is cut. At p = 0.5 you only sample from the tokens covering the top 50% of probability mass, trimming the long tail of nonsense.

Top-k is a hard cutoff: keep only the k highest-probability tokens and throw the rest away before sampling. k = 1 is greedy decoding (always the single best token). Unlike top-p, the cutoff does not adapt to how confident the model is, it is always exactly k tokens.

Next-token distribution (grayed-out bars are cut off and cannot be sampled)

Sampling uses the truncated, renormalized distribution shown above.
The math is real: each candidate token has a fixed base logit. The tool computes p(token) = exp(logit / T) / sum(exp(logit / T)) - an actual temperature-scaled softmax, not a mock-up. Top-k then keeps the k most probable tokens, top-p keeps the smallest set covering probability mass p (both filters apply together), the survivors are renormalized, and the Sample button draws from that final distribution with a random number. This is exactly the pipeline behind the temperature, top_p, and top_k parameters in the Claude and OpenAI APIs, just with 15 candidate tokens instead of a full vocabulary.