Glossary

What is Tokenization in LLMs?

Understanding how language models break down text into processable units

· 5 min read

Tokenization is the foundational process that allows large language models to understand and generate text. Before an LLM can process your prompt, it must first convert the text into numerical representations called tokens.

How Tokenization Works

Modern LLMs use subword tokenization algorithms like Byte Pair Encoding (BPE) or SentencePiece. These algorithms learn common patterns in text and create a vocabulary of tokens that balance efficiency with coverage.

What is a token?

A token is the smallest unit of text that an LLM processes. It can be a whole word ("hello"), a subword ("un" + "happy"), or even a single character. The tokenizer determines how text is split.

How many tokens is a word?

On average, one English word equals about 1.3 tokens. Common words like "the" or "and" are single tokens, while technical terms or rare words may be split into 2-4 tokens.

Why does tokenization matter for costs?

LLM APIs charge per token for both input and output. Understanding tokenization helps you estimate costs and optimize prompts. A 1,000-word document might be 1,300 tokens, directly affecting your bill.

Common Tokenization Algorithms

BPE (Byte Pair Encoding) - Used by GPT models. Iteratively merges the most frequent character pairs to build a vocabulary.

SentencePiece - Used by LLaMA and T5. Language-agnostic tokenization that works directly on raw text.

WordPiece - Used by BERT. Similar to BPE but uses likelihood instead of frequency for merging.

Tokenization and Context Windows

Every LLM has a maximum context window measured in tokens. GPT-4 supports up to 128K tokens, while Claude 3 handles 200K. Understanding tokenization helps you stay within these limits and avoid truncation.

Monitoring Token Usage

DriftRail tracks token usage across all your LLM interactions, helping you monitor costs and optimize prompts. Our observability platform logs both input and output tokens, giving you visibility into your AI spending.

Track Your Token Usage

Monitor LLM costs and optimize token efficiency with DriftRail.

Start Free