You can define tokenization in an interview and still get stuck when asked why a model miscounts letters in an ordinary word. To practice that jump from definition to explanation, grab the free Top 30 AI Engineer Interview Questions PDF (13 pages, each with what the interviewer tests and the follow-up to expect) and enter $0.
What the interviewer is checking
The interviewer wants to hear what the model receives and what that representation means for your application. A tokenizer converts text into a sequence of integer IDs. Each ID identifies an entry in the tokenizer's vocabulary. A token can represent a whole word, part of a word, punctuation, whitespace, or even part of a character's byte encoding.
Subword tokenizers let common patterns fit into a compact sequence while keeping smaller pieces available for unfamiliar text. Two common approaches build those pieces differently.
- Byte pair encoding, or BPE, starts with small units and learns merges from pairs that occur frequently in the training text. At encoding time, it applies the learned merge rules.
- A unigram tokenizer starts with many candidate pieces and prunes them during training. At encoding time, it can score possible splits and select the most likely one under its learned piece probabilities.
A strong answer
Tokenization is how we turn text into the sequence of IDs a language model processes. The vocabulary usually has pieces of different sizes, so a familiar word can fit into one token and an unfamiliar one can take several. BPE learns which neighboring pieces to merge. A unigram tokenizer learns probabilities for candidate pieces and uses them to choose a split.
That matters for tasks where the unit I care about differs from the model's unit. If I ask for the number of letter r's in strawberry, the model may have to reason about letters inside a token. Long numbers can be split into digit groups that don't line up with the columns needed for arithmetic. Even a leading space can change the token sequence because some vocabulary entries include a space.
It also matters when I ship an application. More input tokens consume more of the context window and can increase prompt processing time. More generated tokens usually mean a longer wait. If the service bills by tokens, the counts affect the bill too. I'd measure with the target model's tokenizer, and I'd use deterministic code whenever the task needs an exact letter count or arithmetic result.
Follow-ups to expect
- How would you count tokens before sending a request? Use the target model's tokenizer or its token counting endpoint when available. Count the complete input, including system instructions, chat history, retrieved text, and tool definitions. If you count locally, account for message formatting and special tokens as far as the provider documents them. Reserve room for the expected output within the context limit, then compare your estimate with the usage reported by the API.
- Why does the same text cost different amounts on different models? There are two variables. Different vocabularies and encoding rules can produce different token counts. Models can also charge different rates per token, with separate rates for input and output. Compare both the count and the applicable price before making a cost estimate.
- Why might a non-English prompt use more tokens? If a tokenizer's training data favored English, its vocabulary may cover common English words and fragments with larger pieces. Text in a less represented language or script can break into smaller pieces, sometimes down to bytes. The difference depends on the language, the text, and the tokenizer. Measure equivalent requests in the languages your application serves.
The weak answer
Saying that tokenization splits text into words leaves you unable to explain why adding a space can change the count or why two models disagree on the same request. Bringing up a fixed characters-per-token ratio has the same problem. Such a ratio can give you a rough estimate for similar text, but it can miss the budget on code, numbers, or multilingual input.
A drill
- Inspect the token boundaries for
strawberryandstrawberrywith a tokenizer you use. Count the r's separately, then explain why counting tokens cannot give you that answer. - Type a 20-digit number without separators, then the same number with commas, and inspect both. Compare the token boundaries with the place values you'd use for addition.
- Count equivalent requests in two languages on two models. Then give the strong answer aloud in 60 to 90 seconds and name one engineering decision those counts would change.
Keep practicing
For more practice connecting interview concepts to system design decisions, see The 0 to 1 AI Engineer Interview Playbook (twenty chapters on RAG, agents, evals, fine-tuning and LLM system design), 30 percent off with code BF30 through Mon Nov 30.
Valenx Press. Practice material, no company affiliation, no interview promise.
Top comments (0)