Availit World How AI really works, in your language

Lesson 13 of 4616 minFacts checked October 20, 2026

Tokens: how a model reads

Models do not read letters, and they do not read words. They read tokens: chunks of text, each with a number. How text is cut up explains why models stumble on spelling, why long numbers are hard, and why the same message costs more in some languages.

In this lesson you will

  • Say what a token, a token ID and a vocabulary are
  • Build a small tokenizer by hand with byte-pair encoding (BPE)
  • Read real tokenizations from Qwen3.8, DeepSeek-V4 and gpt-oss, and explain their surprises
  • Know the special tokens and the chat template that turn a conversation into one text
On this page
  1. Text becomes numbers
  2. Why not letters, or whole words?
  3. Byte-pair encoding: build a tokenizer by hand
  4. Real tokenizers, real surprises
  5. Special tokens and the chat template
  6. Remember
  7. Check yourself

Text becomes numbers

A model can only do arithmetic, so text must become numbers before it goes in. A tokenizer cuts the text into pieces called tokens and replaces each piece with its number, its token ID. Here is a real sentence cut by the tokenizer of Qwen3.8:

Tokenization␣is␣surprisingly␣important.

6 tokensQwen3.8 tokenizer; DeepSeek-V4 and gpt-oss cut it the same way

Common words are one token each, usually with the space in front included. A less common word, “Tokenization”, is two pieces. The whole list of tokens a tokenizer knows is its vocabulary, and its size is a design choice:

Vocabulary sizes (from each model’s config.json)
  • Llama 3.1 128,256 tokens
  • DeepSeek-V4 129,280 tokens
  • GLM-5.3 154,880 tokens
  • gpt-oss 201,088 tokens
  • Qwen3.8 248,320 tokens

A bigger vocabulary means fewer tokens per text, especially for languages other than English, but a bigger first and last matrix in the model.

“The cat sat on the mat.” as Qwen3.8 sees it
TokenID
The760
␣cat7993
␣sat7338
␣on383
␣the279
␣mat5344
.13

␣ marks a space. These seven numbers are all the model ever receives.

A useful rule of thumb for English: one token is about three quarters of a word, or about four characters. A 1,000-word essay is roughly 1,300 tokens. Prices, speeds and context limits are all counted in tokens, so this rule is worth remembering.

Why not letters, or whole words?

One token per letter

  • A tiny vocabulary, and nothing is ever unknown.
  • But texts become very long: every letter is one step of the model, so it is slow and the context fills up fast.
  • The model has to learn from scratch that c-a-t is a word.

One token per word

  • Short sequences, and each token means something.
  • But there are millions of words, names and typos, in thousands of languages.
  • Any word not in the list becomes “unknown”, and the model is stuck.

Modern tokenizers sit in between, with subword tokens. Frequent words get their own token; rare words are built from frequent pieces, like “Token” + “ization”. Nothing is ever unknown, because in the worst case a word is spelled out from small pieces.

Byte-pair encoding: build a tokenizer by hand

Most tokenizers are built with byte-pair encoding (BPE), an old compression trick adapted for language models in 2015. The idea is simple:

  1. Start with the smallest pieces: every single character (in modern tokenizers, every one of the 256 possible bytes).
  2. Count which two pieces appear side by side most often in a large amount of text.
  3. Merge that pair into one new piece and add it to the vocabulary.
  4. Repeat, often more than 100,000 times, until the vocabulary is the size you want.
Try itRun BPE yourself

A tiny training text: the words “low” 5 times, “lower” 2 times, “newest” 6 times and “widest” 3 times. Press the button to merge the most common pair, and watch the token count fall.

This interactive part needs JavaScript.

The first merge is “e” + “s” (it appears 9 times, in “newest” and “widest”), then “es” + “t”, then “l” + “o”. After 10 merges, “low”, “newest” and “widest” are single tokens, and the text has shrunk from 79 tokens to 20. The rare word “lower” stays in pieces: “low”, “e”, “r”. A real tokenizer does the same on trillions of characters.

Real tokenizers, real surprises

Once you know that models see tokens, many famous mistakes stop being mysterious.

“strawberry” at the start of a text (Qwen3.8)

strawberry

3 tokensWith a space in front, “ strawberry” is a single token

Ask a model how many letter r’s are in “strawberry” and it may get it wrong. It never saw the letters: it saw token number 70135, “ strawberry”, as one indivisible unit. To count letters, it has to have learned how that token is spelled, which is like asking you how many strokes are in a word you have only ever heard. Models that reason step by step can get it right by spelling the word out first, one letter per token.

The number 1234567 in Qwen3.8

1234567

7 tokensOne digit per token

The same number in DeepSeek-V4 and gpt-oss

1234567

3 tokensDigits grouped in threes

Numbers matter for maths. Older tokenizers cut numbers into irregular chunks (“12”, “345”, “67”), so the model saw the same digit in a different place each time, and arithmetic was harder to learn. Today’s tokenizers use a fixed rule: Qwen gives every digit its own token, while DeepSeek and gpt-oss group them in threes, like the commas in 1,234,567.

A line of Python (Qwen3.8)

def␣add(a,␣b):↵␣␣␣␣return␣a␣+␣b

12 tokensThe four spaces of indentation become two tokens

Spaces count too. In Qwen3.8, “the” at the start of a line is token 1719, but “ the” with a space in front is token 279, and “ The” is 561. To the model these are three different things that it has learned are related.

“Privacy” in Urdu (Qwen3.8)

پرائیویسی

5 tokensThe English word “Privacy” is a single token

Tokenizers learn their merges from their training text, which is mostly English, Chinese and code. Languages with less text online get fewer merges, so their words break into more pieces. The Chinese for “artificial intelligence”, 人工智能, is one token in Qwen3.8 and DeepSeek-V4. Urdu “پرائیویسی” is five. The lesson on AI in your language measures this on a long text, in the languages of this course.

One token or several, in Qwen3.8’s tokenizer? (All measured.)

0 of 6 sorted
  • “ the” (with a space in front)

    Answer: One token

  • “strawberry” (no space in front)

    Answer: Several tokens

  • “ Islamabad”

    Answer: One token

  • “1234567”

    Answer: Several tokens

  • “人工智能”

    Answer: One token

  • “ChatGPT”

    Answer: Several tokens

Special tokens and the chat template

Besides pieces of text, every vocabulary has a few special tokens that never appear in normal text. They mark structure: where a message starts and ends, who is speaking, where the model’s private thinking begins, where a tool call is. Qwen3.8 has 33 of them, including <|im_start|>, <|im_end|>, <think> and <tool_call>.

A chat is not really a back-and-forth. Before every reply, the app or engine turns the whole conversation into one long text, using the model’s chat template (the chat_template.jinja file from the AI stack lesson). Here is what Qwen3.8 actually reads for a short chat, with thinking switched off:

One conversation, as one text (Qwen3.8 chat template)text
<|im_start|>system
You are a helpful assistant.<|im_end|>
<|im_start|>user
What is a token?<|im_end|>
<|im_start|>assistant
<think>

</think>

  • Each message is wrapped in <|im_start|> plus the speaker’s role, and closed with <|im_end|>.
  • The text ends by opening the assistant’s turn. The model continues from there, one token at a time.
  • With thinking switched off, the template writes an empty <think> block, so the model answers straight away. With thinking on, it opens <think> and lets the model write its reasoning first.
  • When the model produces <|im_end|>, the engine stops: that special token is how a model says it has finished.

Quick check

How does a chat model know when to stop writing?

Show the answer

Answer: It produces a special end-of-message token, and the engine stops there During training the model learned to write an end token, such as Qwen’s <|im_end|>, when its reply is complete. The engine watches for it and stops.

Remember

  • A tokenizer cuts text into tokens and gives each a token ID. In English, one token is about ¾ of a word.
  • Vocabularies have 128,000 to 250,000 tokens. Subword tokens mean nothing is ever unknown.
  • Byte-pair encoding builds the vocabulary by repeatedly merging the most frequent pair, starting from bytes.
  • Tokens explain the strawberry problem, the care taken with digits, the importance of spaces, and why some languages need more tokens.
  • Special tokens and the chat template turn a whole conversation into one text; the model stops when it writes its end token.

Words to know

Token
A piece of text, often a word or part of a word, that a model reads and writes.
Token ID
The number that stands for a token. A model only ever sees these numbers.
Tokenizer
The program, with its vocabulary and rules, that turns text into token IDs and back.
Vocabulary
The full list of tokens a tokenizer knows, such as 129,280 for DeepSeek-V4.
Subword
A token smaller than a word, like “ization”, used to build rare words.
Byte-pair encoding (BPE)
Building a vocabulary by repeatedly merging the most common pair of neighbouring pieces.
Byte-level
A tokenizer that starts from the 256 bytes, so it can encode any text at all.
Special token
A token for structure, not text, such as the start or end of a message.
Chat template
The rule for writing a conversation, with roles and special tokens, as the single text a model reads.

Go to the source

This lesson is built on these papers and documents. Paper links open arxiv.org, a separate site.

Check yourself

5 questions. Tap the answer you think is right.

0 of 5 answered

What does a model actually receive as input?

Show the answer

Answer: Token IDs: one number per token The tokenizer turns text into a list of numbers, and only those numbers go into the model.

In BPE, what is added to the vocabulary at each step?

Show the answer

Answer: The pair of neighbouring pieces that appears most often, merged into one BPE counts neighbouring pairs, merges the most frequent one into a new piece, and repeats.

Why do models often miscount the letters in a word?

Show the answer

Answer: They see the word as one or a few tokens, not as letters “ strawberry” is a single token. The model must have learned its spelling separately; it never sees the letters directly.

Roughly how many tokens is a 600-word English text?

Show the answer

Answer: About 800 One token is about ¾ of a word, so 600 words is about 600 ÷ 0.75 = 800 tokens.

What is a chat template for?

Show the answer

Answer: Writing the conversation, with roles and special tokens, as one text for the model The model reads one long text. The template lays out the system prompt, each message and the start of the reply in the exact format it was trained on.

Lesson complete

Answer every question above to complete this lesson.

Your progress is saved on this device only.

Next lessonEmbeddings: where meaning becomes geometry
Previous lesson All lessons

Choose your language