How modern language models work
The whole article as a progression of ideas, one line each. Every step links to its full section.
From text to vectors
- TextA language model never reads letters directly: before it can do anything, text has to become a sequence of integers.
- TokenizationText is split into units from a fixed vocabulary: whole words, pieces of words, or raw bytes.
- Token IDsEach token is replaced by its position in the vocabulary. The number is an index, and carries no meaning of its own.
- EmbeddingsToken IDs select rows of a learned table of vectors: the model's starting point for each token, not its final word on meaning.
- Positional informationAttention on its own ignores word order, so position has to be injected. Most current models do it by rotating queries and keys (RoPE).
Inside the transformer
- Context-dependent representationsAs vectors pass through the network, each token's representation is rewritten using the tokens around it.
- Transformer layersA transformer is a stack of blocks. Each one lets tokens exchange information (attention), then transforms every token on its own (an MLP).
- Self-attentionEach token's representation gathers information from other positions in the context, weighted by how relevant the model computes them to be.
- Queries, keys and valuesEach token is projected into a query (what it looks for), a key (what it can be matched on) and a value (what it passes along).
- Dense attentionIn full (dense) attention every token can attend to every earlier token, so the work grows with the square of the sequence length.
- Sparse and sliding-window attentionSome attention layers restrict each token to a window or pattern of positions, trading direct reach for lower cost. It all happens inside the model.
- Context windowsThe context window is the most tokens a model can process at once: prompt, documents, tool results and its own output together.
- KV cacheDuring generation, keys and values already computed for earlier tokens are kept and reused, so each new token only computes its own.
Choosing the next token
- LogitsThe final representation at the last position is turned into one score per vocabulary entry: the logits.
- Probabilities and softmaxSoftmax turns the logits into a probability distribution over the entire vocabulary.
- Decoding and samplingGeneration is a loop: choose one token from the distribution, append it to the input, run the model again.
- Temperature, top-k and top-pTemperature reshapes the distribution; top-k and top-p cut off its unlikely tail before a token is drawn.
- What happens to the tokens not chosenNext-token candidates that were not chosen are normally discarded. The model does not keep them as alternative lines of reasoning.
- Multiple samples, search and verificationSystems can explore alternatives deliberately: generate several candidates, search over partial solutions, and check the results. It is an outer loop around generation.
Running a model yourself
- QuantizationQuantization stores a model's weights in fewer bits, such as 8 or 4 instead of 16, trading a little accuracy for a model that is smaller and faster to read.
- Running a model on your own hardwareWhether a model runs locally is mostly a question of memory: it must hold the weights and the KV cache, and generation speed is set by how fast those weights can be read.
Bringing in outside information
- Retrieval-augmented generationRAG searches an external collection at request time and places the most relevant passages in the context before the model answers.
- Retrieval versus attentionAttention mixes information among tokens already in the context. Retrieval decides which outside information gets into the context at all.
- External memoryAnything a system should remember beyond one context window has to be stored outside the model and read back in as tokens.
- Tool useA model can emit a structured request to call a tool. Software outside the model runs it and feeds the result back into the context.
- Model Context Protocol (MCP)MCP is an open protocol for exposing tools, data and prompts to AI applications. It standardises the connection, not the retrieval.
- Codebase-aware retrievalCoding agents find the relevant parts of a repository with search tools, such as text search, symbol indexes, embeddings or code graphs, and read them into context.
Learning, and what the words mean
- Inference versus trainingTraining changes a model's weights. Inference, meaning ordinary use, runs fixed weights and changes nothing in the model.
- HallucinationA model can state something false as fluently as something true, because it generates likely text and has no store of facts to check against.
- Self-training and synthetic dataModel outputs that have been filtered, checked or ranked can become training data for a later model: a learning loop outside generation.
- Recursive self-improvementThe idea that an AI system could improve its own capabilities, including its ability to improve itself. A research concept, not a current mechanism.
- AGI, and why definitions varyArtificial general intelligence has no single agreed definition, so any claim about it depends on which definition is being used.