Tokenizer
The device that cuts text into a fixed list of pieces and numbers them
- A tokenizer is the device that cuts text into pieces the model can accept and swaps each piece for a number. It's the gatekeeper standing right in front of the model.
- It cuts according to a fixed list of pieces, built in advance. A word already whole on the list stays one piece; a word missing from it gets split into several.
- The list isn't written by hand — it's built automatically by repeatedly merging whichever pair of characters shows up together most often across a huge pile of text.
- Handing back an answer runs the process in reverse: numbers get turned back into letters. Cutting and rebuilding both rely on the same list.
- The list is different for every model, which is why the same sentence can split into a different number of pieces depending on which model it's fed to.
Contents
1The analogy
Walk into a public bathhouse and you get assigned a locker, with a numbered key strapped to your wrist. Lockers come in fixed sizes, so if your bag is too big it won't fit in just one. In that case it gets split across two or three lockers, and you get that many keys. A tokenizer is the attendant who sorts text into fixed lockers this way and hands out the numbers.
The types and sizes of lockers were all decided when the place was built. Common items people check all the time get a roomy locker of their own and go in whole; a large, unfamiliar item nobody's seen before gets broken down and scattered across several lockers. That's why an everyday greeting is one piece while an unfamiliar name comes out as three or four.
On the way out, all you need is the number. Hand it over and your item comes back exactly as it went in.
2In detail
The locker list was built automatically
The way the list gets built is surprisingly simple. Start by treating every single character as its own tiny locker. Then scan the entire training text over and over, find whichever pair of characters shows up together most often, merge it into one, and register that merged chunk as a new locker. Repeat this merging tens of thousands of times and the list is done.
Whatever shows up most often gets merged earliest and claims a big locker. Common particles, endings, and frequent words earn their own locker that way. Rare material, on the other hand, never finishes merging and stays behind as small leftover pieces.
The list usually runs to a few tens of thousands of entries. Make it bigger and each sentence needs fewer pieces, which is more efficient — but the model has that many more candidates to juggle, which makes it heavier. The size in use today sits at a balance point between those two pulls.
Anything missing from the list gets split up
A tokenizer never gives up on a word it doesn't recognize. It's built so that any word can always be broken down into some combination of smaller pieces already on the list. Individual characters sit on the list too, so in the worst case it can still fall back to one character at a time.
That's why new slang or an unfamiliar foreign place name still gets handled without an error. The piece count just shoots up instead. A common word might take one piece while an unfamiliar name takes five — and since piece count directly drives how much text fits at once and what it costs, that gap is worth paying attention to.
Languages with more character variety run into this harder. Since the same word keeps taking on different endings and particles, plenty of word forms never make it onto the list whole and end up chopped fine.
Cutting and rebuilding use the same list
There are two directions here: cutting text into pieces and turning them into a row of numbers, and taking the row of numbers a model produced and stitching it back into letters. Both directions run on the same list, just flipped. Without the list, the numbers mean nothing at all.
That's why a model and its tokenizer always move as a matched pair. Numbers cut with a different list read as something else entirely — like showing up with a key from the wrong bathhouse.
Spaces and line breaks get folded into the pieces too, since restoring the original text exactly requires it. A leading space often gets bundled into the piece that follows it.
A different list means a different piece count
Every model-maker trained on different text, so the list pulled from that text differs too — the same sentence produces a different piece count depending on the model. One list, built from a lot of Korean text, might keep a Korean chunk whole; another, built mostly on English, chops the same Korean text finer.
That means "how many pieces is this sentence" can't be answered without naming a model first. Comparing service pricing isn't just about the rate per piece either — you need to check how many pieces the same sentence turns into on each one.
What the tokenizer causes downstream
There's a reason models often stumble on long arithmetic: digits don't always get cut along place-value boundaries, they get chopped into arbitrary chunks — and the same number can split differently depending on where the cut lands, which makes it hard to learn a consistent rule.
The same cause sits behind weak answers to something like "how many consonants are in this word." A model never sees individual letters — it only receives a bundled piece number, so what's actually inside a piece stays blurry to it. On the flip side, it's also why a model can shrug off a minor typo: a slightly misspelled piece still lands in a spot close to the original word.
3More precisely
A tokenizer is a program that splits a string into subword units according to a fixed vocabulary, then swaps each piece for the vocabulary's integer ID. Byte Pair Encoding is the best-known way of building that vocabulary, and other approaches that pick pieces by probability are used too. Many tokenizers today start from raw bytes instead of characters, so any character that comes in gets handled without breaking. The vocabulary itself is trained once, ahead of time, and then frozen — a live model never adds a new piece on the fly, no matter how often an unfamiliar word shows up in use. Retraining the vocabulary from scratch is the only way to change it, and doing so means retraining the model that sits behind it too.
The analogy has a limit. A bathhouse locker actually holds your belongings, but a tokenizer stores nothing at all — it only carries the rule for cutting text and turning it into numbers. A locker also sorts by looking at an item's size, while a tokenizer never looks at meaning at all. It only tracks which characters statistically travelled together, so it will cheerfully cut straight through the middle of a word.
4Try it yourself
5Common misconceptions
It's easy to think a tokenizer cuts by looking at meaning or grammar, but actually it only looks at how often characters showed up together, so it sometimes slices right through the middle of a word.
It's easy to assume a tokenizer works the same on every model, but actually the list differs by model, so the same sentence's piece count can vary quite a bit.
It's easy to think an unfamiliar word causes an error, but actually it always gets broken down into smaller pieces instead — the piece count just goes up.
7One-line summary
In shortA tokenizer sorts text into a fixed list of lockers, hands out numbers, and later turns those numbers back into text — and that list is different for every model.
Spotted an error or have a better analogy? Suggest an edit · Last updated2026-09-02