Tokenization

LLM foundationsModels and inferencePublished By Simon Budziak

Tokenization is the process that converts text, code, or other input into tokens a language model can process. A token may be a word, part of a word, punctuation, or another learned unit, so token counts rarely match character or word counts exactly.

The Hugging Face tokenizer documentation describes the main tokenization approaches used by transformer models.

How does tokenization work?

A tokenizer applies a fixed vocabulary and splitting algorithm to input, then maps each token to a numeric identifier. The model receives token identifiers, not raw words, and converts them into learned representations before processing them through its transformer architecture. Different model families can tokenize the same sentence differently.

Why do token counts matter?

Tokens consume the model’s context window and often determine API cost. Long prompts, code, tables, and multilingual text can use more tokens than a simple word count suggests. Measure with the tokenizer for the model you actually use, especially before setting retrieval chunk sizes or output limits. A token is therefore both a model input unit and a practical capacity constraint, while embeddings turn token sequences into useful numerical representations.

Frequently asked questions

Is one token the same as one word?

No. A familiar word may be one token, while an unusual word can be split into several tokens. Punctuation, spaces, code, and non-English text also affect the count.

Why does tokenization matter in production?

Token counts determine how much input fits in a context window and often drive model cost and latency. They also affect how text is split for retrieval and processing.

Summarize this page with

Train your team to build this