Token Lab검색

← 모든 튜토리얼
개발자 가이드 / 02

언어, 이모지, JSON에 따라 토큰 수가 달라지는 이유

다국어 입력을 비교하고 문자, 바이트, 토큰의 차이를 이해합니다.

세 가지 단위 구분

유니코드 코드 포인트는 텍스트를, UTF-8 바이트는 저장 형식을, 토큰은 특정 어휘의 표현 방식을 나타냅니다. 이모지 하나에 여러 코드 포인트가 포함될 수 있고 한 코드 포인트가 여러 바이트나 토큰이 될 수 있습니다.

영어에서 약 네 문자가 한 토큰이라는 경험칙은 다국어 예산에 맞지 않습니다. 실제 프롬프트와 인코딩으로 측정하세요.

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.

같은 입력으로 비교

다국어와 이모지 예제를 불러오고 인코딩 비교를 누르세요. 동일한 입력으로 두 결과를 계산합니다. 한국어, 일본어, 중국어, 스페인어의 실제 프롬프트에서도 반복해 보세요. 비율은 고정되지 않습니다.

JSON은 키, 따옴표, 구두점, 공백을 추가합니다. 정렬한 객체와 압축한 객체를 비교하세요. 공백 제거는 바이트를 줄이지만 토큰 변화는 인코딩과 주변 텍스트에 따라 달라집니다.

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);
}
도구에서 실행 →

겉모양보다 의미 최적화

불필요한 필드, 중복 문서, 무관한 기록을 먼저 제거하고 제약과 근거는 유지하세요. 짧아 보이는 입력이 반드시 토큰이 적은 것은 아니며, 토큰을 줄여도 답변 품질이 유지된다는 보장은 없습니다.

다국어 회귀 테스트를 만들고 변경 후 개수와 정답률을 함께 평가하세요. 이 두 인코딩을 다른 모델 토크나이저의 정확한 카운터로 사용하지 마세요.

참고 자료 및 구현

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