Lesson 5 of 9 · about 19 minutes
How Large Language Models Work
You'll be able to
- Explain what a token is and estimate token counts for a piece of text
- Describe next-token prediction and how a chatbot builds a reply one piece at a time
- Explain attention in plain words
- Describe the stages of training: pretraining, fine-tuning and RLHF
- Explain the context window and what temperature changes
A large language model, or LLM, is a neural network trained to do one thing: given some text, predict what comes next. Everything else (answering questions, writing code, summarizing a 90-page budget) grows out of that single skill done at enormous scale. That sounds too simple to work. It worked anyway, and the people who built it were as surprised as anyone.
Tokens: how a model sees text
Models don't read letters or words. They read tokens, chunks from a fixed vocabulary of a hundred thousand or more pieces. Common words are one token. Rare words get split into parts. Spaces usually stick to the front of the next word.
Worked example: tokenizing a sentence
Here is how OpenAI's o200k tokenizer (used by its GPT-4o generation of models) splits one sentence. Each box is one token; a dot shows a leading space.
The Millbrook water board voted 4 to 1 to raise rates by 12 percent.
[The] [·Mill] [brook] [·water] [·board] [·voted] [·] [4] [·to] [·] [1]
[·to] [·raise] [·rates] [·by] [·] [12] [·percent] [.]
14 words, 19 tokens. The made-up town name split in two. Each number became its own token, with the space before it as a separate token. A few more from the same tokenizer:
| Text | Tokens | Pieces |
|---|---|---|
| unbelievably | 3 | un / bel / ievably |
| Pemberton-Vasquez | 6 | P / ember / ton / -V / as / quez |
| 2026-10-10 | 6 | 202 / 6 / - / 10 / - / 10 |
| ¿Dónde está la biblioteca? | 6 | ¿ / Dónde / está / la / biblioteca / ? |
Other companies use different tokenizers, so counts vary by model. OpenAI's rule of thumb for English: one token is about four characters, and 100 tokens is about 75 words. So a 1,500-word article runs about 2,000 tokens.
Tokens explain some odd chatbot behavior. Ask a model how many r's are in "strawberry" and older ones often got it wrong, because they never saw letters, only chunks like "str" and "awberry." Unusual names and long numbers get chopped into pieces, which is one reason models garble them. And AI companies bill by the token, so tokens are also money.
Next-token prediction
Feed the model some tokens. It outputs a probability for every token in its vocabulary: how likely each one is to come next. Pick one, stick it on the end, feed the whole thing back in, and repeat. A 300-word answer is about 400 trips through that loop.
Here's the part that trips people up. The model is picking plausible continuations. It has no separate fact-checking step. A true sentence and a false one that sounds just as typical can get similar odds. Lesson 6 is about what that means.
Predicting one token at a time doesn't mean no planning happens inside. In a 2025 study, Anthropic researchers traced the internal activity of their model writing rhyming couplets and found it picked the rhyme word before writing the line that led to it.
Attention, in plain words
Consider: "The board tabled the motion because it was incomplete." What does "it" mean? You know instantly it's the motion. Change one word, "because it had run out of time," and now "it" is the board. Meaning depends on other words, sometimes far away.
Attention, the core of the 2017 transformer, handles this. For each token, the model asks a question of every other token in the text: how relevant are you to me? It scores every pair, then blends in information from the tokens that scored highest. "It" ends up carrying a strong dose of "motion." A transformer does this in dozens of layers, each with many attention "heads" looking for different kinds of relationships at the same time: one tracking who did what, another matching quotation marks, another tracking tense. Because every token looks at every other token at once, the work runs in parallel on GPUs, which is what made training on trillions of tokens possible.
Training: three stages
| Stage | What happens | Data | Result |
|---|---|---|---|
| 1. Pretraining | Next-token prediction, gradient descent, for weeks or months on thousands of GPUs | Trillions of tokens: web pages, books, code, articles | A base model: a brilliant autocomplete that will continue any text, but doesn't follow instructions well |
| 2. Supervised fine-tuning | Training on examples of good conversations | Tens of thousands of prompts with model answers written by people | A model that answers questions instead of rambling on |
| 3. RLHF (and relatives) | People rank several answers to the same prompt; a reward model learns their preferences; the chatbot is tuned to score higher | Human rankings, and increasingly AI-written feedback guided by written principles | An assistant that is more helpful and more likely to refuse harmful requests |
Ask a base model "What is the capital of France?" and it might continue with "What is the capital of Germany? What is the capital of Spain?" because that's what a quiz page looks like. Fine-tuning teaches it to answer. OpenAI's 2022 InstructGPT paper laid out this recipe, and its launch post for ChatGPT says it was trained the same way: people wrote example conversations, then ranked model replies, and the rankings trained a reward model that tuned the chatbot.
RLHF has side effects. Human raters tend to like confident, agreeable answers, so models can learn to flatter and to sound sure when they shouldn't. Companies work against this, with mixed results.
The context window
The context window is how many tokens the model can hold at once: your messages, its replies, any documents you pasted, and hidden instructions from the company. It is working memory. When a conversation outgrows it, the oldest parts drop off or get summarized. As of October 2026, Anthropic lists a 1 million token window for its current Claude models, and OpenAI's open gpt-oss models support 128,000. A million tokens is roughly 750,000 words, about the length of eight or nine typical novels. Even so, models tend to use information at the start and end of a long context better than the middle. Don't assume a huge window means it read every page carefully.
Nothing you type changes the model's weights. Each chat starts fresh unless the app adds a memory feature, which works by quietly pasting notes back into the context.
Temperature
After the model scores the candidates, the app picks one. Temperature controls how adventurous that pick is. Here are the odds from the diagram reshaped at three temperatures:
| Next word | Temperature 0.5 | Temperature 1.0 | Temperature 2.0 |
|---|---|---|---|
| rates | 86.6% | 65.2% | 46.6% |
| bills | 11.7% | 24.0% | 28.2% |
| prices | 1.6% | 8.8% | 17.1% |
| pressure | 0.1% | 2.0% | 8.1% |
The math: the model's raw scores (here 4.0, 3.0, 2.0 and 0.5) are divided by the temperature, then turned into percentages with a function called softmax. At 1.0, "rates" gets e to the 4.0 (about 54.6) out of a total of about 83.7, which is 65.2 percent. At 0.5 the scores double before that step and the leader runs away with it. At 2.0 they halve and the field evens out. Low temperature gives steady, repetitive text; high temperature gives variety and, past a point, nonsense. Temperature does not make a model more truthful. A model sure of a wrong fact will state it at any temperature.
Reporting angle
If an agency or company uses a chatbot, ask which model and version, how big its context window is, and whether the vendor trains on the chats and under which setting. Request the contract, the usage invoices and any staff policy on pasting documents into a chatbot. Billing is by the token, so check cost claims: about 2,000 tokens for a 1,500-word article gives you a way to test a vendor's math. Ask whether prompts and replies are saved, and if so request them under your state's public records law (in Idaho, Idaho Code Title 74, Chapter 1). A huge context window is not proof the model read every page, so ask what checks a person did on the output.
Research angle
- OpenAI help page on tokens: how tokens are counted and the rules of thumb.
- Attention Is All You Need: the original transformer paper.
- Claude models overview: current context window sizes and model names.
- OpenAI gpt-oss announcement: an open-weight model and its stated context length.
- Tracing the thoughts of a large language model: Anthropic's interpretability study, including the rhyme planning result.
Common mix-ups
- Claim: The chatbot looks things up in a database of facts. What the evidence shows: A plain LLM generates from patterns stored in its weights. Some apps add web search on top (lesson 6), but the model itself is no database.
- Claim: It learns from my conversation as we talk. What the evidence shows: The weights are frozen during your chat. Companies may use chats to train future versions, depending on your settings and their policy.
- Claim: "It's just autocomplete" means it can't do anything impressive. What the evidence shows: Predicting the next token well across trillions of examples forces a model to pick up grammar, facts, arithmetic and some reasoning. Simple objective, complex result.
Check yourself
1. Using OpenAI's rule of thumb, about how many tokens is a 1,500-word English article?
OpenAI's help page says 100 tokens is about 75 words, so 1,500 words is about 2,000 tokens. Names, numbers and other languages often take more.
2. At its most basic, what is a language model trained to do during pretraining?
Pretraining is next-token prediction at enormous scale. Grammar, facts and style all get absorbed because they help predict the next token.
3. In the sentence "The board tabled the motion because it was incomplete," what does attention help the model do?
Attention lets each token look at every other token and decide which ones matter for its meaning. That is how "it" gets tied to "motion" and not "board."
4. What does RLHF add after pretraining?
Reinforcement learning from human feedback is how a raw text predictor gets shaped into a helpful assistant. OpenAI used it for InstructGPT and ChatGPT.
5. You lower the temperature setting to near zero. What changes?
Temperature reshapes the odds before a token is picked. Low temperature favors the top choice. It does not make the model more truthful.
6. A long chat starts going off the rails and the bot forgets instructions you gave at the start. What's a likely reason?
The context window is the model's working memory. Anything outside it is gone, and even inside it, very long contexts can dilute attention. Start a fresh chat and restate key instructions.
Terms in this lesson
- Token
- The chunk of text a model reads and writes: a whole word, part of a word, a number or a punctuation mark.
- Next-token prediction
- The model's basic job: given the text so far, give odds for every possible next token, pick one, add it, repeat.
- Attention
- The transformer's method for letting each token weigh how much every other token matters to its meaning.
- Pretraining
- The first, most expensive training stage: next-token prediction over a huge body of text.
- RLHF
- Reinforcement learning from human feedback: tuning a model toward answers human raters prefer.
- Context window
- The maximum amount of text, in tokens, a model can take in and work with at one time.
Sources
- OpenAI Help Center: What are tokens and how to count them? checked 2026-10
- Vaswani et al., Attention Is All You Need (arXiv 1706.03762) checked 2026-10
- Ouyang et al., Training language models to follow instructions with human feedback (arXiv 2203.02155) checked 2026-10
- OpenAI: Introducing ChatGPT (November 30, 2022) checked 2026-10
- Anthropic: Models overview (context windows) checked 2026-10
- OpenAI: Introducing gpt-oss (128k context) checked 2026-10
- Anthropic: Tracing the thoughts of a large language model (March 27, 2025) checked 2026-10