Lesson 3
How does a model read text?
What a token is, where its number comes from, and why the same sentence can cost more in Hindi.
1How does a model read the words you type?
A model can't read words. It only works with numbers, so your text has to be turned into numbers first.
- 🧮Inside, a model works only with numbers. Mostly it multiplies them and adds them up. 1 × 3 + 2 × 1 = 5, like the layers in lesson 2.
- ✂️So the text is cut up first. A tokenizer is a separate program that cuts your text into pieces. I have a pet becomes 4 pieces: I, have, a, pet.
- ␣On the pieces in this lesson, the mark ␣ means a space. The space is part of the piece that comes after it. ␣pet is one piece: a space, then the word pet.
- 🔢Then the tokenizer swaps each piece for a number. ␣pet becomes 5716.
From your text to numbers, and back
I have a pet
- I40
- ␣have679
- ␣a261
- ␣pet5716
40, 679, 261, 5716
6446 → ␣dog
You type a sentence. Nothing is cut yet.
The tokenizer cuts the sentence into 4 pieces. ␣ is a space that belongs to the piece after it.
The tokenizer swaps each piece for its number: I is 40, ␣pet is 5716.
The model gets only these 4 numbers. It never sees the letters p, e, t.
The model's guess for the next word also comes out as a number, 6446. The tokenizer turns it back into text: ␣dog.
Real pieces and numbers from GPT-4o's tokenizer. ␣ marks a space. The guess dog is an example we picked; its number is real. The colours only help you see where one piece ends and the next begins.
2What is a token?
A token is one piece of text that a model reads. Each token has a number, and every piece with its number sits in one fixed list.
- 🧩Token: a piece of text. It can be a whole word, part of a word, or a mark like a comma. ␣pet is a whole word. nin is part of a word: the typo runnin is cut into run and nin. The full stop is a mark.
- 🔢Token id: the number for one token. In GPT-4o's tokenizer, ␣dog is 6446.
- 📖Vocabulary: the list of every token the tokenizer knows, each with its id. GPT-4o's vocabulary has about 2 lakh tokens (200,000).
Two things to know about token ids:
- 🔒The list never changes, so the same piece always gets the same id, in every sentence, for every user. ␣dog is 6446 in I have a pet dog. and also in My dog is big.
- 🤷The id says nothing about what the word means. ␣Dog with a capital D is 18018. Nothing in 6446 and 18018 says they are the same animal. The model has to learn that from text.
The word dog: which id?
- ␣dog6446
- ␣dog6446
- ␣Dog18018
Real ids from GPT-4o's tokenizer. ␣ marks a space that is part of the piece.
3Why are tokens pieces of words, not letters or whole words?
Pieces of words are the middle choice between single letters and whole words. Letters make every sentence a very long list, and whole words leave too much out.
- 🔤If every letter were a token, sentences would become very long lists. The word dog would be 3 tokens (d, o, g) instead of 1.
- ❓And a single letter means almost nothing on its own. The letter t could belong to tea, cat or tiger.
- 📕If every whole word were a token, no list could hold every word, name and typo. A word missing from the list could not be read at all. The typo runnin is in no dictionary.
- 🧩Pieces fix both problems. A common word is one token. Any other word is built from smaller pieces that are on the list. running is one token. The typo runnin is built from two: run + nin.
One word: how many pieces?
- ␣running6788
- ␣run2461
- nin54173
Real pieces and ids from GPT-4o's tokenizer. ␣ marks a space that is part of the piece.
4Who decides how text is cut into pieces?
A separate program makes the list of pieces, before the model is trained. The program looks through a big pile of text. It finds the two pieces that sit side by side most often, and joins them into one new piece.
- 1️⃣Start with single letters. sing is s, i, n, g.
- 2️⃣Count how often each pair of pieces sits side by side in the pile. In the pile sing ring win pin, i and n sit side by side 4 times.
- 3️⃣Join the most common pair into one new piece, and add it to the list. in joins the list.
- 4️⃣Count again and join again, until the list is as big as its makers chose. Next, in and g sit side by side 2 times, so ing joins the list.
Building a list from the pile sing ring win pin
A made-up pile of 4 words, so you can check every count. A real tokenizer counts a huge pile of text and stops at a far bigger list.
- 🔗A model does not choose its own tokens. It gets the list before training starts, and it must keep using that same list. GPT-4o learned that 6446 is ␣dog. With another list, 6446 would be some other piece, and what it learned about 6446 would be wrong.
5Why does the same sentence cost more in Hindi?
AI companies charge for each token, not for each word. Hindi usually needs more tokens than English to say the same thing, so the same sentence costs more in Hindi.
- 💰You pay for each token. I have a pet dog. has 5 words but 6 tokens, so you pay for 6 tokens.
- 📊The list was built by counting a big pile of text (section 4). Pieces that showed up often became whole tokens. Text that showed up less often gets cut into smaller pieces. The pile had less Hindi text than English, so Hindi words get cut into more pieces. ␣pet is 1 piece, but ␣पालतू (pet) is 3.
The word "pet": how many pieces?
- ␣pet5716
- ␣प1583
- ालत117552
- ू2796
Each word as it appears in the two sentences below, with the space before it. ␣ marks a space. A piece can be just part of a letter, like the vowel mark in the third piece. A dotted circle on a piece means a mark that is written on a letter, like a vowel sign, but has no letter in front of it in this piece. Real pieces and ids from GPT-4o's tokenizer.
Tokens for the whole sentence
- I40
- ␣have679
- ␣a261
- ␣pet5716
- ␣dog6446
- .13
6 tokens for the whole sentence
- मे59041
- रे9689
- ␣पास38351
- ␣एक6298
- ␣प1583
- ालत117552
- ू2796
- ␣क848
- ुत19688
- ्ता88306
- ␣है2487
- ।1670
12 tokens for the whole sentence
- English6
- Hindi12
GPT-4o's tokenizer cuts the English sentence into 6 tokens. The word pet, with an orange border, is 1 of them.
It cuts the Hindi sentence, which says the same thing, into 12 tokens. The 3 with an orange border are पालतू (pet).
The whole sentence: English is 6 tokens, Hindi is 12. At the same price per token, the Hindi sentence costs twice as much.
Real pieces, ids and counts from GPT-4o's tokenizer. ␣ marks a space. Both sentences say the same thing. The orange border marks the word pet: 1 piece in English, 3 in Hindi. The orange bars are Hindi.
A token id is only a number: 6446 says nothing about what a dog is. So how does a model know that cat and dog are alike, while cat and car are not? Lesson 4 starts there.
Where this comes from
- Every token piece, id and count on this page: run on 2026-10-31 with OpenAI's tiktoken 0.14.0. GPT-4o's tokenizer is the encoding o200k_base; tiktoken's own model table maps gpt-4o to o200k_base. github.com/openai/tiktoken. In o200k_base: I have a pet = I 40, ␣have 679, ␣a 261, ␣pet 5716. ␣dog 6446 (in I have a pet dog. and My dog is big.); ␣Dog 18018 (in I have a pet Dog.). ␣running 6788 (in I am running); ␣run 2461 + nin 54173 (in I am runnin). ␣pet 5716; ␣पालतू = ␣प 1583 + ालत 117552 + ू 2796. I have a pet dog. = 6 tokens (I 40, ␣have 679, ␣a 261, ␣pet 5716, ␣dog 6446, . 13); the Hindi sentence = 12 tokens (ids as shown).
- About 2 lakh tokens in GPT-4o's vocabulary: o200k_base reports n_vocab = 200,019 in tiktoken 0.14.0 (199,998 ordinary pieces plus special markers).
- Models work on ids, not text; ids come from a table in the tokenizer; the answer is decoded back: Hands-On Large Language Models, ch.2, PDF p.70-74: the ids "reference a table inside the tokenizer containing all the tokens it knows"; output ids such as 3323 and 622 decode to "Sub" + "ject".
- Ids carry no relation by themselves: How Large Language Models Work (Raff, Farris, Biderman; Manning 2025), ch.2, PDF p.38: "Dis" is 4944 and "dis" is 834 in GPT-3, and "the relationships are learned through observation of data."
- Letters vs words vs pieces: Hands-On Large Language Models, ch.2, PDF p.75-78 (word tokens cannot handle new words; character tokens make the model spell everything out; subwords are the middle).
- Building the list by joining the most common pair, before the model is trained: How Large Language Models Work, ch.2, PDF p.43 ("n"+"g" becomes "ng", later "i"+"ng" becomes "ing"; repeat until the vocabulary is the chosen size). Hands-On Large Language Models, ch.2, PDF p.95: "A pretrained language model is linked with its tokenizer and can't use a different tokenizer without training."
- Charged per token; rarer languages cut into more pieces: How Large Language Models Work, ch.2, PDF p.48-49: rarer languages get more, smaller pieces, and providers charge per token.
- Made up on purpose: the 4-word pile sing ring win pin in section 4 (its counts are worked out on the page), and the guess dog in section 1 (its id is real). All web pages accessed 2026-10-31.