Tokenizer Fertility Across Languages

easy
Unit 9 · KV Cache0/3 to milestone

The same sentence can cost 2–3× more tokens in Hindi or Thai than in English, which means higher API bills and less effective context. Measure it.

tokenize is any function from a string to a list of tokens. Implement:

  • fertility(texts, tokenize): total tokens divided by total whitespace-separated words
  • chars_per_token(texts, tokenize): total characters divided by total tokens
  • language_report(corpus, tokenize, baseline="en"): corpus maps language codes to lists of parallel texts. Return {lang: {"fertility": ..., "cost_vs_baseline": ...}}, where the cost ratio is that language's total tokens divided by the baseline's.
#tokenizers#multilingual#cost2 visible + 1 hidden tests
solution.py · Python 3.13
Loading editor…
Run your code to see results. ⌘↵ to run · ⌘⇧↵ to submit
Tokenizer Fertility Across Languages · TechGradify