Foundations

Tokenization I: characters, words, and subwords

Tokenization decides the units a model can see; Qwen3.8-27B's published tokenizer maps 248,077 ids, while its embedding and output tensors reserve 248,320 rows.

Updated

01 · Concept

Concept

Take the word unbelievability and ask a designer’s question: how many units should the model spend on it? Three answers have all been tried in production, and their consequences are worth working out before any terminology arrives.

Spell it one character at a time and it costs fifteen units. The vocabulary needed is tiny, a few hundred entries covers most Latin-script text, and no word is ever unrepresentable. But every sentence now stretches across five or six times as many positions, and as track 4 will show, the work a transformer does grows with positions rather than with characters. You have made the model cheap to store and expensive to run.

Store it as one whole word and it costs one unit — provided somebody put it in the vocabulary. If they did not, the model receives an unknown symbol and the distinction between unbelievability and incomprehensibility is destroyed at the door. Names, inflections, domain jargon, typing errors, and words invented last Tuesday all land in the same hole. No finite word list closes over open-ended text, and enlarging it has its own price we will come to.

Split it as un, believ, abil, ity and it costs four units, with pieces that are reusable across thousands of other words. That is subword tokenization, and it is what essentially every modern model does, Qwen3.8-27B included. Frequent strings stay whole; rare ones are composed. The pieces are learned from a corpus by an algorithm, and lesson 1.3 traces one of those algorithms merge by merge.

Qwen’s variant goes one step further down. Its tokenizer applies NFC normalization and a ByteLevel pre-tokenizer before BPE. The byte-derived base can spell every UTF-8 byte produced by a valid Unicode string, so unfamiliar scripts and emoji need not collapse to an unknown token. This is not a fallback path—the published BPE configuration says byte_fallback: false and declares no unknown token—and it does not make the public text API accept arbitrary binary. Coverage of normalized Unicode text is broad; efficiency is not, because unusual strings may expand into long chains of byte-derived pieces.

Notice that none of these splits is a fact about language. Even word is ambiguous. Is don’t one word or two? Does the punctuation attach? Chinese does not put spaces between words at all. German cheerfully welds four concepts into one compound. A tokenizer must nevertheless return a deterministic answer for every valid Unicode string, including strings its designers never imagined, so the boundaries it draws are statistical rather than linguistic. A split may look absurd to a person and still be the right engineering choice.

Now the number in the configuration file, which is where this lesson earns its place. Qwen3.8-27B declares 248,320 vocabulary rows. The obvious wrong turn is to read that as the model knows 248,320 words, and the more sophisticated wrong turn — the one that catches people who already know better — is to read it as the tokenizer can emit 248,320 distinct tokens. Neither is guaranteed by that field. What vocab_size governs is a tensor shape: the number of rows in the embedding matrix, and the number of columns in the output projection that produces logits.

The tokenizer artifacts make the gap measurable. The BPE model contains 248,044 entries, and 33 added tokens occupy ids through 248,076, for 248,077 mapped ids in total. The model configuration sets vocab_size=248,320\text{vocab\_size}=248{,}320, so the embedding and output tensors reserve 243 additional rows. The shape is divisible by 512—248,320=512×485248{,}320 = 512 \times 485—which is convenient for sharding, but the published artifacts do not state why this exact size was chosen, what training signal the unmapped rows received, or how every server handles their logits. The pinned generation configuration declares no generic suppress_tokens list. Inspect the actual runtime before making a masking claim.

The vocabulary size is not free, and the cost is easy to underestimate. Every row is a vector of 5120 numbers, and in this model the input embedding and the output projection are separate matrices rather than a shared one, so each additional row costs storage twice over. Lesson 1.5 does the full accounting and the total is startling. The design tension is therefore genuine: more vocabulary entries mean shorter sequences and cheaper attention, but a larger table to store, load, and multiply against at every single decoding step. There is no universally correct answer, only a point on a curve chosen for a particular set of languages, hardware, and workloads.

Because the tokenizer is fixed when training begins, it is part of the model’s contract rather than a preprocessing convenience. The embedding matrix has one row per vocabulary entry, and those rows learned their values under one specific mapping from text to ids. Swap the tokenizer afterwards and every id points at a row that learned something else. This is why you cannot mix a model’s weights with another model’s tokenizer, however similar the two look.

When you inspect any tokenizer, four questions settle most of what matters. Can it represent the valid text your interface accepts? How many tensor rows does it have, and how many ids do its tokenizer artifacts map? How many tokens does typical text in your languages require? And are the languages and domains you care about fragmented fairly against the ones you do not? Those questions show why tokenization is not mere preprocessing. It fixes the alphabet available to the model and sets the price of every sequence that model will ever process.

02 · Analogy

Analogy

Suppose every sentence must be built from a box of refrigerator magnets. A box of single letters can spell anything, but a short note swallows the whole box. A box of complete words makes common notes fast and makes an unfamiliar surname impossible. A subword box is the working compromise: frequent whole words stay intact, and anything else is assembled from reusable pieces such as un, believ, and able. Qwen's box goes one level further down: at the bottom of it lie the 256 possible byte values, so nothing you can type is unspellable.

03 · Teach it back

Teach it back

Explain why modern models use subword tokens rather than characters or whole words, and say what the number 248,320 in Qwen3.8-27B's configuration actually counts.

Minimum: 80 characters and 15 words. Your writing stays only in this browser.

Waiting for your explanation.

Compare with a model answer

Character tokens keep the vocabulary tiny and can spell anything, but they stretch every sentence over many more positions, and cost grows with positions. Whole-word tokens make common prose short but need an unbounded vocabulary and fail on names, inflections, typos, and new coinages. Subword tokenization keeps frequent strings whole and composes rare ones from pieces. Qwen's ByteLevel pre-tokenizer provides a byte-derived base for valid Unicode text after NFC normalization; its BPE configuration explicitly sets byte fallback to false. The tokenizer model maps 248044 ids and 33 added tokens extend the highest mapped id to 248076, so 248077 ids are mapped. The configuration's 248320 counts tensor rows, leaving 243 rows with no tokenizer mapping in the published artifacts. Those artifacts do not document how those rows were trained or how every runtime treats their logits.

04 · Check your understanding

Check your understanding

01Qwen3.8-27B's configuration declares 248,320 vocabulary rows. What is the safest reading of that number?
Answer and explanation

It sizes the embedding and output matrices and may be padded above the count of tokens the tokenizer actually emits — The configuration governs tensor shapes. Padding to a convenient multiple is routine, so rows can exist that no token maps to; the tokenizer files are the authority on what text becomes.

02What problem does a fixed whole-word vocabulary handle badly?
Answer and explanation

Rare, misspelled, or newly coined words — Anything outside the fixed list needs an unknown symbol, which destroys exactly the distinction the model may need. Subword pieces compose it instead.

03Lesson 0.1 said one forward pass produces a score for every output row. What does enlarging the mapped vocabulary and its tensors therefore cost?
Answer and explanation

A larger output matrix and more scores to compute at every position, in exchange for shorter sequences — Vocabulary size trades against sequence length: bigger vocabulary means fewer positions but a wider embedding table, a wider output projection, and more logits per step.

Complete the teach-back and answer the quiz correctly to finish this lesson.

◎ · Evidence marker

Sources

  1. Rico Sennrich, Barry Haddow, and Alexandra Birch (2016). Neural Machine Translation of Rare Words with Subword Units.
  2. Taku Kudo and John Richardson (2018). SentencePiece: A simple and language independent subword tokenizer and detokenizer for Neural Text Processing.
  3. Qwen Team (2026). Qwen3.8-27B tokenizer.json (pinned revision).
  4. Qwen Team (2026). Qwen3.8-27B config.json (pinned revision).
  5. Qwen Team (2026). Qwen3.8-27B generation_config.json (pinned revision).
  6. Qwen Team (2026). Qwen3.8-27B Model Card.