AI for Indian languagesMiddleLesson 2356 min read

Tokens, scripts and the cost of Indic text

Tokenizers trained mostly on English often split Indian-language text into more pieces. That means higher cost and less room in the context window. Measure it yourself.

Lesson in motion

In 60 seconds

Tokens, scripts and the cost of Indic text

Tokenizers trained mostly on English often split Indian-language text into more pieces. That means higher cost and less room in the context window. Measure it yourself.

1/5
In simple words
Imagine a taxi that charges by the number of boxes you carry, not by weight. If your luggage is packed in big boxes, you pay little. If the same luggage is packed in many small boxes, you pay more. A tokenizer packs text into boxes called tokens, and for many Indian languages it uses more, smaller boxes.
In Step 1 · The tokenizer you saw that a model does not read letters or words. It reads tokens: pieces of text from a fixed vocabulary. Most tokenizers learn their vocabulary from their training text. If that text is mostly English, common English words become single tokens, while words in other scripts are split into many small pieces.

Three ways to count the same sentence

UnitWhat it countsWhy it matters
Characters (code points)Unicode code points, the numbers the computer stores for each letter or signA visible letter in an Indic script is often more than one code point
UTF-8 bytesThe bytes used to store or send the textBasic Latin letters take 1 byte. Letters in scripts such as Devanagari, Bengali, Tamil or Telugu take 3 bytes each. Arabic-script letters, used for Urdu, take 2.
TokensThe pieces the model reads, which depend on the tokenizerYou pay per token, and the context window is measured in tokens

See it in Python

This demo uses only the standard library. It prints the numbers, so you do not have to trust anyone's claim. Run it and look at the output.
Characters and UTF-8 bytes, English and Hindipython
import unicodedata

samples = {
    "English": "Where is the railway station?",
    "Hindi": "रेलवे स्टेशन कहाँ है?",
}

for name, text in samples.items():
    chars = len(text)                      # Unicode code points
    utf8 = len(text.encode("utf-8"))       # bytes on disk / on the wire
    print(f"{name:8} chars={chars:3}  utf8_bytes={utf8:3}  bytes_per_char={utf8 / chars:.2f}")

# Look inside one Hindi syllable: one visible unit can be several code points
for ch in "स्टे":
    print(f"U+{ord(ch):04X}  {len(ch.encode('utf-8'))} bytes  {unicodedata.name(ch)}")
You will see that the Hindi sentence uses more bytes than the English one, although it has fewer characters. The last part shows that the syllable "स्टे" is four code points: a consonant, a virama (the sign that joins consonants), another consonant, and a vowel sign.
Note
Many modern tokenizers work on UTF-8 bytes. If a piece of Indic text is rare in the tokenizer's training data, it can fall back to small byte-level pieces. That is one reason why Indic text often turns into more tokens. The exact numbers depend on the tokenizer, so always measure with the one you will use.

Why more tokens hurts

  • Higher cost. Hosted models usually charge per token. More tokens for the same meaning means a bigger bill for users of that language.
  • Less context. The context window is counted in tokens. If a document needs more tokens, less of it fits, so the model "remembers" less.
  • Slower answers. Models produce output one token at a time, so more output tokens take longer.
  • Worse learning. When words are cut into meaningless pieces, the model may learn their meaning less well.
Watch out
This is a fairness issue, not only a technical one. If an app costs more, or answers less well, for people who use Indian languages, then those users get a worse deal for the same need. Measure it and design for it.

What builders can do

  1. 1

    Measure first

    Count tokens for real user text in each language with your actual tokenizer.
  2. 2

    Compare models

    Tokenizers differ. Some newer ones are trained with more multilingual data. Test several.
  3. 3

    Budget per language

    Set token limits and prices with the real token counts, not English ones.
  4. 4

    Trim the prompt

    Keep long fixed instructions short. Some teams write system instructions in English and ask for answers in the user's language; test whether that keeps quality.
  5. 5

    Consider Indic-trained models

    Models and tokenizers trained with more Indian-language data may be more efficient. Check their licences and quality.
Guessing
  • "A token is about four characters" for every language
  • Setting the same length limit for all languages
  • Testing costs only with English text
Measuring
  • Counting tokens with the real tokenizer on real text
  • Setting limits based on each language's token counts
  • Tracking cost per language in your dashboard
Try this. Add one more sentence to the demo, in another language you know, with the same meaning. Before you run it, guess the byte count. Then run it and check.

Watch and read more

Lab

A small table of characters, bytes and tokens for the same sentence in at least three languages.

~30 min

The problem

Run the starter code. Then:

  1. Add at least two more sentences with the same meaning in languages you know or can check with a speaker. Type them yourself or ask a friend who speaks the language.
  2. If you can install it, pip install tiktoken to see token counts from one public tokenizer. If not, the code still shows characters and bytes.
  3. Make a table: language, characters, bytes, tokens, and tokens compared with English.
  4. Write two sentences on what this would mean for a chatbot's cost and context in each language.

Do not state results you did not measure. If you only measured bytes, say so.

Starter codepython
# Same meaning, different languages. Replace or add your own lines.
sentences = {
    "English": "Please send the bill on WhatsApp.",
    "Hindi": "कृपया बिल व्हाट्सऐप पर भेजिए।",
    # "Tamil": "...",   # add a language you know, typed by you
}

try:
    import tiktoken                         # optional: pip install tiktoken
    enc = tiktoken.get_encoding("cl100k_base")
except ImportError:
    enc = None

base = None
for name, text in sentences.items():
    chars = len(text)
    utf8 = len(text.encode("utf-8"))
    tokens = len(enc.encode(text)) if enc else None
    if base is None and tokens:
        base = tokens
    ratio = f"  x{tokens / base:.1f} vs first line" if tokens and base else ""
    print(f"{name:8} chars={chars:3} bytes={utf8:3} tokens={tokens}{ratio}")
Open Google Colab ↗This code needs your own setup (a model, a GPU or extra packages). Run it in Google Colab: File → Upload notebook.

You are done when

Hard questions

Try to answer before you reveal. If you can answer these, you understood the lesson.

Q1Two tokenizers give very different counts for your Kannada text. Which should you trust?Reveal

Both are correct for their own model. Token counts belong to a tokenizer, not to a language. What matters is the tokenizer of the model you will actually use. If you are choosing a model, compare cost and quality together: a model with fewer tokens but worse answers is not a win.

Q2Could you fix the cost gap by transliterating Indic text into Roman letters before sending it?Reveal

It may reduce tokens with some tokenizers, but it is risky. Transliteration has no single standard, it can lose meaning and sounds, the model may understand it less well, and the user usually wants the answer in their own script. Test quality carefully before doing this, and never do it silently to text the user will see.

Please sign in to continue.

Questions people ask

Is UTF-8 unfair to Indian scripts?

UTF-8 is a storage format. It uses more bytes for letters outside the basic Latin range, and that is a fixed design choice that works for every language. The bigger issue is the tokenizer: what it learned to treat as common pieces decides how many tokens a sentence becomes.

Why is a "character" count confusing for Indic text?

Python's len() counts Unicode code points. A letter you see on screen, like a consonant with a vowel sign, can be two or more code points. What a reader thinks of as one letter is called a grapheme cluster. The third-party regex package can count those with \X.

Can I count tokens without paying?

Yes, usually. Many open tokenizers can be run locally, for example through Hugging Face libraries, and some providers publish their tokenizers or offer a free token-counting tool. Check the current docs for the model you use.

Should I write prompts in English to save tokens?

Sometimes it helps, but test it. The instructions may be cheaper in English, but the answer should still be in the user's language and natural. Always check quality in the target language, not only cost.

Lesson test

5 questions. Get 3 right (60%) to pass and complete this lesson.

Sign in to take the test and save your progress