Lessons and outlineLesson 2 of 11

AI Concepts in PicturesLesson 2

18 min read

Inside a Model: Tokens, Attention and Context

How a language model reads and writes, step by step, with no maths.

In plain English

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.
Picture it
How a model writes
1
Read tokens
Your text, in pieces
2
Look back
Attention picks what matters
3
Pick next token
The most fitting one
4
Add it and repeat
Until the answer is done
Then it goes back to step 1 and repeats

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.

tokens.txt
"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.

Try it yourself
See your own text turn into tokens

Type anything and watch it split into pieces.

Autonomous·agents·observed·the·environment·in·2026.
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.

Try it yourself
Turn the temperature dial

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%
Click several times. Low temperature gives the same word. High gives more variety.

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.
→If a chat goes strange, start a fresh one and paste only the facts that matter. A clean desk beats a messy one.
⚠Fluent does not mean true. The model is built to sound right. Verify numbers, names and quotes.
Key takeaways
  • ✓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.
Hands-on exercise

See tokens at work

  1. Open a free token counter, or use a chat tool that shows length.
  2. Paste a short paragraph and note the token count.
  3. Paste a paragraph with rare words and numbers. Compare the counts.
  4. Write one sentence on why long, messy text costs more.
Check yourself
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.

0 / 11 finished0%