Hypothetical scenario. Northwind has agreed to begin with supported answers from permitted policies. Dev prepares a model request containing instructions, an employee’s question and a policy excerpt. The request exceeds the selected endpoint’s allowance even though the uploaded document looked small to Maya.
Maya: “The document is short. What else did we send?”
Dev: “I checked its upload size, but the request also includes our instructions and conversation.”
Priya: “Count the final input with the tokenizer and framing that belong to this destination.”
An upload and a model request cross different boundaries. A byte count can describe the file without describing the model input. You will trace text into token IDs, compare BPE, WordPiece and SentencePiece, and reconcile the complete illustrative request budget before deciding what to remove.
Your outcome is to trace text into token IDs, explain the differences between BPE, WordPiece and SentencePiece, and calculate an illustrative request budget without confusing words, characters and tokens. This lesson requires only basic arithmetic. Use GenAI foundations if representing text as indexed symbols is unfamiliar.
Why did a short-looking request exceed the allowance?
A tokenizer converts text into units from a vocabulary and assigns their IDs. A unit can cover a word, part of a word, punctuation or another text fragment. A word count therefore cannot determine a token count. Even two tokenizers that display similar pieces may assign different IDs. The vocabulary and processing rules belong with the model, not with a generic estimate chosen by the application.
Northwind's upload service and model request serve different purposes. The upload boundary may be expressed in bytes. The model boundary is expressed in the tokens of the serialized input, with any required allowance for generated output. The lesson's calculations are explicitly invented examples; actual limits and serialization must be checked for the selected model and endpoint.
Trace the complete representation boundary
Keep three objects distinct: the text you intend to send, the tokenizer configuration that turns it into IDs, and the serialized request that includes role markers or other framing. Northwind can record the selected configuration and input count alongside a request without retaining sensitive document contents. A number without that identity is difficult to compare after a model change.
Version the tokenizer together with the request envelope
Hypothetical scenario. Two clients send identical visible text but use different tokenizer artifacts or chat templates. Their token identities and counts need not match. Store the tokenizer revision, normalization rules, special-token policy and message template with the serving configuration.
| Artifact | Concrete evidence | Decision boundary |
|---|---|---|
| Input text | original bytes plus normalization | Retain traceable source |
| Encoding | tokenizer revision, template, special tokens | Compatible with model |
| Budget | instructions, evidence, tools, output reserve | Admission owns total |
The budget applies to the complete serialized input, including instructions, retrieved passages and tool descriptions. A local estimate must use the same representation contract as the serving boundary; otherwise it is only an estimate. Choose a toy envelope with 40 instruction tokens, 120 evidence tokens and 30 reserved output tokens: 40 + 120 + 30 = 190 tokens. Adding an 11-token tool description raises the selected total to 201. Truncating arbitrary bytes to recover the budget can break Unicode, a schema or a policy qualification.
Watch BPE build a reusable piece
Hugging Face's BPE explanation describes learning merges of frequent adjacent symbols. Training establishes a vocabulary and merge ordering; encoding uses those learned rules. It does not retrain the vocabulary each time an employee submits a document.
For a toy derivation, choose a corpus containing “low” twice and “lower” once. Start with characters and preserve word boundaries for this example. The two copies of “low” each contain the pairs l–o and o–w. “Lower” contributes l–o, o–w, w–e and e–r once each. The weighted counts are therefore 3, 3, 1 and 1. These are counts in our chosen corpus, not observations about English.
The two leading pairs tie. Declare a tie-break choosing l–o. After that merge, the corpus is “lo w” twice and “lo w e r” once. The pair lo–w now occurs three times. Merge it next: “low” becomes one unit and “lower” becomes “low e r.” Across all three occurrences, the original character-unit count was 3 + 3 + 5 = 11. After both merges it is 1 + 1 + 3 = 5, a reduction of 11 − 5 = 6 units.
This is a simplified character-based training example without end markers, normalization or byte fallback. It demonstrates reuse, not a prediction that a real tokenizer will reduce Northwind's input by this amount. The complete merge rules determine how an unseen string is encoded. The same visible string must be tested with the actual selected tokenizer before its count is used for admission.
WordPiece makes a different segmentation decision
Hugging Face's WordPiece lesson distinguishes its vocabulary construction and encoding from BPE. In the illustrated WordPiece procedure, encoding searches for the longest available piece at the current position, then continues through the word. Continuation pieces are commonly displayed with a prefix such as “##”; that marker is vocabulary notation, not evidence that the user typed hash characters.
Assume a toy vocabulary contains “play,” “##ing” and “##er,” but not the complete word “playing.” Under the declared longest-match rule, “playing” becomes “play” plus “##ing.” This example supplies the vocabulary; it does not infer a production vocabulary from the spelling. If a word cannot be fully segmented, the implementation's unknown-token behavior matters. Do not assume every tokenizer guarantees a useful decomposition for every script.
The architectural consequence is modest but important: knowing that two models both use subwords does not make their token IDs interchangeable. Preserve the matching tokenizer assets when moving a model or evaluating an alternative. Compare task results and actual request counts instead of treating the algorithm's name as a quality ranking.
SentencePiece is not simply a third merge rule
Kudo and Richardson's SentencePiece paper describes training subword models directly from raw sentences rather than requiring a prior word split. SentencePiece supports approaches including BPE and Unigram. Comparing “BPE versus WordPiece versus SentencePiece” therefore mixes an algorithm distinction with a text-processing system distinction.
This matters for languages and text where spaces are not dependable word boundaries. SentencePiece can represent whitespace explicitly as part of its processing. Inspect the selected model's actual normalization, whitespace handling and vocabulary instead of assuming that one visible space always corresponds to a separate token. With a Unigram model, segmentation is selected using learned piece probabilities; it is not the same repeated-merge procedure traced above. The Unigram lesson provides that separate mechanism.
Reconcile Northwind's request budget
Hypothetical scenario, continued. For an exercise only, choose a total request-and-output allowance of 120 units. Suppose the selected tokenizer reports 18 input tokens for instructions, 12 for the question, 60 for evidence and 10 for serialization overhead. Assume those four categories do not overlap. Total input is 18 + 12 + 60 + 10 = 100 tokens. Reserving 16 output tokens gives 100 + 16 = 116, leaving 120 − 116 = 4.
Now replace the evidence with text counted at 68 tokens. The new input is 18 + 12 + 68 + 10 = 108. With the same output allowance, the total is 108 + 16 = 124, exceeding the exercise limit by 124 − 120 = 4. Removing four characters is not a justified fix: the relationship between removed text and encoded tokens depends on segmentation.
Actual endpoints may express input, output and context constraints differently. The purpose of this small ledger is to expose assumptions. Count the final representation with the matching tokenizer, apply the endpoint's documented accounting, and test the boundary. Northwind must also decide which evidence can be removed without losing the support needed for an answer. Passing admission does not establish evidence quality.
Where a seemingly correct integration fails
Hypothetical failure scenario. A gateway estimates tokens using configuration A, then routes the request to model B with a different vocabulary or framing. Its arithmetic is internally correct but describes a different input representation. Diagnose this by comparing model identity, tokenizer assets and serialized counts before increasing the limit. This is a constructed failure, not a reported production incident.
In the wild, Sennrich, Haddow and Birch's subword-unit research addresses representing rare words in neural machine translation. It provides a concrete motivation for composing words from smaller units. It does not establish that one tokenizer is best for every language, domain or application.
Use token-level accounting when admitting model requests and comparing representation costs. Do not use token count as a measure of truth, reasoning quality or retrieval relevance. Likewise, fewer pieces can reduce an input's length without making its answer better. When evaluating a different model, keep text, tokenizer identity, framing and acceptance criteria visible as separate variables.
Test the input text boundary
The model release changes its template but keeps the same public model name. Can old cached token counts be reused?
Reveal the design reasoning
Only after establishing representation equivalence. Version the cache identity and compare complete encoded requests. Recompute admission where equivalence is absent; a stable marketing name is insufficient.
Decision: Pin representation artifacts and budget the whole envelope before generation.
Check the representation before changing the limit
The toy corpus has two copies of “low” and one of “lower.” Why is the first l–o count three rather than two?
Explain the weighted count
Both occurrences of “low” contribute one, and “lower” contributes one. The count is 2 + 1 = 3. Distinct word spellings are not the same as occurrence counts; ignoring frequency changes the learned merge choice.
The revised budget totals 124 against a limit of 120. A teammate proposes deleting four characters. Is that sufficient?
Use the unit the limit counts
It is not established. The excess is four tokens under the declared accounting. Character deletion can change segmentation in several ways. Re-encode the complete revised request and preserve enough output allowance and supporting evidence.
A model uses SentencePiece with BPE. Must it be classified as either SentencePiece or BPE, but not both?
Separate system from algorithm
No. SentencePiece can supply text processing and model tooling while BPE is the subword algorithm. Record both the system configuration and the algorithm instead of forcing them into mutually exclusive labels.
Go deeper into text representation
- Speech and Language Processing, Chapter 2: Words and Tokens — Daniel Jurafsky and James H. Martin; book chapter. Explains text units and tokenization beyond an English word-count intuition.
- Speech and Language Processing, Chapter 3: N-gram Language Models — Daniel Jurafsky and James H. Martin; book chapter. Connects a chosen text unit to the next prediction problem; it is background, not a description of modern transformer architecture.
- Let's build the GPT Tokenizer — Andrej Karpathy; video. Walks through tokenizer construction and its practical edge cases; implementation details are optional supporting study.
- Transformers, the tech behind LLMs — Grant Sanderson, 3Blue1Brown; video with text adaptation. Places token units in the larger representation-to-prediction picture.
- SentencePiece: A simple and language independent subword tokenizer and detokenizer for Neural Text Processing — Taku Kudo and John Richardson; paper. Explains why training from raw sentences is a separate design choice.
Record the boundary you will preserve
Decision: count the complete request with the tokenizer and framing matched to its destination.
Reason: word counts and unrelated vocabularies do not establish the model's actual input length.
Reconsider when: the destination, tokenizer assets, serialization or endpoint limits change.
Northwind now has a boundary for counting what it sends, not a rule for choosing useful evidence. Page 03 asks why two policy passages can share vocabulary or a high similarity score while answering different questions.