Back to Home
Inside an LLM

Top-P Sampling

Top-P controls how many likely next words the AI is allowed to choose from.

This is a simple learning demo using predefined word probabilities, not a real AI model.

Interactive Playground
0.90
0.1
Narrow
0.5
Moderate
1.0
All words
Sentence So Far
Your sentence will grow here…
Last chosen: Words added: 0
Live Visualization
Cumulative Probability
0% Top-P cutoff: 90% 100%
Word Probabilities
InAllowed OutExcluded
Statistics
0.90
Top-P Value
Cum. Probability
Allowed Words
Excluded Words
Chosen Word
How It Works
📊
Predicted
Words
📉
Sort by
Prob.
✂️
Keep
Top-P
🎯
Choose
Word
P=1.0 considers all words (maximum randomness). P=0.1 restricts to only the very top few words, near-deterministic output.
Top-P and Temperature both control randomness but differently. Most apps use them together (e.g. temperature=0.7, top_p=0.9).
💡
Key Takeaway

Top-P limits the AI to a group of likely words, helping control randomness while still allowing variety.

A low Top-P (e.g. 0.3) means only the top 1-2 words are available. A high Top-P (e.g. 0.95) opens up many more options. Most AI systems use 0.9 by default.