EasyDeepLearn

How does Byte-Pair Encoding (BPE) tokenization work?

medium

Answer

  • Start with a vocabulary of individual bytes/chars.
  • Repeatedly find the most frequent adjacent pair in the corpus and merge it into a new token, until the desired vocab size (e.g., 32k, 100k, 200k).
  • At inference, apply the same merge rules greedily.
  • Byte-level BPE (GPT-2+, Llama, Mistral) starts from raw bytes → handles any Unicode without OOV.
  • Common vocab sizes: 32k (Llama-2), 100k (GPT-4), 200k+ (Gemini).
  • Larger vocab = fewer tokens per text = more efficient long-context inference.
Check yourself — multiple choice
  • Tokenize by fixed-length substrings
  • Greedily merge the most frequent byte pairs until reaching target vocab size; byte-level handles any Unicode
  • BPE requires word-level split first
  • BPE has fixed 512 vocab

BPE: iteratively merge frequent byte pairs; byte-level BPE avoids OOV entirely.

#tokenization#fundamentals

Practise LLMs & GenAI

214 interview questions in this topic.

Related questions