C.W.K.
Stream
Lesson 02 of 12 · published

Character vs Word vs Subword: Three Strategies, One Winner

~16 min · bpe, subword, vocabulary

Level 0Token
0 XP0/94 lessons0/10 achievements
0/120 XP to next level120 XP to go0% complete

There are three fundamental ways to split text. Each has been tried at scale, and the winner is decisive.

Character-level

One token per character (or per UTF-8 byte). Tiny vocabulary (~256 for bytes), no out-of-vocabulary problem ever, but sequences become very long. The word "tokenization" becomes 12 tokens. Your context window evaporates and your model has to learn from scratch that 't', 'h', 'e' tend to mean "the." Used by ByT5 and a few research models, but rarely in production.

Word-level

One token per whitespace-separated word. Sequences are short, but vocabulary explodes — English alone has 100K+ inflected forms, and you must invent an [UNK] token for everything you didn't see during training. Misspellings, named entities, and code identifiers all collapse to [UNK]. Used pre-2018; effectively dead now.

Subword

One token per sub-word fragment, with common words kept whole and rare words split. Vocabulary stays bounded (30K-200K), sequences stay short, and there is never an OOV — anything can be encoded as a sequence of fragments. Every modern LLM uses subword tokenization; the only debates are which algorithm (BPE, WordPiece, Unigram, BBPE) and how big the vocabulary should be.

StrategyVocabSeq lengthOOV?Use today
Character / byte~256Very longNeverNiche (ByT5, Charformer)
Word100K+ShortYesEffectively retired
Subword30K-200KModerateNeverAll modern LLMs

Code

Same string, three tokenizations·python
text = "transformer-based tokenization"

# 1. Character-level (UTF-8 bytes)
chars = list(text.encode('utf-8'))
print(len(chars))   # ~30 tokens

# 2. Word-level (whitespace + punctuation)
import re
words = re.findall(r"\w+|\S", text)
print(words)        # ['transformer', '-', 'based', 'tokenization']

# 3. Subword (BPE via tiktoken)
import tiktoken
enc = tiktoken.encoding_for_model("gpt-4")
print(enc.encode(text))  # ~5-7 tokens; common subwords kept whole

External links

Exercise

Take a 200-word English paragraph and a 200-word Korean paragraph. Tokenize each with (1) UTF-8 bytes, (2) whitespace word-split, (3) GPT-4's tiktoken cl100k_base, (4) Llama 3 tokenizer. Compare token counts in a table. What's the ratio of the worst case to the best case for each language?

Progress

Progress is local-only — sign in to sync across devices.
Spotted a bug or have feedback on this page?Report an Issue

Comments 0

🔔 Reply notifications (sign in)
Sign inPlease sign in to comment.

No comments yet — be the first.