A model that continues text
A large language model (LLM) is trained on a very large amount of text. Its core task is narrow: given a sequence of text, estimate what is likely to come next. Google’s machine learning course defines a language model in exactly these terms, as something that estimates the probability of a token or sequence of tokens appearing in a longer sequence. Conversation, summarising and writing code are all built on that one ability.
When a chat tool answers you, the model is not retrieving a finished paragraph. It produces one small piece of text, appends it to what came before and predicts the next piece again. The answer is assembled step by step, which is also why it can stream onto your screen as it is generated.
Tokens, not words
Models do not read letters or words directly. A tokenizer first splits the text into tokens: a token can be a whole word, part of a word or a single character, along with punctuation and spaces. The model only ever sees sequences of these tokens.
This matters in practice because limits and prices are counted in tokens. For English text a common rule of thumb is roughly one and a half tokens per word, but it depends on the tokenizer and the language. Turkish words that carry several suffixes are often split into more pieces, so the same content can cost more tokens in Turkish than in English.
Why the same question gets different answers
At each step the model does not produce a single “right” next token. It produces a probability for every token in its vocabulary. 3Blue1Brown’s short explainer visualises this well: the model ends each step with a ranked list of candidates, and the text is built by picking from that list again and again.
If the system always picked the most likely token, the same input would always give the same output. In practice it usually samples from the list, with a setting (often called temperature) that controls how adventurous the choice is. That is why asking the same question twice can produce two differently worded answers, and why a low setting is preferred when you need consistent, predictable output.
Data, architecture and two stages of training
Data: the model learns from a large collection of text, and often code. What is in that collection, and what is missing from it, shapes what the model is good and bad at.
Architecture: today’s LLMs are built on the transformer, introduced in the 2017 paper “Attention Is All You Need”. Its key mechanism, attention, lets the representation of each token take the other tokens into account, so the model can connect a pronoun to a name a few sentences earlier.
Training: Andrej Karpathy’s introductory talk describes two stages. In pretraining, the parameters are adjusted on a huge amount of text so that next-token predictions get closer to the real text; the result is a base model that continues documents. In fine-tuning, the model is trained further on examples of questions and good answers, and on human feedback, which turns it into an assistant that follows requests.
The context window is working memory
Anthropic’s documentation describes the context window as all the text a model can reference when generating a response, including the response itself. That covers system instructions, the conversation so far, any documents you added and the answer being written. Whatever is outside the window does not exist for the model.
A chat that seems to remember earlier messages is usually just sending the history again with every request. When the conversation outgrows the window, something has to be dropped or summarised, and details from the beginning can be lost.
Larger windows are not free. With standard attention, the work grows much faster than the text: IBM Research notes that doubling the length of the input requires about four times as much memory and compute.
What this means when you build with it
Estimate size and cost in tokens, not characters, and measure them with the tokenizer of the model you actually use. Decide deliberately what goes into the window: instructions, the relevant data and enough history, rather than everything you have.
Remember that the model generates likely text; it does not look facts up. That is why a fluent answer can still be wrong, a topic this series returns to in its last note. The next note covers how to write prompts that make the model’s job clearer.
References
- Andrej Karpathy: Intro to Large Language Models (video, November 2023)
- 3Blue1Brown: Large Language Models explained briefly (video, November 2024)
- Google Machine Learning Crash Course: Introduction to Large Language Models
- Vaswani et al.: Attention Is All You Need (arXiv, June 2017)
- Anthropic documentation: Context windows
- IBM Research: What’s an LLM context window and why is it getting larger? (July 2024)
- IBM Technology: How Large Language Models Work (video, July 2023)