Predict the approximate token count difference between 'Hello world' and its Arabic equivalent 'مرحبا بالعالم' in a GPT-4 tokenizer.
Using tiktoken with cl100k_base (GPT-4's tokenizer), compare the token count for: - English: 'Hello world' (2 words, 11 characters) - Arabic: 'مرحبا بالعالم' (same meaning: 'Hello world', 2 words, 13 Arabic characters) Arabic characters use 2 bytes each in UTF-8. The cl100k_base tokenizer was trained predominantly on English data. Predict the token count for each string and the approximate ratio.
English 'Hello world' is about 2 tokens; the Arabic equivalent is roughly 8-10, a 4-5x token tax driven by English-biased merge rules.
Imagine a vending machine stocked to dispense whole sandwiches for the most popular orders. Ask for a regular sandwich and one button gives you the whole thing. Order something the owner never expected and the machine has no sandwich button, so it hands you the ingredients one slice at a time, and you pay per slice. That is what happens here. The tokenizer learned shortcuts for common English, so 'Hello' pops out as one piece. Arabic was rarely stocked, so its words come out almost letter by letter, and you pay for every little piece. Same meaning, many more pieces, a much bigger bill.
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.
3 min: 2-byte UTF-8 Arabic + missing Arabic merges + fertility 4-5x + cost/context/rate-limit budgets + why tiktoken beats a quoted integer.
import tiktoken
enc = tiktoken.get_encoding("cl100k_base") # GPT-4's tokenizer
english = "Hello world"
arabic = "مرحبا بالعالم" # same meaning
en_toks = enc.encode(english)
ar_toks = enc.encode(arabic)
print(len(en_toks)) # ~2
print(len(ar_toks)) # ~8-10
print(len(ar_toks) / len(en_toks)) # ~4-5x token tax| Property | English 'Hello world' | Arabic 'مرحبا بالعالم' |
|---|---|---|
| UTF-8 bytes per character | 1 byte (ASCII) | 2 bytes |
| Learned merge coverage | Extensive (word-level) | Sparse (few pairs merge) |
| Approx tokens | ~2 | ~8-10 |
| Fertility (tokens/word) | ~1 | ~4-5 |
| Relative cost / context use | Baseline | 4-5x higher |
Real products, models, and research that use this idea.
- OpenAI bills GPT-5.5 calls per token via tiktoken, so an Arabic or Hindi chatbot pays several times more than an English one for equivalent messages.
- Cohere and other providers publish multilingual fertility studies showing 3-5x token inflation for Arabic, Hindi, and Thai under English-trained BPE vocabularies.
- Gemini 3.1 and Llama 4 expanded tokenizer vocabularies specifically to lower non-Latin fertility and narrow this cost gap for global deployments.
What an interviewer would ask next. Try answering before peeking at the approach.
QHow would you forecast monthly API cost for a product that is 70% Arabic and 30% English traffic?
QWould switching from cl100k_base to o200k_base actually reduce the Arabic tax, and by how much?
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.
Estimating Arabic tokens from character count and assuming roughly 1 token per word, the way English behaves, then under-budgeting cost by 4-5x.
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.