MLCrack

    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.