4 December 2026

AI and agents, every day. Straight to it.

ToolsQuick notes

LLM Math attaches a NumPy snippet to every language-model formula

A free guide pairs every LLM formula with an already-run NumPy snippet, so you can check the math in code.

Diego Sato

· 2 min read

Read in Portuguese

If language-model papers lose you at the notation, here is a shortcut. The LLM Math guide, built and run by Serein, sets each formula next to a NumPy snippet. The page was shared on Hacker News on November 28; it gives no date for when it first went live.

The material follows the order in which a model uses the math, from byte-pair encoding (BPE) to speculative decoding. It is split into three parts: the model (tokenization, embeddings, attention), training (loss, the Adam and AdamW optimizers, scaling laws) and serving and tuning (the KV cache, quantization, LoRA, RLHF). Every formula comes with a plain explanation, where an LLM uses it and the paper it came from. According to the site, each code block was run before the page was built.

One example: vocabulary size is the base alphabet plus the number of merges plus any special tokens. For GPT-2, the arithmetic works out like this:

def vocab_size(base=256, merges=50_000, special=1):
    return base + merges + special

print(vocab_size()) # 50257

Verdict: useful for engineers who would rather check a formula by running it than by staring at symbols. The catch is scale. The snippets work on toy matrices, such as a 10-token vocabulary in the embeddings example, so they illustrate the math rather than serve as production code.

Report an error

Use 10–1,000 characters; a reply email shares this space.

Next in your reading list