Understanding Tokens: The Basic Unit of LLM Measurement
This article explains what tokens are and why they are the fundamental unit for measuring large language model usage. It covers how tokenizers split English text, Chinese characters, code, and structured data into tokens; why input and output length, context limits, cost, and rate limits are all counted in tokens; and practical strategies for reducing token consumption, along with common misconceptions to avoid.
1. What a Token Actually Is
A token is the smallest discrete unit a large language model uses to process text. It is neither a character nor exactly a word, but a semantic fragment produced by a tokenizer according to a specific algorithm. The model never “reads” the raw string; it receives a sequence of integer IDs, each mapping to one token in the vocabulary. Understanding tokens is therefore a prerequisite for understanding model inputs and outputs, context length, and billing logic.
One common misconception is worth clearing up: a token is not a word as humans see it. The same word can be split into completely different token sequences depending on context, language, capitalization, and surrounding whitespace.
2. How an English Sentence Is Split into Tokens
Take the sentence Tokenization is the process of converting text into tokens. A typical tokenization result is:
["Token", "ization", " is", " the", " process", " of", " converting", " text", " into", " tokens", "."]
This example reveals several key patterns:
- High-frequency words stay intact: common words such as
the,is, andofeach become a single token, and the leading space is usually merged into the token (for example," is"). - Low-frequency long words are broken down:
Tokenizationis split intoToken+ization, whileconvertingbecomes a subword unit of its own kind. Roots and common suffixes are reused. - Punctuation stands alone: the period occupies its own token.
- Tokens usually outnumber words: 14 words map to 11 tokens, showing that the splitting granularity is driven by word-frequency statistics rather than grammatical boundaries.
The underlying idea comes from subword tokenization: by measuring co-occurrence frequency across a corpus, high-frequency fragments are fixed in the vocabulary while low-frequency words are left to smaller, composable units. This balances vocabulary size against the ability to cover out-of-vocabulary words.
3. Token Differences Across English, Chinese, and Code
- English: dominated by subwords, where one token often corresponds to about 0.75 English words. As a rough estimate, 1,000 tokens is about 750 English words.
- Chinese: a common Chinese character is often one token, while some rare characters or combinations are split into multiple tokens. Character count and token count are therefore close but not equal.
- Code and symbols: indentation, brackets, operators, and variable naming style all significantly affect token counts. Long names, deep indentation, and heavy comments drive consumption up.
- Structured data: key names and delimiters in JSON, logs, and tables also count as tokens, so redundant fields directly amplify cost.
4. Why Usage Must Be Measured in Tokens
- Model input is a sequence of IDs: attention computation operates on the token sequence, and its length determines compute and memory overhead.
- The context window is limited: input tokens plus output tokens cannot exceed the model’s context limit; exceeding it requires truncation or chunking.
- Cost and rate limits are token-based: call charges and rate limits are generally tied to token throughput rather than the number of requests.
- Quality is sensitive to tokenization: splitting affects semantic completeness, which in turn affects inference quality and output stability.
5. Optimization Strategies in Engineering Practice
- Trim prompts: remove repeated instructions and redundant examples, and replace long natural language with structured templates.
- Control retrieved chunks: in retrieval-augmented scenarios, limit the number of retrieved items and the length of each chunk so irrelevant content does not crowd out the context.
- Compress conversation history: summarize multi-turn conversations or apply a sliding window to prevent linear token growth.
- Standardize data formats: unify field naming and remove meaningless whitespace and duplicate keys to reduce structured-input overhead.
- Estimate before launch: use a tokenizer to profile the token distribution of typical inputs offline, then plan capacity and budget.
- Monitor and alert: track token usage trends continuously with monitoring, alerting, and logging services to catch abnormal growth early.
6. Common Misconceptions
- Misconception 1: A token equals a word. In reality it is determined by statistical tokenization, with clear differences across languages.
- Misconception 2: Chinese characters are always cheaper. Rare characters and mixed-language text can actually increase token counts.
- Misconception 3: Longer output is better. Output tokens count toward cost and latency too, so aim for information density.
- Misconception 4: Tokenization is identical across models. Vocabularies differ, so the same text yields different token counts; re-evaluate when migrating.
7. Conclusion
Tokens are the bridge between human language and model computation. Mastering their splitting rules, measurement basis, and optimization methods is what lets you balance context management, cost control, and quality tuning. In large model application practice at Baidu AI Cloud, the recommendation is to build a token profile from real business samples and establish a closed loop of “estimate, load test, observe, iterate,” making the token budget a predictable and governable engineering metric.
