Predict how many tokens the rainbow flag emoji 🏳️🌈 uses in a byte level BPE tokenizer with no emoji in training data.
A byte level BPE tokenizer (like GPT-2's) has never seen any emoji during training, so no emoji merge rules were learned. The rainbow flag emoji 🏳️🌈 is a ZWJ sequence: it encodes as the UTF-8 bytes for 🏳 (white flag, 4 bytes) + ️ (variation selector, 3 bytes) + ZWJ U+200D (3 bytes) + 🌈 (rainbow, 4 bytes) = approximately 14 bytes total. Predict how many tokens this emoji produces.
With no learned merges, byte-level BPE falls back to one token per byte, so the ~14-byte rainbow flag ZWJ sequence becomes roughly 14 tokens.
Imagine a typist who knows shortcut keys for common words. Type 'hello' and one key produces the whole word. But hand them a strange symbol they have never practiced, and they have no shortcut, so they spell it out one keystroke at a time. The rainbow flag emoji is that strange symbol. To the computer it is really four little pictures glued together with an invisible 'joiner', and all of it adds up to about 14 tiny byte-pieces. With no learned shortcut, the tokenizer types each byte-piece on its own, so one emoji costs about 14 keystrokes, while the word 'hello' costs barely one or two.
Detailed answer & concept explanation~6 min readEverything 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. 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.
2 min: no merges -> 1 token/byte + 4-codepoint ZWJ sequence + non-BMP 3-4 byte widths + ~14 byte total + glyph size unrelated to cost.
emoji = "🏳️🌈" # rainbow flag, a ZWJ sequence
# Inspect the Unicode structure: 4 codepoints joined by ZWJ.
print([hex(ord(c)) for c in emoji])
# ['0x1f3f3', '0xfe0f', '0x200d', '0x1f308']
# flag VS-16 ZWJ rainbow
print(len(emoji.encode("utf-8"))) # ~14 bytes
# With no learned merges, a byte-level BPE tokenizer
# emits ~1 token per byte -> ~14 tokens.Real products, models, and research that use this idea.
- Chat products on GPT-5.5 see emoji-dense messages inflate token counts, since each unseen ZWJ emoji can cost a dozen tokens of input.
- tiktoken and HuggingFace tokenizers both expose byte fallback, so any emoji always encodes but rare ones expand to many byte tokens.
- o200k_base added merges for common emoji, so a plain 🌈 may be 1-2 tokens while an exotic ZWJ flag still falls back to bytes.
What an interviewer would ask next. Try answering before peeking at the approach.
QWhy does a plain 🌈 sometimes cost fewer tokens than the rainbow flag 🏳️🌈 in a modern tokenizer?
QHow would emoji-heavy chat input change your prompt-truncation strategy?
Don't say thisRed flags and common mistakes that signal junior thinking. Click to expand.
Red flags and common mistakes that signal junior thinking. Click to expand.
Counting the emoji as 1 token because it looks like one glyph, when it is a 4-codepoint ZWJ sequence of ~14 UTF-8 bytes with no merges to compress it.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.
Same topic, related formats. Practice these next.