parallax background

LLM thinking

%alireza rashidi data science%
Machine vs Deep Learning
%alireza rashidi data science%
LLM Evaluation
Anatomy of a Choice — How an LLM Decides What Comes Next
Anatomy of a Choice
AI Architecture Series

Anatomy of a choice.

“The weather today is very…” — how does an LLM decide what comes next? Not magic, but a sequence of precise mathematical transformations: raw scores, a creativity knob, a probability translator, and a ruthless filter. This is that journey, one token at a time.

Every word you have ever read from a language model survived this exact gauntlet. Once you see the pipeline, the mystery becomes machinery.

01Overview

From numbers to a word#

The goal is narrow: predict the next token to complete the sentence. Everything the model knows about language, weather, and frogs gets compressed into four moves.

01LogitsRaw scores for every token in the vocabulary — preference before probability.
02TemperatureDivide the scores by one knob to sharpen or flatten the race.
03SoftmaxSquash scores into a true distribution: everything between 0 and 1, summing to 100%.
04·05Top-p samplingKeep the nucleus, discard the tail, sample once — then repeat for the next token.
02The pipeline

The four transformations#

Follow one prompt — “The weather today is very…” — through the machine.

The journey begins when the model scans its vocabulary — modern tokenizers hold 100,000 to 200,000+ tokens — and assigns a raw score to every candidate. These scores are logits.

Logits are unnormalized real numbers: positive or negative, no upper limit. A higher logit means the model favors the word, but these are not percentages yet.

The raw board
0 4 8 12 hot 12.5 cold 11.0 cloudy 6.0 frog -2.0 Raw scores from the final layer — unnormalized, unlimited, not yet percentages.

How to read this: “hot” and “cold” are neck-and-neck at the top, “cloudy” trails, and “frog” is buried below zero. Nothing here sums to 100 — that comes next.

Insight: these are raw outputs from the neural network’s final layer — preference, before probability.

Before scores become probabilities, we can scale them with the temperature parameter: divide every logit by it.

New_Logit = Old_Logit ÷ Temperature

Conservative (Temp < 1)

  • Differences are exaggerated. The winner becomes much stronger; the gap between “hot” and “frog” turns into a canyon.
  • Use for: factual answers, code, extraction — anywhere creativity is a bug.

Creative (Temp > 1)

  • Differences are flattened. Outliers like “frog” get a fighting chance; the distribution goes soft.
  • Use for: brainstorming, fiction, naming — anywhere surprise is the point.
Temperature does not change what the model knows — it changes how honestly it reports its preferences.Same logits, different personality.

Softmax exponentiates every logit (making them all positive) and divides by the total. After softmax, every value sits between 0 and 1, and the sum of all values is exactly 1 — 100%.

Softmax(x) = exp(x) ÷ Σ exp(all_x)
The probability pie
100% total probability After softmax, every value sits between 0 and 1 and the sum is exactly 1.
hot · 70cold · 20cloudy · 8frog · 2

How to read this: the ranking never changed — “hot” was always winning. Softmax simply makes the preference legible: 70%, not 12.5.

First, the vocabulary is sorted from highest to lowest probability. Then top-p (nucleus) sampling sets a cumulative threshold — say P = 0.90 — and keeps only the top tokens whose probabilities sum to it. The tail is discarded before sampling, so the model can never blurt a nonsensical word.

CandidateCumulative probabilityVerdict
hot (0.70)0.70KEEP
cold (0.20)0.90 — threshold reachedKEEP
cloudy (0.08)past thresholdDISCARD
frog (0.02)past thresholdDISCARD
The nucleus is dynamic: one token on confident days, dozens when the model is unsure.The filter adapts to the shape of the distribution itself.

Finally, the model samples from the survivors — weighted by their probabilities. That single sampled token is appended to the text, and the entire pipeline runs again for the next one. The weather today is very… hot.

03Steering

How I would set the knobs#

You cannot change what the model knows at inference time — but you can change how honestly it reports its preferences. That is what sampling settings are for.

What are you generating?

1
Facts, code, extraction: freeze it.

Temperature near 0 — the best answer, every time.

2
Everyday assistant work: stay balanced.

Moderate temperature, tight nucleus.

3
Ideation: open the taps.

High temperature, loose nucleus, generate many, keep one.

4
Whatever the setting, keep the tail out.

Top-p is the difference between creative and incoherent.

The mental model: logits are opinion, softmax is honesty, temperature is courage, and top-p is judgment. Choose your settings like you would choose those traits in a colleague.

The four moves between raw numbers and your next word.
Part of the AI Architecture Series · Updated 5 August 2026. Example values are illustrative.
Ali Reza Rashidi
Ali Reza Rashidi
Ali Reza Rashidi, a Senior Data Scientist-Gen Al | Al Architect | MLOps with over ten years of experience, He is the author of three books that delve into the world of data and management.

Comments are closed.

error: Content is protected!