Text Into Pieces
For a long time, a famous way to trip up an AI model was to ask: "How many letter r's are there in the word strawberry?" Models that could write essays and fix code would often answer "two". Newer models usually get it right, but the old mistake tells you something important about how every model reads.
Leila That's strange. Counting letters is the easiest thing in the world. A child can do it.
Omid A child can, because a child sees the letters. What if you couldn't? What if every word arrived already cut into a few chunks, and you only ever saw the chunks?
Leila Then I'd have to remember how each chunk is spelled. Like knowing how many r's are in "berry" without looking at it.
Omid That's the model's situation. It never sees s-t-r-a-w-b-e-r-r-y. It sees three pieces: st, raw and berry. Each piece is just a number to it.
Leila Why on earth would anyone cut text up like that? Why not give it the letters?
Omid Think about this sentence you're reading. How many letters does it have, roughly?
Leila Sixty? Seventy?
Omid A model handles text one piece at a time: every piece it reads or writes costs it a step of work. With letters, that's seventy steps for one sentence, every sentence, for a whole book. Very slow and very expensive.
Leila Then whole words. One step per word.
Omid How many words are there? English alone, with names, typos, new words, "strawberryish"? Plus every other language, and code?
Leila Millions. And there would always be a new one it doesn't have.
Omid So the answer is in between: pieces bigger than letters and smaller than rare words. Common words get one piece each. Rare words are built from a few common pieces. And nothing is ever impossible, because in the worst case you can spell a word out in tiny pieces.
Tokens and the tokenizer
These pieces are called tokens. Before a model reads anything, a program called a tokenizer cuts the text into tokens and turns each one into a number. The model reads the numbers, and writes numbers back, which the tokenizer turns into text again.
The tokenizer has a fixed list of all the pieces it knows, its vocabulary. A modern one has about 100,000 to 200,000 pieces. They were chosen by looking at a huge amount of text and keeping the chunks that come up most often. A few things follow:
- Common words are one token:
the,how,today, evenunderstanding. - Spaces usually stick to the front of the next word:
how, nothowplus a space. - Rare and long words split:
unbelievablybecomesun,bel,ievably.TokenizationbecomesTokenandization. - Numbers split into chunks:
1234567becomes123,456,7. That's one reason models used to make silly slips in arithmetic with long numbers.
Every company trains its own tokenizer, so the exact pieces differ a little between models. The examples here are from a widely used public one.
How long is a token?
For ordinary English, a useful rule of thumb: one token is about four characters, or about three quarters of a word. So 1,000 tokens is roughly 750 words, a page and a half of a book.
Other languages often need more. A tokenizer's vocabulary is mostly built from the text it was trained on, and much of that is English, so English words are more likely to be whole pieces. When the same short paragraph was written in English and in Persian, one widely used tokenizer needed 40 tokens for the English and 62 for the Persian. An older tokenizer, with half the vocabulary, needed 127 for the Persian.
Leila So if I work in Persian, the model has to read more tokens to get the same message.
Omid Yes. And you'll see over the next lessons why that matters: tokens are what everything is measured in.
Why tokens matter for agents
Tokens are the unit of everything in the rest of this course:
- Speed: a model writes its answer one token at a time, so a long answer takes longer.
- Limits: there's a maximum number of tokens a model can see at once.
- Price: AI companies charge per token, for what goes in and what comes out.
An agent reads a lot: files, web pages, the results of commands. All of it becomes tokens. When you start counting in tokens instead of in "messages", much of what agents do, and much of what goes wrong, starts to make sense.
Try it
Search the web for "tokenizer" and open one of the free online token counters (several AI companies offer one). Paste in a sentence, a long rare word, a number like 1234567, and a sentence in another language you know. Look at where the pieces break, and compare the token counts.
Using it well
- Don't trust a model with exact letter-level jobs: counting letters, reversing a word, exact character limits. It doesn't see letters. If it matters, ask it to write and run a small program (an agent can), or check yourself.
- Estimate in tokens. About 750 English words per 1,000 tokens is close enough to tell whether a document is small or huge for a model.
- Expect other languages to cost more. The same conversation in Persian, Arabic or Hindi can take one and a half times as many tokens as in English, or more, and fills a model's limits sooner.
Words to know
- token - a piece of text a model reads or writes: a common word, part of a word, a punctuation mark or a chunk of a number
- tokenizer - the program that cuts text into tokens and turns them into numbers, and back again
- vocabulary - the fixed list of all the tokens a tokenizer knows
Big idea
A model doesn't read letters or words. It reads tokens, chunks of text from a fixed vocabulary, and everything about an agent is measured in them: how fast it works, how much it can see, and what it costs.