Which tokenizer can learn merges that span whitespace boundaries by design?
Same topic, related formats. Practice these next.
Same topic, related formats. Practice these next.
SentencePiece, because it runs on raw text and treats whitespace as an ordinary character (▁), so merges are free to cross word boundaries.
Imagine writing a sentence on a long strip of paper with no gaps marked as special. Most tokenizers first snip the strip at every space, so they can only join letters that sit inside one word. SentencePiece skips the snipping. It treats a space as just another mark on the paper, so it can join letters and even whole words across what used to be a gap. That freedom is exactly what you need for languages like Japanese or Chinese, which do not put spaces between words at all.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
3 min: standard BPE pre-splits on whitespace + that wall blocks cross-word merges + SentencePiece skips the pre-split + encodes space as ▁ + merges cross former boundaries + suits space-free scripts + tiktoken and byte-level BPE keep the wall.
import sentencepiece as spm
sp = spm.SentencePieceProcessor(model_file="spm.model")
# Spaces become the meta-symbol U+2581 (shown as the lower one-eighth block).
print(sp.encode("New York", out_type=str))
# e.g. ['\u2581New', '\u2581York'] -> a frequent phrase could merge to ['\u2581New\u2581York']
# No whitespace? No problem: the raw stream is tokenized directly.
print(sp.encode("\u6771\u4eac\u90fd", out_type=str)) # Tokyo (no spaces between chars)Real products, models, and research that use this idea.
What an interviewer would ask next. Try answering before peeking at the approach.
Red flags and common mistakes that signal junior thinking. Click to expand.
Thinking byte-level BPE allows cross-word merges because bytes ignore whitespace; its regex pre-tokenizer still cuts at spaces and blocks them.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.