Why not just words?
A word-level vocabulary can never cover typos, new slang, or every language. Subword pieces let a fixed vocabulary of ~100k entries spell anything.
No math degree required. Follow a single sentence as it becomes numbers, flows through billions of parameters, and comes back out as the next word — one prediction at a time.
An LLM does exactly one thing: given a sequence of text, it guesses what comes next. Everything else — reasoning, code, translation, poetry — is that one trick, repeated. Here is the full journey of your input.
Before anything else, your text is chopped into tokens — common chunks of characters. Frequent words become one token; rare words shatter into pieces. Each token maps to an integer ID, and that integer is all the model ever receives.
Approximation of byte-pair encoding for illustration. Real tokenizers learn their vocabulary from data — but the shape is the same: ~4 characters per token in English, far more per token in code or other alphabets.
A word-level vocabulary can never cover typos, new slang, or every language. Subword pieces let a fixed vocabulary of ~100k entries spell anything.
Cost and context limits are measured in tokens, not words. "Strawberry" may be three tokens — which is also why models famously miscount its letters.
" the" and "the" are different tokens with different IDs. That leading space carries real information about word boundaries.
Token ID 4917 means nothing on its own. The model looks it up in a giant table and gets a vector — a list of a few thousand numbers. Similar meanings end up pointing in similar directions, so geometry becomes semantics.
Because directions encode meaning, you can do math on words. The classic result: king − man + woman ≈ queen. Nobody programmed that — it fell out of the training data.
Vectors alone are order-blind: "dog bites man" would look identical to "man bites dog." So a positional signal is mixed into each vector, telling the model where each token sits.
This is the breakthrough behind the transformer. Every token compares itself to every earlier token and pulls in information from the ones that are relevant. That's how a pronoun finds its noun, and how a closing bracket finds its opener.
Illustrative weights from a single head. Real models run dozens of heads per layer in parallel, each learning a different relationship: syntax, coreference, topic, formatting.
Each token emits a query ("what am I looking for?") and a key ("what do I offer?"). Matching pairs score high, and the winner's value gets mixed into the asker.
During generation, a mask blocks every token from seeing the future. The model must predict word 12 knowing only words 1–11 — otherwise training would be cheating.
Every token compares to every other, so work grows with the square of the length. Doubling the context roughly quadruples the attention math — the core reason long context is expensive.
One attention step isn't enough. A transformer block — attention, then a feed-forward network that does the "thinking" on each token — is stacked over and over. Early layers handle grammar; deeper layers handle meaning, intent, and abstraction.
The final layer scores every token in the vocabulary. Those scores become probabilities, and one token is drawn. Temperature controls how adventurous that draw is — then the chosen token is appended to the input and the whole process runs again.
A fresh model's weights are random — its output is gibberish. Three stages turn that into something you'd want to talk to.
The model reads a huge slice of the internet, books, and code, endlessly predicting the next token. Every miss nudges billions of weights a tiny bit. This is where knowledge, grammar, and world structure are absorbed — and where nearly all the cost lives.
Pretraining yields a document-completer, not an assistant — ask it a question and it might reply with more questions. Fine-tuning on curated instruction/response pairs teaches it to answer rather than continue.
Humans (and other models) rank competing answers. Those rankings train a reward signal that shapes the model toward being helpful, honest, and safe. This stage sets the personality — not the knowledge.
There is no fact database inside — only weights that make likely text. A confident, well-formed, wrong answer is a perfectly successful prediction by the model's own objective. Grounding it in retrieved sources or tools is the fix, not asking it to try harder.
Weights are frozen after training. A chat "remembers" only because the entire transcript is re-sent with every turn. Slide past the context window and the earliest part is genuinely gone.
Your prompt doesn't instruct a program — it conditions a probability distribution. Examples, role, and format constraints all shift which continuations look likely, which is why showing beats telling.
Each token gets a fixed amount of compute. Letting the model write intermediate steps gives a hard problem more forward passes to work with — the mechanism behind chain-of-thought and reasoning models.
Tokens in, vectors through a stack of attention, a probability distribution out — repeated once per word. Everything else is scale.
Back to the top ↑