Lessons and outlineLesson 2 of 11
AI Concepts in PicturesLesson 2
Inside a Model: Tokens, Attention and Context
How a language model reads and writes, step by step, with no maths.
A model reads tokens, which are small pieces of text. It writes by predicting the next token, again and again. Attention lets each token look back at the ones that matter. The context window is how much fits at once.
- Token
- A small piece of text, such as a word or part of a word.
- Attention
- How each token looks back at the tokens that matter.
- Context window
- The most text a model can hold at once.
Layer 1 is the model. Inside it, three ideas do most of the work: tokens, attention and the context window. You do not need maths to understand them. A picture is enough. This lesson explains how a language model reads and writes, one small step at a time.
Step one: text becomes tokens
A model does not read letters or whole words. It reads tokens. A token is a small piece of text. Short common words are often one token. Long or rare words are split into pieces. Numbers and code are split too.
"Unbelievable results" -> [Un] [believ] [able] [ results] "cat" -> [cat] "2026" -> [20] [26]
Tokens matter because they are the unit of everything. Models limit tokens. Providers charge by the token. Longer text means more tokens.
Type anything and watch it split into pieces.
- Tokens
- 13
- Words
- 7
- Characters
- 51
A dot marks a space. This demo only imitates a real tokenizer. Real ones split a little differently, but the idea is the same: long and rare words become several tokens.
Step two: the model predicts the next token
The model looks at the tokens so far. It gives a score to every possible next token. It picks one. Then it adds that token and does it again. A whole answer is this loop, repeated many times.
- The model is very good at what sounds right next.
- It is not looking up facts in a database.
- That is why it can sound sure and still be wrong.
Step three: attention
How does it choose the next token? It uses attention. Attention lets each token look back at the other tokens and decide which ones matter. In the sentence the trophy did not fit in the case because it was too big, attention helps link it to the trophy, not the case.
You can think of attention as a spotlight. For every word, the model moves a spotlight over the earlier words and shines it brightest on the helpful ones.
The context window
The context window is the most text the model can hold in mind at once. It counts your prompt, the chat so far and the answer. When the window is full, something must be cut. A bigger window is like a bigger desk. You can lay out more papers. Yet even on a big desk, details in the middle of very long text can be missed.
A dial called temperature
Many tools let you set temperature. It controls how adventurous the pick is. A low setting gives steady, repeatable answers. A high setting gives more variety. Use low for facts and rules. Use high for brainstorming.
Slide it, then pick a word several times to feel the difference.
The model must finish: “The capital of France is ___”
- Paris94%
- a3%
- the2%
- located1%
- known0%
- Lyon0%
Why this matters in daily use
- Long chats cost more and may lose early details.
- Clear, specific text helps the model pick the right next tokens.
- A model can be fluent and wrong, so check what matters.
- ✓A model reads tokens, which are small pieces of text. Providers charge by the token.
- ✓It writes by predicting the next token, again and again.
- ✓Attention lets each token look back at the tokens that matter.
- ✓The context window is how much text fits at once, like a desk.
- ✓Low temperature gives steady answers. High temperature gives variety.
See tokens at work
- Open a free token counter, or use a chat tool that shows length.
- Paste a short paragraph and note the token count.
- Paste a paragraph with rare words and numbers. Compare the counts.
- Write one sentence on why long, messy text costs more.
Q1What is a token?show answer
A small piece of text, such as a word or part of a word. Models read and write in tokens.
Q2Why can a model sound sure and still be wrong?show answer
It predicts what sounds right next. It does not look facts up.
Q3What does the context window limit?show answer
How much text the model can hold at once, counting the prompt, the chat and the answer.