What this is about
A language model never sees your text the way you do. Before it reads anything, a small program called a tokenizer cuts the text into pieces called tokens. A token can be a whole short word, part of a long word, a single digit, or a space and a letter together. The model reads tokens, and it writes tokens.
So when someone says "this model can take 128,000 tokens" or "this runs at 100 tokens per second", the unit is the token. Not the word, and not the letter.
Why it matters
Three things you care about are counted in tokens.
- Speed. Each token the model writes is one trip around its loop. More tokens means more trips.
- Room. A model can only look at a fixed number of tokens at once. If your text turns into many tokens, less of it fits.
- Cost. Hosted services charge per token. On your own machine the bill is time and electricity, but the time is still counted per token.
The catch is that the same sentence can cost a different number of tokens depending on the language, the topic and the tokenizer. English prose is usually cheap. Code, tool calls and numbers can be more expensive.
How it works
A tokenizer holds a list of pieces, called its vocabulary. Common pieces get their own entry. Rare words get cut into smaller entries that are in the list. The classic method is called byte-pair encoding. It starts from single bytes and keeps merging the pairs that appear together most often in a large sample of text, until the list is as long as you want.
The list is a trade. A longer list packs more text into each token, which saves trips. But the model has to score every entry in the list at every step, so a longer list makes each step slower. We measured this on a small model we train at home, called Metis, with 72,632,320 weights. Our starting list had 8,192 entries. A list of 16,384 would have cut the tokens in our big training text by 11.9 percent, but it would have added 8.4 million weights to a 72.6 million model. We did not measure the slowdown directly. We estimated about 11 percent slower per step, so we called it roughly even and kept the small list.
The shape of your text matters just as much as the list. On the starting tokenizer, Wikipedia text averaged 3.64 bytes per token. Our own notes averaged 2.42, and our tool-call rows 2.45. More bytes per token is better. Our notes were simply less like the text that tokenizer came from.
So we trained our own tokenizer, in Mojo, on a sample that included our own text. On our notes it packed 26.3 percent more bytes into each token. On tool rows, 38.1 percent more.
A cheaper token is not a better model
We expected the shorter text to help the model learn. It did not. In one run, the new tokenizer made the training text 16 percent shorter, from 401.5 million tokens to 337.4 million. The run finished in 52.2 GPU minutes instead of 61. But the quality landed within 0.1 percent of the old run, a hair short of the bar we had set. So a tokenizer bought us time and not quality. We say this with care: other changes were in the same run, so we claim a tie in quality, not a win for the tokenizer alone.
Pictures are tokens too
Images are billed in tokens as well, and by size, not by content. We sent a 900 by 300 screenshot of text to a model. As a picture it cost 363 tokens. The words in it, as plain text, cost 27. That is about 13 times more for the same words.
A larger picture was worse. A 2560 by 1107 image was billed at 3,680 tokens, even though the model only received a version resized to 1568 by 678, which counts as 1,400. Converting a PNG to a JPEG did not change the count, because the count follows pixel size. We measured one screenshot, so treat the exact numbers as an example, not a rule.
Counting tokens yourself
You can estimate tokens before you send anything. Our line counter, mokei, has a --tokens mode. Without a tokenizer file it gives an estimate that stayed within 3 percent of the real Qwen2.5 count in total on the code we checked. If you give it a real tokenizer.json, it counts exactly, but that is slower: about 0.1 seconds for a small repository, and minutes for a 140 MB tree.
Behind many tokenizers is a pattern that decides where a word may be cut. Writing that pattern needs a regular expression engine that understands all the world's scripts. We wrote one in Mojo, called mojo-uregex, for exactly this. It is checked against Python's regex module.
Words you may not know
- Token: a small piece of text that a model reads or writes.
- Tokenizer: the program that cuts text into tokens, and joins them back.
- Vocabulary: the list of pieces a tokenizer knows. Ours had 8,192 entries.
- Byte-pair encoding: a way to build the list by merging the most common neighbor pairs.
- Bytes per token: how much text one token carries. Higher is cheaper.
- Weights: the numbers inside a model. A longer vocabulary adds more of them.
- Regular expression: a short pattern that matches text, used here to decide where pieces may split.
Try it
- Install our line counter and run
mokei --tokenson a folder of your own text. See the mokei project page for the install and the limits. The estimate is only as good as the text it was fitted on. - Look at the regex engine behind our tokenizers: mojo-uregex on GitHub. Its README shows a small tokenizer-style pattern you can run.
- A quick home test: paste the same paragraph in English and in another language into any token counter. Compare the two counts.
Read next
- The Tokenizer Bought Time, Not Quality, the full run with all seven checks.
- A Screenshot Cost 363 Tokens as Pixels and 27 as Text, the picture-versus-text test.

Comments
No comments yet.
Log in to comment.