TensoriumInterview preparation
← Home

Core concepts · 62 topics

A guided path through the ideas behind modern LLMs.

Read the stages in order: how text becomes a prediction, what happens inside the Transformer block, how a model learns, then serving, scale, and post-training. Every topic names what to know first, then gives the intuition, the math with concrete numbers, the common misconception, and a self-check. Already comfortable with the basics? Switch to By area and jump straight to a topic.

New to machine learning? Start here instead.

These topics work best as a refresher; they assume ideas like probability and loss. Begin with three short beginner lessons (tokens, embeddings, next-token prediction), then the visual walkthrough for attention and the Transformer.

Finish line: You can explain how text becomes a prediction and what training does to improve that prediction.

Topic 27 of 62 · Generating and serving

Temperature, top-k, and top-p

Easy

How do temperature, top-k, and nucleus (top-p) sampling reshape the next-token distribution?

Why this mattersTemperature, top-k, and top-p reshape the next-token distribution at decode time; knowing what leaves the argmax unchanged and how truncation works prevents evaluation confounds.

1 · Start with the intuition

At each decode step, the model outputs a vector of raw logits z over the vocabulary V. Sampling strategies control the trade-off between coherence and diversity when drawing the next token: temperature T rescales the logits (z / T) before softmax to sharpen (T < 1) or flatten (T > 1) the distribution, while top-k and top-p (nucleus) truncate the long tail of low-probability tokens and renormalize the survivors so a million tiny probabilities cannot add up to a nonsensical word choice.

2 · How the mechanism works

Mechanism step 1 of 3 · no question to answer

Scale logits by temperature T

Compute z′ = z / T (for T > 0); as T → 0⁺, softmax approaches greedy argmax.

Next, we will look at: Truncate the tail (top-k / top-p). Move on when this operation makes sense.

Visualizing the behavior

Logits [2, 1, 0, −1] at three temperatures

Derived

T = 0.5 (sharper)

token A
0.865
token B
0.117
token C
0.016
token D
0.002

T = 1.0 (model distribution)

token A
0.644
token B
0.237
token C
0.087
token D
0.032

T = 2.0 (flatter)

token A
0.455
token B
0.276
token C
0.167
token D
0.102
Temperature divides the logits before softmax. The ranking never changes, only how peaked the distribution is. As T → 0 it approaches greedy decoding (argmax).

Top-p = 0.8 on [0.60, 0.25, 0.10, 0.05]

Derived

Original distribution

token A
0.600
token B
0.250
token C
0.100
token D
0.050

Smallest set reaching 0.8, renormalized

token A
0.706
token B
0.294
token C
cut
token D
cut
A (0.60) + B (0.25) = 0.85 ≥ 0.8, so C and D are removed and A and B are rescaled by 1/0.85. On a flatter distribution, the same p keeps more tokens; that adaptivity is the point of nucleus sampling.