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.

From your text to numbers, and back

📝 What you type

I have a pet

✂️ The pieces, each with its number
  1. I40
  2. ␣have679
  3. ␣a261
  4. ␣pet5716
🧠 What the model gets

40, 679, 261, 5716

💬 What comes back: the model's guess for the next word, as a number

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.

Step 1 of 5

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.

Two things to know about token ids:

The word dog: which id?

    1. ␣dog6446
    in I have a pet dog.
    1. ␣dog6446
    in My dog is big. Same piece, same id.
    1. ␣Dog18018
    in I have a pet Dog., with a capital D. Different piece, different id.

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.

One word: how many pieces?

    1. ␣running6788
    from I am running: 1 piece. The word is on the list.
    1. ␣run2461
    2. nin54173
    from I am runnin: 2 pieces. The typo is not on the list, so it is built from run and nin.

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. 1️⃣Start with single letters. sing is s, i, n, g.
  2. 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. 3️⃣Join the most common pair into one new piece, and add it to the list. in joins the list.
  4. 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

Step 1 of 6

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.

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.

The word "pet": how many pieces?

    1. ␣pet5716
    English: 1 piece
    1. ␣प1583
    2. ालत117552
    3. ू2796
    Hindi, पालतू: 3 pieces

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

English: I have a pet dog.
  1. I40
  2. ␣have679
  3. ␣a261
  4. ␣pet5716
  5. ␣dog6446
  6. .13

6 tokens for the whole sentence

Hindi: मेरे पास एक पालतू कुत्ता है।
  1. मे59041
  2. रे9689
  3. ␣पास38351
  4. ␣एक6298
  5. ␣प1583
  6. ालत117552
  7. ू2796
  8. ␣क848
  9. ुत19688
  10. ्ता88306
  11. ␣है2487
  12. ।1670

12 tokens for the whole sentence

Tokens for the whole sentence, side by side
  1. English6
  2. 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.

Step 1 of 3

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.

← Lesson 2  ·  All lessons  ·  Next lesson →

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.