DEEP DIVE · TOKENIZER

How AI Reads Text

Before a model can reason about a dispute note or a fee schedule, it chops the text into tokens — the units it actually reads and generates. Tokens drive cost and context limits, so it pays to see them.

✂️ Tokens🧪 Interactive playground💰 Cost & context

✂️ Text Becomes Tokens

A model doesn't see letters or words — it sees tokens: common chunks of text, often word-pieces. "Representment" might be one token; a rare code like "DSP-4821" splits into several. Everything the model reads and writes is counted in tokens.

🔢Why a business audience should care: you pay per token, in and out — and the model can only hold so many tokens at once (the context window). Tokens are the meter and the memory limit.
🧩

Tokens ≈ word-pieces

Common words are one token; rare words, IDs, and numbers split into several. Roughly 4 characters ≈ 1 token in English.

💰

Tokens = cost

Pricing is per million tokens, both input and output. A long policy pasted into every prompt gets expensive fast.

📏

Tokens = context limit

The context window is measured in tokens. Big documents can overflow it — a key reason to use RAG and send only relevant chunks.

Payments angle: masked data and codes tokenise differently from plain words — ••••4921 and ACP-DIS-014 use more tokens than they look. The playground on the next tab lets you feel this with real payments text.

🧪 BPE Playground

Watch a sub-word tokenizer actually build itself. Byte-Pair Encoding starts from single characters and repeatedly merges the most frequent adjacent pair into a new token — press ▶ Play, or step through, to see common payments sub-words emerge.

This is an illustrative BPE run on the text you give it — it shows the real algorithm on a tiny corpus. Production tokenizers train on billions of words, but the mechanic is exactly this.

✂️ BPE builds a vocabulary

Step 0 / 0
🎓
Press ▶ Play to watch BPE build a vocabulary step by step, or use the arrow buttons to step through manually.
initial split
Tokens0 tokens
📊 Pair frequencies (top 12)
📚 Vocabulary (0)
🔀 Merge history

No merges yet — press ▶ to start

📖 How BPE works

Split text into characters, with marking word ends

Count every adjacent token pair

Merge the most frequent pair into one new token

Repeat — common sub-words emerge as single tokens

Watch for: shared roots like dispute / chargeback / representment collapse into single tokens after a few merges — which is why familiar payments words are cheap in tokens, while a rare code like DSP-4821 stays fragmented.

🧠 How Sub-word Tokenization Works

Modern tokenizers use Byte-Pair Encoding (BPE) or similar. The idea: start from characters and repeatedly merge the most frequent pairs into bigger pieces, until you have a vocabulary of common sub-words. Frequent words become single tokens; rare ones stay in pieces.

🔤

Start with characters

Every word begins as individual characters the tokenizer already knows.

🔗

Merge frequent pairs

Pairs that appear often ("in", "ing", "ment") get merged into single tokens over training.

📚

Build a vocabulary

The result is a fixed vocabulary of common sub-words — enough to represent any text, common or rare.

🧩

Encode new text

New text is greedily matched to the longest known pieces. "representment" → "represent" + "ment"; "DSP" stays split.

Why sub-words, not whole words?

ApproachProblem it hasWhy BPE wins
Whole wordsVocabulary explodes; can't handle new words, codes, or typosBPE composes any word from known pieces
Single charactersSequences get very long and slowBPE keeps common words compact (one token)
Sub-words (BPE)Balance: compact for common text, flexible for rare
Payments takeaway: your internal codes (DSP-4821, ACP-DIS-014), masked values, and abbreviations aren't in the model's common vocabulary, so they fragment into more tokens — and can be easier to mis-read. Spell things out where clarity matters.

💰 Tokens, Cost & Context

Because everything is counted in tokens, they shape the two numbers that matter most in production: what a request costs, and how much the model can consider at once.

What tokens drive

Rough rules of thumb

RuleDetail
~4 characters ≈ 1 tokenFor typical English; codes, numbers, and masked values run higher
~0.75 words ≈ 1 tokenSo ~100 words ≈ ~130 tokens
Input + output both countA long grounded answer costs tokens too — constrain the format
Whole doc vs RAGA full policy can be thousands of tokens per call; a few retrieved chunks are a fraction of that
Bottom line: tokens are the unit of cost, speed, and memory. Grounding with RAG and constraining output aren't just quality moves — they're the main levers on your bill and your latency.

🔬 Algorithm Comparison

There are four levels at which text can be split, and a few competing sub-word algorithms. Understanding the trade-offs explains why modern models all landed on sub-word tokenization.

Token granularity — how big should each piece be?

LevelHow it splitsExample: "representment"Trade-off
WordEach word = 1 tokenrepresentmentSimple, but a huge vocabulary and can't handle unseen words, codes, or typos
Sub-wordMeaningful piecesrepresent + mentBest balance — what Nova, Claude, Llama all use
CharacterEach character = 1 tokenr·e·p·r·e·s·…Tiny vocabulary, but very long sequences (slow, costly)
ByteRaw byte encoding114·101·112·…Handles any language/symbol, but extremely long
The sweet spot is sub-word tokenization — it captures shared roots ("dispute", "disputed", "disputes" share a stem) while keeping the vocabulary manageable. Common payments words become single tokens; rare codes like DSP-4821 stay in pieces.

The main sub-word algorithms

AlgorithmHow it decides mergesUsed by (examples)
BPE (Byte-Pair Encoding)Repeatedly merge the most frequent adjacent pair (what the playground shows)GPT family, many open models
WordPieceMerge the pair that most improves the model's likelihood, not just raw frequencyBERT family
SentencePiece / UnigramLanguage-agnostic; starts from a large vocabulary and prunes to the most useful piecesLlama, T5, multilingual models
Why it matters for you: the exact algorithm changes token counts a little, but the principle is identical everywhere — common text is cheap, rare/technical text (internal codes, masked values, non-English) costs more tokens. Design prompts and estimate cost with that in mind.

🔗 Where Tokenization Fits

Tokenization is step one of every LLM pipeline — everything downstream depends on how text was split. Here's the whole path, from your text to a generated answer.

📝Your text ✂️Tokenizer (BPE) 🔢Embeddings 🧠Transformer Answer

Tokenization is step 1 — the tokenizer turns your text into tokens, embeddings give those tokens meaning, the transformer weaves them into context, and the model generates an answer token by token.

The rest of the pipeline — deep dives

Connection: the playground showed how BPE builds the vocabulary; the Embeddings deep dive shows what happens to those tokens next, and the RAG deep dive shows how the whole pipeline answers from your payments documents.