HOW LLMS
WORK

a visual guide to language models

Four steps. That's all it takes to understand how these things work.

IT professional exploring how AI systems work under the hood.

01 TRAINING

reading a lot of stuff

Diagram: Books, web, and code data sources with flowing streams converging into a neural network cluster, showing how LLMs learn patterns from diverse text Books Web Code Model

These models learned to write by reading. A lot. More text than any human could read in a thousand lifetimes: every Wikipedia article, millions of books, most of Reddit, and a concerning amount of fan fiction.

They didn't memorize it all. They just noticed patterns. Which words follow other words. What good sentences look like. How questions get answered. After enough examples, they got surprisingly good at guessing what comes next.

02 TOKENS

words become numbers

Diagram: The sentence 'The quick brown fox' split into five tokens, each with a numeric ID (791, 4248, 8516, 2116, 1) that the model processes "The quick brown fox" "The quick brown fox " #791 #4248 #8516 #2116 #1 Each token maps to a number the model understands

Computers can't read letters. They only understand numbers. So your words get chopped into little pieces called tokens.

Common words like "the" stay whole. Longer words get split up. "Breakfast" becomes "break" + "fast". Each piece gets a number, and those numbers are what the model actually sees. Your sentence becomes a list of numbers. Weird, but it works.

03 ATTENTION

figuring out what matters

Diagram: Six tokens 'The cat sat on the mat' with attention lines connecting 'sat' to other words - thicker lines to 'cat' and 'mat' show stronger contextual relationships Input Tokens The cat sat on the mat Thicker lines = stronger attention Repeated across many layers (GPT-4 has 120+)

Not all words matter equally to each other. When you read "The cat sat on the mat," you know instantly that "cat" and "sat" go together. The word "the" is just... there.

Attention does the same thing. Each word looks around and asks: "Who here is relevant to me?" It builds invisible threads between words that belong together. This is how models understand context instead of just mashing words together randomly.

04 GENERATION

one word at a time

Diagram: Prompt 'What is the capital' with probability bars for next tokens - 'of' has the highest bar, followed by 'city', '?', and 'and', showing how models predict one token at a time Prompt: What is the capital ? Next token probabilities: of city ? and The model picks the highest probability token, then repeats

Here's the weird part: the model doesn't plan its answer. It just guesses the most likely next word. Then the next. Then the next.

It's autocomplete, trained on everything ever written. "What is the capital" → probably "of" → probably a country → and so on. That's why responses appear word by word. Each word is a fresh guess based on everything before it.