Part IV — Speaking, Thinking & Limits Chapter 11 of 12

Temperature, Top-P & Sampling

How a single dial shifts an AI between robotic precision and wild creativity.

8 min read · 3 interactive labs · Zero complex math

Ask a language model to tell you a bedtime story twice in a row, and you will get two completely different stories. Yet ask it for the capital of France twice in a row, and it will say Paris every single time.

How can the exact same network—with the exact same frozen weights—be both a rock-solid encyclopedia and an unpredictable storyteller?

The secret happens at the very final step of every single word. Remember: the transformer does not output one word. It outputs a glowing skyline of chances across its entire vocabulary—tall bars for likely words, medium bars for interesting runner-ups, and tiny slivers for weird words. To actually speak, the model has to pick one bar. That picking process is called Sampling.

1. The Temperature Dial

Before spinning the wheel to pick a word, we can reshape the skyline using a single dial called Temperature:

Drag the Temperature slider below and watch the eight candidate bars reshape in real time. Then hit Spin the Wheel a few times at cold, warm, and hot settings to feel how the picks change.

Interactive Lab 1 The Temperature Landscape
"Once upon a time, in a quiet forest, a young ___" Balanced · Natural Creativity
Recent spins: Click "Spin the Wheel" to sample a word!
Temperature 0.90
At 0.0, fox towers near 100% and wins every spin. Turn the dial up toward 2.0, and even spoon glows nearly as tall as fox!

2. Trimming the Absurd Tail: Top-K & Top-P

Even at a gentle temperature, there is a hidden trap: a language model's vocabulary contains tens of thousands of tokens. Individually, words like spoon or refrigerator have tiny chances—but add thousands of tiny slivers together, and once in a while the wheel will land on complete nonsense.

To keep creativity without the nonsense, we place a glowing cutoff curtain that hides the unlikely "long tail" before spinning:

Why do most modern assistants love Top-P? Switch between the Creative Story and Factual Answer contexts below and watch how Top-P automatically narrows when one answer is obvious—and widens when many answers are great!

Interactive Lab 2 Top-K & Top-P (Nucleus) Cutoff Visualizer
Top-K 8
Top-P 85%
Dimmed bars beyond the cutoff curtain are excluded before sampling. Try switching to Factual Prompt with Top-P at 85%—notice how the curtain snaps shut right after Paris!
Why Temperature Isn't "Smartness"

Turning temperature down does not make a model smarter—it makes it more predictable. Turning temperature up does not make it more imaginative in a human sense—it simply lets lower-ranked words win the spin more often. Great settings match the task: low for code and facts, medium for writing and brainstorming.

3. Watch a Story Diverge

Because every single word is sampled one after another, tiny differences compound like ripples in a pond. One slightly unusual word at step 3 shifts the probability bars at step 4, which opens a whole new branch at step 5.

Click Generate Fresh Trio below to run the exact same starter sentence through three temperatures side by side—Cold (0.1), Balanced (0.8), and Wild (1.6). Watch how Cold repeats the same safe groove, Balanced explores vivid new paths, and Wild tumbles into joyful chaos.

Interactive Lab 3 Watch a Story Diverge
Cold · Temp 0.1 Predictable

Variation across clicks Very Low
Balanced · Temp 0.8 Natural Flow

Variation across clicks Sweet Spot
Wild · Temp 1.6 Chaotic

Variation across clicks Extreme
Generation #1
Click Generate Fresh Trio three or four times! Notice how Cold stays locked onto nearly the exact same sentence, Balanced invents fresh coherent scenes, and Wild veers off the rails within words.

Check Your Intuition

You are using an AI assistant to extract exact dates and invoice totals from a business receipt. Which temperature setting makes the most sense?