Family 셋, 일은 하나
토크나이저는 텍스트를 모델이 embed 할 정수 id 로 split. 현재 사용되는 family 셋:
- Byte-Pair Encoding (BPE) — 빈번한 byte/char pair 를 merge. GPT-2, GPT-3, GPT-4, Llama, Qwen, Mistral, 모던 LLM 대부분이 씀. byte 위에서 동작 (UNK 없음), 모든 Unicode 처리.
- WordPiece — greedy longest-match. BERT, DistilBERT 가 씀.
##로 subword 마킹. - SentencePiece (Unigram or BPE) — 입력을 whitespace 포함 raw byte stream 으로 다룸 (
▁가 word boundary 마킹). T5, mBART, ALBERT, XLM-R 가 씀.
진짜 알아야 할 것
모든 토크나이저가 fast Rust 백업 버전 (디폴트) 을 가져. 모델이 slow Python 만 ship 하지 않는 한 fast variant 써. 성능 차이 종종 10x.
99% 케이스에서 만지는 메서드 네 개:
tokenizer(text)—{input_ids, attention_mask}돌려줌.tokenizer.encode(text)/.decode(ids)— round-trip.tokenizer.apply_chat_template(messages)— 모델의 chat template 따라 chat history 렌더 (토크나이저 config 의 Jinja).tokenizer.batch_encode_plus(...)/tokenizer(...)에 리스트 넘기기 — batch.