sampling -- greedy / top-k / top-p / temperature
The model never picks a word. It produces a score for every entry in its token list, and something separate has to choose one: always taking the top score gives the same answer every time. Temperature is a number those scores are divided by before they are turned into percentages, and the effect is on the gaps between them â below one the gaps stretch and the leader takes nearly all the probability, above one they shrink and unlikely words get a real chance. Top-p works differently: sort the candidates, keep adding them to a shortlist until the shortlist covers, say, 90% of the probability, and draw from that. So temperature changes the odds and top-p changes who is allowed into the draw.
Interactive page: how the next token is actually chosen from the lm-head's logits -- temperature, then a truncation strategy (greedy, top-k, top-p), then a draw. Anchor: the decode-time companion to lm-head (which produces the logits); Family C.
What it shows
The logits become probabilities via softmax(logits / T):
- temperature
T:T<1sharpens (more peaked, more greedy),T>1flattens (more random).Tâ0is greedy. - greedy: take the argmax -- deterministic, always the top bar.
- top-k: keep only the
khighest-probability tokens, renormalize, sample from those. - top-p (nucleus): keep the smallest set of top tokens whose cumulative probability first reaches
p, renormalize, sample.
Bars are drawn in descending probability; the kept set is colored, the cut tail is greyed. The cumulative curve + the p line show the nucleus (top-p); a divider shows the k cut (top-k). A live sampler draws tokens from the kept, renormalized distribution and tallies them -- watch the empirical frequency converge to the probabilities (greedy always picks the top).
Drag the k divider or the p line to resize the kept set; the slider tracks it. Hover any bar for its token / logit / prob / cumulative.
Render tier
T1 (Canvas2D bars + cumulative curve + the live sampler; no heatmap needed).
Wiring
layout.mount + controls (temp, strat, k, p, seed) + animate (the live sampler via api.t) + onPointer threshold drag (routes through controls.set so the slider syncs) + hover. ?temp/?strat/?k/?p/?hover hooks. Source: page.js.