Maths for LLMs
Softmax: How LLM Scores Become Probabilities
Softmax is a small equation with a central job: it turns arbitrary model scores into positive weights that sum to one. Here is the arithmetic, the numerical-stability trick, and where the same operation appears inside an LLM.
13 Sep 2026
·
4 min read
·77 views
LLMs, the whole thing
·
Part 9
Multi-head attention, one shape at a time
Part 9 of LLMs, the whole thing: two heads, one token, and the difference between computing attention and organizing its tensors. A concrete PyTorch walkthrough of view, transpose, concatenation and the output projection.
10 Sep 2026
·
5 min read
·67 views
LLMs, the whole thing
·
Part 8
Causal attention and the two masks: one hides the future, one cuts links on purpose
Section 3.5 of Raschka's book on seven real GPT-2 tokens: why masking after softmax breaks the row sums, why -inf on the scores fixes it in one pass, and how dropout is a second, random mask that doubles its survivors.
7 Sep 2026
·
6 min read
·77 views
LLMs, the whole thing
·
Part 7
Trainable self-attention: query, key, value, and a thermostat on the softmax
Section 3.4 of Raschka's book on six tokens with real PyTorch output: three shared learned matrices, eighteen private q/k/v vectors, why d_in is forced, why scores are divided by the square root of d_k, and why 'weights' now means two different things.
3 Sep 2026
·
12 min read
·62 views
LLMs, the whole thing
·
Part 6
Self-attention, from scratch: a context vector is a weighted average
The first attention mechanism in Raschka's LLM book, explained the way it finally clicked for me, a Java dev who bounces off dense maths: self-attention is just three operations, a dot product, a softmax, and a weighted average.
18 Aug 2026
·
9 min read
·138 views