Token LabSearch

← All tutorials
DEVELOPER GUIDE / 02

Why languages, emoji, and JSON change token counts

Compare encodings with multilingual text and learn why characters, bytes, and tokens are different measurements.

Measure three different things

Unicode code points describe text, UTF-8 bytes describe its storage, and tokens describe how a particular vocabulary represents it. One visible emoji can contain several code points; a single code point can require several bytes or tokens.

An English rule of thumb such as four characters per token is not a multilingual budgeting rule. Count the actual prompt in the encoding you will use.

Study guide & lesson outlineLEARNING CONTRACT

Understand → implement → investigate

Goal: explain the mechanism in this lesson, reproduce one example and test a failure case. Reading alone does not mark mastery.

  • Understand: state assumptions, shapes/units and a counterexample.
  • Implement: reproduce a numerical example and inspect boundaries.
  • Investigate: compare one alternative under a matched budget.

Compare without changing the input

Load Languages & emoji and use Compare encodings. Both counts come from exactly the same text. Then try your real Spanish, Japanese, Korean, or Chinese prompt; do not assume the relationship stays constant across samples.

JSON adds keys, punctuation, quoting, and whitespace. Compare a formatted object with a compact version. Removing whitespace can reduce bytes, but the token change depends on the encoding and surrounding text; always measure.

import { encode } from 'gpt-tokenizer/encoding/cl100k_base';
// npm install gpt-tokenizer@4.1.0
const samples = [
  'Hello, world!', '你好,世界!',
  '¡Hola, mundo!', 'こんにちは、世界!',
  '안녕하세요, 세계!', '👨‍👩‍👧‍👦'
];
for (const text of samples) {
  const ids = encode(text);
  console.log(text, ids.length);
}
Try it in the tool →

Optimize meaning, not appearance

First remove unnecessary fields, repeated documents, and irrelevant history. Preserve task constraints and evidence. A shorter-looking prompt is not necessarily fewer tokens, and fewer tokens do not guarantee an equally good answer.

Keep a small multilingual regression set. After a prompt change, compare token counts and task correctness together. Do not use these two encodings as exact counters for unrelated model tokenizers.

References & implementation

MATHEMATICAL REVIEW · 2026-10-26

Assumptions, implementation & acceptance

Hold encoding and text fixed. Record UTF-8 bytes, code points and tokens separately; the English 4-characters-per-token rule is not a multilingual formula.

Shared code, English mathematical explanation and key multilingual numeric passages reviewed. This is not a full translation proofread.

Equivalent texts in several languages → Hold tokenizer encoding fixed → Count bytes, code points and tokens → Compare measurements, not heuristics
Mechanism map: follow the transformations from top to bottom.

Before running: predict a boundary case

Hold encoding and text fixed. Record UTF-8 bytes, code points and tokens separately; the English 4-characters-per-token rule is not a multilingual formula.

Hint: isolate the assumption

Keep the baseline input fixed, change one parameter or boundary, and compare both the numerical result and the claimed units. A passing example verifies this fixture only.

Minimal executable example

Save the example and linked modules in one folder. Use Node.js 22 or newer, then run node multilingual-tokenization.mjs. npm install gpt-tokenizer@4.1.0

import { encode } from 'gpt-tokenizer/encoding/cl100k_base';
// npm install gpt-tokenizer@4.1.0
const samples = [
  'Hello, world!', '你好,世界!',
  '¡Hola, mundo!', 'こんにちは、世界!',
  '안녕하세요, 세계!', '👨‍👩‍👧‍👦'
];
for (const text of samples) {
  const ids = encode(text);
  console.log(text, ids.length);
}

Test and transfer

Hold encoding and text fixed. Record UTF-8 bytes, code points and tokens separately; the English 4-characters-per-token rule is not a multilingual formula.

Record input, code version, expected result and observed result in the notebook below. Then construct a counterexample that violates the assumption above and explain why the original conclusion no longer follows.

Download complete kit (.tar.gz) · Complete reference kit and regression checks

Predict, test and keep evidence

Before revealing an answer, predict one result. After the exercise, record the discrepancy and a transfer test. Saved locally across language editions.

Open notebook / export / clear →

The mathematical review scope is recorded per lesson. It does not establish empirical paper reproduction; report suspected errors in your notes. Review scope