LLMS & TRANSFORMERS · INTERVIEW QUESTION
Explain the tokenization strategies used in LLMs: BPE, WordPiece, and SentencePiece.
🔴 advanced · Pre-training & Fine-tuning
Hint: Think about handling out-of-vocabulary words and subword granularity.
Answer
BPE (Byte Pair Encoding): starts with characters, iteratively merges the most frequent pair. Used by GPT models. Handles OOV words by decomposing into subwords. WordPiece: similar to BPE but merges pairs that maximize likelihood of the training data. Used by BERT. SentencePiece: language-agnostic, operates on raw text (no pre-tokenization), supports both BPE and unigram models. Used by T5, LLaMA.
Key considerations: vocabulary size (32k-100k typical), byte-level BPE handles any UTF-8 text, tokenization efficiency varies by language (English ~1.3 tokens/word, Chinese ~2-3). Tiktoken (OpenAI) is an efficient BPE implementation. Poor tokenization of numbers and code remains a challenge.
Related questions
- Explain the difference between LoRA, full fine-tuning, and prompt tuning. When would you use each?
- How do you evaluate LLMs? What benchmarks and metrics matter?
- What is the difference between encoder-only, decoder-only, and encoder-decoder transformers?
- What is the scaling laws relationship between model size, data, and compute?
- Explain the self-attention mechanism in detail. What are Q, K, V and why do we use scaled dot-product attention?