C.W.K.
Stream
Lesson 01 of 05 · published

Token은 단어가 아니야 — BPE 60초 정리

~22 min · tokenization, bpe, measurement

Level 0Window Watcher
0 XP0/50 lessons0/13 achievements
0/100 XP to next level100 XP to go0% complete

모형은 조각으로 읽는다

Token은 단어, 단어 일부, 구두점, 공백, Unicode 조각 중 뭐든 될 수 있어. tokenizer는 인간 직관이 아니라 학습 데이터 빈도 기준으로 최적화돼. 영어 prose, code, JSON, 한글, URL, stack trace가 token을 다르게 — 가끔은 한 자릿수 차이로 — 쓰는 이유야.

BPE 60초 정리

대부분 modern LLM은 byte-pair encoding(BPE) variant 써. 레시피: 1) 256개 single-byte로 vocab 시작. 2) 학습 corpus에서 가장 자주 인접한 pair 찾음. 3) 그 pair를 하나로 merge해 vocab에 추가. 4) target vocab 크기(보통 50K-200K)까지 반복. 결과: 자주 나오는 영어 phrase는 single token, 희귀한 용어/non-Latin script는 fragment.

눈대중 그만

budget이 중요할 땐 provider tokenizer 써. 한 paragraph는 추정 OK. 200K-token working session은 추정 NOT OK — 30% 빗나가다가 청구서나 truncation으로 깨달아.

Token cost는 empirical이야. 작업 크기가 의미 있으면 세고, 측정이 확인하기 전엔 추정은 추정일 뿐이라고 다뤄.

Code

tiktoken으로 측정 (OpenAI/GPT 계열)·python
from tiktoken import encoding_for_model

enc = encoding_for_model("gpt-5")
text = open("lesson.md", "r", encoding="utf-8").read()
print(f"{len(enc.encode(text))} tokens")
Anthropic count_tokens·python
from anthropic import Anthropic
client = Anthropic()

count = client.messages.count_tokens(
    model="claude-sonnet-4-7",
    messages=[{"role": "user", "content": open("lesson.md").read()}],
)
print(count.input_tokens)
빠른 감 체크 비율·text
English prose:                ~4 chars / token
English code:                 ~3 chars / token
JSON / structured text:       ~3.5 chars / token
Korean / Japanese / Chinese:  ~1-1.5 chars / token  (영어 비용 2-3배)
Emoji / unusual Unicode:      ~0.25-0.5 chars / token

External links

Exercise

비슷한 visible length의 영어 paragraph 1, 한국어 paragraph 1, code snippet 1 골라. tiktoken/count_tokens로 token 세. 어느 게 놀랐는지 설명해.
Hint
visible length는 거짓말해. token당 semantic payload가 진짜 metric이야.

Progress

Progress is local-only — sign in to sync across devices.
이 페이지에서 버그를 발견하셨거나 피드백이 있으세요?문제 신고

댓글 0

🔔 답글 알림 (로그인 필요)
로그인댓글을 남기려면 로그인해 주세요.

아직 댓글이 없어요. 첫 댓글을 남겨보세요.