Breaking Language Into Pieces
Before a model reads text, it chops it into pieces. Meet the token and the tokenizer.
A quick note on how we teach here. You won't find equations or numbers in this series, and that is on purpose. The goal is understanding, not arithmetic, so every idea is explained in plain words and simple pictures. When you want the math later, the rest of Internals Decoded is ready for you.
Welcome back. In the last piece we gave a name to the finished, trained thing that all that practice leaves behind. We called it a model. Today we look at the very first thing that happens when a language model meets a sentence. Before it can do anything else, it has to break the sentence into small, standard pieces.
The idea is simple. A model does not read words the way you do. It chops language into chunks, and it works with those chunks instead of whole words or individual letters.
A pile of bricks, not a lump of clay
Imagine you are building a toy castle out of interlocking bricks. You do not sit down and mold a brand new custom shape for every tower, every window, every door. Instead you reach into a big bucket of standard bricks. Some bricks are shaped for very common parts. A single brick might be a whole door. Another might be a tiny flag. For something rare, like a fancy curved turret, you snap together several smaller bricks to make the shape you need.
A language model works the same way. It does not look at a sentence as a smooth stream of letters. It has a fixed set of building blocks for language. Common words get a block of their own. A word like "the" appears so often that it gets its own single block. A long or unusual word might not have its own block. Instead the model snaps together a few smaller blocks to build it. The model never sees the raw letters. It only sees the blocks.
Here is a real example. OpenAI shares the chopping tool behind several of its GPT models in a free library called tiktoken. Give that tool "The cat sat on the mat" and you get one block per word: "The", "cat", "sat", "on", "the", "mat". Each block quietly carries the space in front of its word. Now give it "hippopotamus". That word is too rare for a block of its own, so it comes out in pieces: "hipp", "opot" and "amus".
Why not just whole words?
You might wonder why the model does not simply give every word its own block. There are two good reasons. First, there are far too many words. New words, names, slang and typos appear all the time, and a model cannot carry a block for every one. With small pieces in the bucket, it can still build any word at all, even one it has never seen. Second, a fixed bucket of standard pieces keeps things manageable: common words get their own block, and anything rarer is built from smaller pieces.
The chopping tool learns its blocks by noticing which groups of letters show up together most often in a huge pile of text. One common method, called byte pair encoding, starts from single letters and keeps gluing together whichever pair turns up side by side most often, until the bucket is full, as Hugging Face's course on byte pair encoding explains. Because it goes by how often, not by grammar, the splits do not always line up with the meaningful parts of a word. In that same OpenAI tool, the common word "unbelievable" is a single block, while the rarer "unhappiness" comes apart as "unh" and "appiness", which is not how a dictionary would divide it. The model learns how its blocks relate to each other from the sentences it reads, not from the way they were cut.
The surprise about spelling
Earlier we talked about a model guessing what comes next. That trick was all about predicting the next word. But now we know the truth. The model is really predicting the next piece, the next building block. Every time it adds to a sentence, it chooses one block from its bucket and snaps it into place.
Because the model sees blocks and not letters, it does not have a direct sense of spelling. It never looked at a word letter by letter the way you do. If you ask it how many times the letter "r" appears in "strawberry", it might stumble. In that same OpenAI tool, a plain question like this hands the model the whole word "strawberry" as one single block. Put the word in quote marks and the tool splits it into "st", "raw" and "berry". Either way, the letters inside the blocks are hidden from the model, so counting them is hard. Researchers who looked at this in a paper called Counting Ability of Large Language Models and Impact of Tokenization found that the way text is chopped into blocks makes a big difference to how well a model counts.
A model can still get there. Spell the word out with a space between each letter, and the same tool gives every letter its own block, so each letter is finally in plain view. None of this is a flaw in thinking. It is a natural result of the building block approach, which trades a letter by letter view for a system that handles words and patterns far more efficiently.
A name for the pieces
In the world of AI, each little building block is called a token. The tool that does the chopping is called a tokenizer. When you hear people say that a model processes text as tokens, this is exactly what they mean. The model breaks every sentence into tokens before it does anything else. And when it generates new text, it is picking one token after another, not one letter or one whole word at a time.
Later, when you want to see tokens with real numbers, including why AI services charge by the token, Tokens: The Currency of AI in the series AI, From Zero picks this up.
Where this is heading
So before a model reads, its tokenizer chops the text into tokens. That is the first quiet step that happens behind the scenes. Once we have these tokens, the next step feels familiar. Each token gets a place on a map of meaning, the map you first met in Turning Meaning Into Places. But there is more to that map than we could see the first time, and now that you know about knobs and training, we can take a second look.
Test yourself
Why might a model find it harder to count the letters in a word than to use that word correctly in a sentence?
Answer: Because the model sees blocks, not letters. A common word often reaches it as a single block, and the model has seen that block used in countless sentences, so it knows well how the word fits with other words. Using the word correctly only needs that knowledge of how blocks go together. Counting letters needs something the model never directly sees: the letters hidden inside the block. It is a little like knowing a song by heart without ever having seen it written down, and then being asked how many times one particular note appears. Spelling the word out letter by letter, so that each letter becomes its own block, is like writing the song out note by note.
Next: Words as Places in Meaning. It takes a second look at the map of meaning, now with tokens on it, and shows that each token's place is itself a set of knobs set by training.
Sources
- github.com · Tiktoken
- Hugging Face's course on byte pair encoding
- Counting Ability of Large Language Models and Impact of Tokenization