Skip to content
Free public beta until December 4, 2026: every course is open, no card needed. After that, the first chapter of each course stays free and full access is a one-time $39 ($19 for up to 100 founding members chosen for helpful feedback). Your progress is kept. How the beta works

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.

Read the full section →
Graph settings

Calculator