How does tokenizer fertility bias affect cost and context window budget for non-English API users?
Same topic, related formats. Practice these next.
Same topic, related formats. Practice these next.
A startup is building a customer service chatbot for Arabic-speaking users using the GPT-4 API. Their English-language prototypes averaged 800 tokens per conversation. Explain why their Arabic conversations will cost significantly more, quantify the expected token ratio, and describe how they should adjust their cost and rate-limit planning.
Arabic fragments into 3-5x more tokens than English under cl100k_base, so cost, context window, and rate limits all degrade by the same multiplier.
Imagine you bought movers who charge by the box. English furniture comes pre-packed into a few big crates, so two rooms fit in two crates. Arabic furniture arrives unpacked, piece by piece, so the same two rooms need ten small boxes. The movers charge per box, the truck fills up faster, and you can carry fewer rooms per trip. The tokenizer is the mover, and tokens are the boxes. English packs into few tokens; Arabic spreads into many. Same conversation, but you pay more, you fit less history in one trip, and you hit the truck's limit sooner. The fix is to count the boxes on a real Arabic shipment before you book the move.
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: English-biased merges + Arabic fertility 3-5x + three token budgets (cost, context, rate limit) + measure with tiktoken on real data.
import tiktoken
enc = tiktoken.get_encoding("cl100k_base")
# Sample real conversations instead of guessing the multiplier.
en_convos = load_sample("english", n=100)
ar_convos = load_sample("arabic", n=100)
def avg_tokens(convos):
return sum(len(enc.encode(c)) for c in convos) / len(convos)
en_avg = avg_tokens(en_convos) # ~800
ar_avg = avg_tokens(ar_convos) # ~2400-4000
fertility = ar_avg / en_avg # measured multiplier for forecasting
print(en_avg, ar_avg, fertility)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.
Extrapolating the Arabic budget straight from the 800-token English prototype, then discovering cost, context, and rate limits are all 3-5x worse in production.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.