OSS4AI AI Stack · Season1 · #7
by Yujian Tang

A tokenizer vocabulary can contain common words and smaller fragments. Open full-size image
A phrasebook rather than an alphabet
Language models operate on numbers. A tokenizer converts text into a sequence of token IDs, and the model then maps those IDs into vectors it can process. A token can be a whole word, part of a word, punctuation, or a space joined to another piece of text.
Think of the vocabulary as a phrasebook. Frequent pieces get convenient entries. Less common strings are assembled from smaller pieces. This is why counting words is not the same as counting tokens, and why two models can consume different numbers of tokens for the same sentence.
The tokenizer is part of the model's input contract. A text string by itself does not specify the exact sequence the model sees.
How frequent pieces become tokens
Byte-pair encoding, or BPE, builds a vocabulary by repeatedly merging common neighboring units. In a byte-level implementation, the process begins from bytes. Other descriptions of subword BPE begin from characters, so do not assume every tokenizer starts with the same alphabet.
During vocabulary construction, frequent adjacent pairs are merged into new units. Repeating that process creates entries for common fragments. At use time, the trained tokenizer applies its rules to new text; it does not rebuild the vocabulary for every request.
Sennrich, Haddow and Birch's paper is a foundational reference for subword BPE in neural machine translation. The tiktoken implementation is a concrete example for inspecting GPT-family tokenization.

A byte-level BPE implementation repeatedly merges frequent neighboring units. Open full-size image
Token pieces are not individual letters
Consider "How many r's are in strawberry?" as an illustrative question, not a tokenizer measurement. A tokenizer might represent a word as one unit or as several subword pieces. A leading space can also change which vocabulary entries match. Inspect the selected encoding to determine the actual pieces and their IDs.
Those possibilities do not prove that a model cannot count letters. They show that the ordinary input representation does not necessarily expose one token per letter. Character-level tasks require care because the model may need to reason about a token's internal spelling rather than count visible character units.
Language and whitespace affect the count
For an illustrative comparison, try encoding 我喜欢开源 AI and 你好,世界 with two explicitly selected encodings. Record their counts and decoded pieces rather than assuming that familiar words define token boundaries. This is a proposed exercise, not a reported tokenization result.
Tokenization differences are a warning against using an English rule of thumb for every language. It is also a warning against assuming a newer or different tokenizer preserves old counts. Whitespace, capitalization, punctuation and the exact encoding can change the result.
For English, roughly four characters or three-quarters of a word per token is a useful estimate. It is not a guaranteed conversion. Use an estimate for rough planning, then use the actual tokenizer for a concrete input.
Count the request you will really send
For an application, count more than the user's latest sentence. Instructions, retrieved passages, conversation history and tool descriptions can all contribute to the input. Leave space for generated output when the model's context limit accounts for it.
A practical exercise is to encode several realistic requests, decode the individual token pieces, and compare the counts. Include the language and document formats your application will use. Try a short sentence, a code sample and a long document excerpt rather than testing only ordinary English prose.
If you change the model, revisit the estimate. A count from one encoding is not automatically the billing or context count for another API; provider-specific request framing can also matter.
What tokenization does not explain
Tokenization explains the conversion from text to discrete IDs. It does not establish what those IDs mean, how the model learned, or whether the resulting answer is accurate. Embeddings supply learned numerical representations, and later layers process them in context.
Knowing the tokenizer helps you diagnose surprising splits, plan context usage and build better test cases. It is one component of the system, not a complete explanation for every language-model error.
