What Are Tokens in Large Language Models? A Complete Guide to Tokenization Principles
This article explains what a token actually is in large language models and why it is not just a billing unit. It covers how tokenization happens before modeling, why tokens do not map one-to-one to words, how frequency-driven splitting affects sequence length, and how Chinese text is typically tokenized. It also outlines why the token layer exists and gives practical engineering guidance on length pre-checks, shared input-output budgets, history control, template trimming, usage monitoring, and asynchronous processing, plus a summary of common misconceptions.
1. Start With an Error: A Token Is Not an Arcade Coin
When many people first hear the word “token,” they picture the plastic discs you insert into arcade machines to start them. That analogy captures only half of the idea, the billing-unit half, and misses the role tokens play inside the model. What usually forces a closer look is a failed production call: the request returns exceeded maximum token limit, meaning the input plus the output exceeded what the model can process in a single call. If you treat that only as “the quota ran out,” you will keep hitting problems in length estimation, truncation strategy, and cost control.
The precise definition is that a token is the smallest unit of text a large language model splits input into. The model does not read character by character. It first splits a string into a sequence of discrete units, maps each unit to an integer ID, and feeds that sequence into the network. The natural language you see is, to the model, a sequence of IDs.
2. A Quick Experiment: The Model Does Not Read Letter by Letter
Read this sentence silently: “The weather is nice today.” You do not identify each character stroke by stroke; you understand the sentence as a few meaningful chunks. A large language model works similarly, only with finer chunks: it splits first, then processes those units.
Here is a schematic view of the process (pseudocode that conveys the concept only and does not represent any specific implementation):
text = "I love machine learning"tokens = tokenize(text) # split the text into unitsids = [vocab[t] for t in tokens] # map each unit to an integer IDlogits = model(ids) # the model computes over the ID sequence
The key point is that splitting happens before modeling. The splitting scheme directly determines sequence length and how semantically complete each unit is, and it also determines how much content fits in the same context window.
3. A Token Is Not a Word, and That Is the Most Common Misconception
Beginners usually assume one word equals one token. In practice it is far less tidy. In English, common short words are often a single unit; inflected or longer words get split into a root plus suffixes; technical terms, misspellings, and rare words may be broken into very small pieces, degrading to individual characters in extreme cases.
The logic behind this is not dictionary lookup but frequency statistics: letter combinations that appear extremely often in the training corpus get merged into a single unit, such as common verb-ing and noun-forming suffixes, common prefixes, and negation prefixes. Two stable patterns follow:
- High-frequency combinations tend to merge into complete units, producing shorter sequences.
- Rare words, newly coined words, and meaningless strings get split more finely, producing longer sequences.
This also explains an engineering phenomenon: two texts with the same character count can differ severalfold in token count. Text containing many proper nouns, code identifiers, or random strings consumes noticeably more tokens.
4. How Chinese Text Is Split
Chinese is generally closer to one unit per character, so a sentence of a dozen characters maps to roughly a dozen tokens, which makes estimation more intuitive than in English. However, some tokenization schemes merge high-frequency two-character words and function-word combinations into a single unit, so the actual count is slightly lower than the character count. Note that different models use different tokenization schemes, so the token count for the same text varies reasonably across models, and you cannot carry over old estimation coefficients when migrating between models.
5. Why Introduce the Token Layer at All
Handling raw characters seems simpler, but it immediately runs into two hard constraints.
The first is sequence length. For a common short English sentence, counting characters gives roughly twenty-odd, while counting tokens usually gives only four or five. The context window is a finite resource: the coarser the splitting, the more useful information fits in the same window, which improves long-document understanding and the ability to retain multi-turn conversation history.
The second is semantic granularity. A single letter carries no usable meaning, so the model would need to stack a great many layers to reconstruct words and concepts from letter combinations, which is inefficient. Using high-frequency combinations as units is like handing the model a set of prefabricated semantic blocks: the same compute learns more stable language patterns and more easily covers inflections and spelling variants.
6. Engineering Practice: Build Token Estimation Into the Design
Once you understand the principles, what matters more is turning them into executable engineering constraints.
- Input and output share one budget. The context window usually covers the prompt, conversation history, retrieved material, and the model output together, so reserve room for the output instead of giving the entire allowance to the input.
- Check length before the call. After assembling the prompt template and injecting retrieved fragments, measure the length once before sending the request, and truncate or compress according to a policy when it exceeds the limit, so production does not fail outright.
- Control history growth. Multi-turn sessions should cap the number of retained turns or apply summarization, otherwise history consumes the budget linearly.
- Trim templates and redundant examples. Few-shot examples and repeated system instructions are often invisible token heavyweights and can be rewritten more compactly.
- Establish usage observability. Log input length, output length, latency, and failure reasons for every call, feed them into logging and alerting, and aggregate by business dimension so you can locate the source of abnormal growth.
- Add elasticity and asynchrony. For long-text batch scenarios, a message queue can smooth peaks and handle retries, while object storage can hold large source text so only the necessary fragments go to the model, balancing cost and stability.
In related practice at Baidu AI Cloud, this kind of length pre-check, usage observability, and asynchronous processing is typically combined: alerting surfaces abnormal consumption, the log service traces the specific request, and a container platform runs batch jobs, turning the token from “a concept remembered only when an error occurs” into a routine, measurable, and governable metric.
7. Common Misconceptions at a Glance
- Misconception 1: a token equals a word. In reality the granularity is decided by frequency statistics and is not fixed.
- Misconception 2: the same character count means the same consumption. Proper nouns and code raise consumption significantly.
- Misconception 3: all models split text the same way. Migrating across models requires recalibrating estimation coefficients.
- Misconception 4: only the input occupies the window. The output consumes budget too, so it must be reserved for.
With these points in hand, you can anticipate length risk during architecture design, give a credible range in cost estimates, and, when an error occurs, quickly tell whether the input is too long, the output reserve is insufficient, or history has accumulated out of control. That is the most practical payoff of understanding tokens.
