Skip to the document
Madhuopen lab
Outcome School · Other AI topics18 min read

by Amit Shekhar · 19 September 2026

How do Top-k and Top-p Sampling work?

How Top-k and Top-p Sampling work, the two most common ways an LLM decides which word to write next when it is replying to us. We will also see how an LLM picks one token at a time, why always picking the best token gives boring text, why picking from every token gives silly text, how Top-k keeps a fixed number of tokens, how Top-p keeps tokens based on their total probability, how both of them work with temperature, and when to use which one.

3,410 words#llm#ai#system-design4 recall cards

How do Top-k and Top-p Sampling work?
Read on Outcome School ↗then come back to lock it in
Before you read, guess

What is the simplest method for selecting tokens during generation?

Ten seconds, a guess, then read — a wrong guess still makes the answer stick.

Before you go

In one sentence, what was this chapter about?

From memory, without scrolling up. Writing it is what makes it yours; the grade is only to show you what you had.

How sure?