Same topic, related formats. Practice these next.
Same topic, related formats. Practice these next.
Pre-tokenization splits raw text into coarse chunks first, and those chunk edges become hard walls that BPE merges can never cross.
Imagine cutting a long ribbon into shorter pieces before you start gluing beads onto each piece. Once the ribbon is cut, you can only glue beads that sit on the same piece, never across a cut. Pre-tokenization is that cutting step: a pattern slices the text at spaces, punctuation, and digit-letter changes. Then the merging step that glues frequent neighbours together only works inside each slice. So a token like a word can form, but a token that spans 'word + space + next word' cannot, because the cut sits between them.
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: regex splits raw text + chunk edges are hard walls + BPE merges only inside a chunk + no cross-word tokens + leading-space rule + cl100k vs o200k regex differences + pin encoding per model.
import regex as re
# A simplified cl100k_base-style pre-tokenization pattern.
# The real pattern also handles contractions, leading spaces, digits.
pat = re.compile(r"""'s|'t|'re|'ve|'m|'ll|'d| ?\p{L}+| ?\p{N}+| ?[^\s\p{L}\p{N}]+|\s+""")
text = "Hello world 42!"
chunks = pat.findall(text)
print(chunks) # ['Hello', ' world', ' 42', '!']
# BPE merges run INSIDE each chunk only.
# It can build a token for ' world', but never for 'Hello world'
# because the two sit in different chunks.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 pre-tokenization cleans or normalizes the text by stripping punctuation or lowercasing, when its real job is to draw merge boundaries BPE cannot cross.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.