top-k sampling
Restricting sampling to only the k highest-probability tokens before drawing from the (renormalized) distribution.
Top-k sampling truncates the next-token distribution to its k highest-probability tokens, renormalizes their probabilities to sum to 1, and samples only from that shortlist -- preventing the long tail of very-low-probability tokens from ever being drawn.
Examples
With k=40, only the 40 highest-probability next tokens are eligible to be sampled at that step, no matter how many thousand tokens sit in the full vocabulary.
Point table
Graph settings
Calculator