How does a model read Korean and English, and why can their costs differ? — Tokenization

Cover for the series exploring AI after ChatGPT

We can ask ChatGPT a question in Korean or paste an English document into the same window. The characters look quite different to us. How does the model read them? If two sentences mean the same thing, does it process roughly the same amount?

For a service calling an AI model, this can affect cost. Input is typically billed in tokens rather than characters. Could translating a Korean request into English make it cheaper? I compared two sentences to find out.

A sentence is split before it reaches the model

A tokenizer splits text into small pieces and converts each piece into its corresponding number. Each piece is a token. Both Korean and English reach the model as sequences of these numbers.

The pieces have different sizes. Characters that frequently occur together can form one token, while a single word can span several. Spaces and punctuation affect the split too. Counting words or characters by eye won’t give an exact token count, and different tokenizers can produce different results. tiktoken documentation

Here are the two sentences I used.

오늘 날씨가 좋아서 산책하고 싶어.

The weather is nice today, so I want to go for a walk.

I used the o200k_base tokenizer in js-tiktoken 1.0.21. I excluded quotation marks and kept the periods. Below, vertical bars mark token boundaries and ␣ represents a space in the original.

LanguageToken piecesCount
Korean오늘|␣날|씨|가|␣좋아|서|␣산|책|하고|␣싶|어|.12
EnglishThe|␣weather|␣is|␣nice|␣today|,|␣so|␣I|␣want|␣to|␣go|␣for|␣a|␣walk|.15

The two Korean characters in 오늘 formed one token, while 산책 split into two. In English, spaces were attached to words, and the comma and period each used a token. These are details a word count would miss.

The English sentence used more tokens

In this comparison Korean used 12 tokens and English used 15. At the same input price per token, the English version would cost more. Equivalent meaning didn’t produce an equal token count.

That doesn’t establish that Korean requests are always cheaper. This result covers two particular sentences with one tokenizer. A longer request or a different model calls for another measurement.

To try it yourself, choose a setting that uses o200k_base in the tokenizer tool and paste each sentence separately. Then substitute a request you actually use. Check that both versions include the same information. Dropping examples or conditions during translation changes the task as well as its length.

What should we shorten to reduce cost?

Seeing the counts might make us want to shorten every request. But suppose we’re asking for a customer notice and remove “Show prices inclusive of tax.” The input gets shorter, but we may need a second request to fix the prices. If one task takes two calls, the tokens saved in the first request don’t tell us the total cost.

Korean and English both become token IDs, but expressing the same meaning can take different numbers of tokens. Translating into English won’t necessarily save money.

To reduce the cost of a real request, measure its length with the tokenizer for the model you plan to use. Then check that it still includes the conditions needed to finish the task. The sentence length we shorten is only one part of what we pay for. The bill includes the input and output used to reach the result we wanted. We need both to judge whether translating or shortening the request actually made it cheaper.