---
title: Explain how a subword tokeniser such as byte-level BPE is trained and applied, then tell me how the choice of tokeniser…
url: https://gurkanozkan.ai/learn/questions/applied-llm-fnd-01/
markdown: https://gurkanozkan.ai/learn/questions/applied-llm-fnd-01.md
kind: question
role: Applied LLM
stage: Technical
difficulty: Easy
json: https://gurkanozkan.ai/api/learn/questions/applied-llm-fnd-01.json
robots: noindex
---

# Explain how a subword tokeniser such as byte-level BPE is trained and applied, then tell me how the choice of tokeniser shows up in cost, latency and quality for a product that serves Welsh, Turkish and English users, source code and numbers.

Applied LLM · Technical · Easy

## Answer

*Model answer, written in a candidate's voice*

### In short

- Byte-level BPE: start from 256 byte tokens, repeatedly merge the most frequent adjacent pair until target vocab size; encoding replays merges in learned rank order; byte base means any input is encodable, no OOV.
- Contrast: WordPiece chooses merges by a likelihood score rather than raw frequency; unigram LM starts large and prunes by likelihood; SentencePiece is a library (BPE or unigram) that treats whitespace as a symbol.
- Production: tokens-per-word (fertility) differs by language, so Welsh/Turkish text and code can cost more tokens, hit context limits sooner and add latency; English common words are usually cheaper.
- Code and numbers: indentation, punctuation and digit splitting change formatting and arithmetic reliability; measure with the exact serving tokeniser, not a proxy.
- Trade-off: larger vocab shortens sequences but grows embeddings/softmax and creates rare under-trained tokens; train/serve tokeniser or chat-template mismatch silently breaks behaviour.

### In full

Byte-level BPE starts from the 256 byte values, counts adjacent pairs in a training corpus, merges the most frequent pair, and repeats until it reaches the target vocabulary size; encoding then applies the learned merges in their learned order, and because the base vocabulary is bytes, any byte sequence can be represented, so there are no true out-of-vocabulary failures. WordPiece is similar in spirit but chooses merges by a likelihood/score criterion rather than raw frequency, while the unigram LM method starts with a large candidate vocabulary and prunes it using language-model likelihood; it is usually trained with the SentencePiece library, which also implements BPE and treats whitespace as an explicit symbol (▁). For a product serving Welsh, Turkish and English, the same text can have very different fertility: common English words are usually compact, while Welsh digraphs/diacritics and Turkish agglutinative words and special letters are more likely to be split, so those users can pay more tokens, reach context limits sooner and see higher latency even at the same nominal model size. Source code adds another effect: indentation, punctuation and digit sequences are tokenised differently from prose, which can hurt arithmetic, formatting and exact-match behaviour, so I would count tokens with the target model's own tokeniser and check the chat template rather than assuming a generic tokeniser is equivalent. The vocabulary-size trade-off is that a larger vocabulary shortens sequences but increases embedding and output-softmax cost and can leave rare tokens under-trained, while a smaller vocabulary is cheaper per token but longer and more fragmented; the practical rule is to measure fertility, context headroom and latency per language and per content type, and to keep training and serving tokenisers and templates identical.

*Corrected by an independent AI reviewer.*

## What a strong answer covers

- Training: start from bytes/characters, repeatedly merge the most frequent adjacent pair until the target vocabulary size; encoding replays merges in learned order; byte-level base vocabulary means no out-of-vocabulary failures
- Contrasts with WordPiece (likelihood-driven merges) and the unigram LM (starts from a large vocabulary and prunes it); knows SentencePiece is a library that implements both BPE and unigram LM on raw text, treating whitespace as a symbol
- Production effects: tokens-per-word ("fertility") varies by language, so some users pay more, hit context limits sooner and see higher latency; code whitespace and digit splitting affect arithmetic and formatting
- Vocabulary-size trade-off: shorter sequences vs. larger embedding/softmax matrices and rare, under-trained tokens
- Practice: always count with the target model's own tokeniser; train/serve tokeniser or chat-template mismatch silently breaks behaviour

## Common mistakes

- Assuming one token ≈ one word in every language
- estimating cost or context limits with a different model's tokeniser

## Topic guides

- [LLM cost and unit economics](https://gurkanozkan.ai/learn/topics/cost.md)
- [Transformers, attention and scaling](https://gurkanozkan.ai/learn/topics/transformers.md)
---

*Study material compiled with AI: drafted by a local model (Inkling 2 Mini) from public sources, then checked against those sources by independent AI reviewers (Claude) in November 2026. Not reviewed line by line by a person.*
