In a language model, tokenization is the step that turns raw text into the sequence of integer token IDs the model actually reads. A token is the smallest string unit the model sees. It can be a single character, a whole word or a subword chunk such as “play” or “##ing”. Many state-of-the-art models use subword tokenization, with byte-pair encoding (BPE) the most used scheme, because it shortens the input context and handles unknown words. BPE is also reversible and lossless, so the tokens decode back to the original text. Subword tokenizers break dates such as “20250312” into meaningless fragments, and in one study a single OCR misread turned one token into three.
What Tokenization Means in the Context of Language Models, for Extraction Work
A language model does not see text the way a person does. It sees a sequence of numbers, and BPE is one way of producing that sequence. Hugging Face Transformers supports three subword algorithms: BPE, Unigram and WordPiece. All three split text into units somewhere between words and characters, so common words stay whole and rare or unknown words break into pieces. They differ in how they segment text. BPE repeatedly merges the most frequent character pairs and is deterministic. Unigram picks the most likely segmentation from a large starting vocabulary. WordPiece works like BPE but uses a likelihood-based rule to choose merges. If you want the mechanics from the beginning, our walkthrough of how text becomes tokens for generative models starts there, and the piece on BERT tokenization and WordPiece subwords covers what WordPiece means for evaluations.
Two variants matter for documents. Byte-level BPE uses the 256 byte values as its base vocabulary, so every input can be tokenized without falling back to an “
Training a tokenizer is a compression problem: find the rules that express a dataset in the fewest tokens, because fewer tokens means more usable context without a bigger model. How well that works depends on the language. The “Tokenizer Tax” study measured ten foundation models on parallel text in 25 European languages. It found about 1.2 tokens per word for English and about 3.1 for Greek and Maltese. That ratio sets inference cost, which our note on average tokens per word and inference cost works through.
One property matters for everything below. Under BPE, merge rules are applied deterministically across the whole string. In one example of tokenization under Llama 2’s BPE rules, “hello” is a single token, but “hellow” becomes two tokens, “h” and “ellow”. So a one-character difference can change how the rest of a string is split into tokens.
Why Does Subword Tokenization Garble Dates, Part Numbers and Codes?
Subword vocabularies are optimised on their training data. The “Date Fragments” study shows what this does to dates. “20250312” became “202”, “503” and “12”, and “2025-03-14” became “20”, “25”, “-0”, “3”, “-1” and “4”. That split cuts across the year, month and day boundaries. Models also differ from each other. Llama 3 and the GPT family usually split date components into three-digit pieces, OLMo into two-digit pieces, Qwen and Gemma into single digits, and Phi into single digits after an initial token.
Fragmentation correlates with lower accuracy. In that study, heavier fragmentation went with accuracy drops of up to 10 points on uncommon dates, such as historical and future ones. The correlation between fragmentation and accuracy was -0.61 across time periods and -0.42 across date formats. The authors call this moderate: fragmentation is a consistent bottleneck, but not the only factor, and the authors attribute the rest to factors such as model architecture, scale and pretraining exposure. Larger models also rebuild the date in earlier layers than small ones do. One limit matters here: the benchmark uses clean, canonical date formats and does not cover noisy inputs such as OCR output.
Some models adopt number-specific tokenization schemes. The “Tokenization counts” study notes that LLaMA and PaLM split numbers into single digits, while GPT-3.5 and GPT-4 have separate tokens for 1-, 2- and 3-digit numbers. On GPT-3.5 and GPT-4, the authors forced right-to-left digit grouping by adding commas to numbers at inference time, and arithmetic performance improved substantially. They also found that errors under the default left-to-right grouping follow stereotyped patterns.
A study of post-OCR denoising on numerical texts found correction harder for dates, amounts and invoice numbers. A misread dictionary word has only a few close spellings to fall back on, but every one-character variant of an amount or invoice number is equally likely to be the real value.
A deeper caveat applies too. BPE and maximum prefix encoding introduce a sampling bias that more training or data cannot remove. The same researchers presented a probabilistic method that removes this bias without additional training.
How Does Tokenization Interact with OCR Output?
OCR errors range from single wrong characters to whole words. Some of those errors change the tokenization, splitting or merging tokens. A Lehigh University study of more than 3,000 scanned pages lists the typical OCR errors: substitutions such as l → i, h → li and rn → m, deleted spaces (“of the” → “ofthe”) and inserted spaces (“project” → “pro ject”). In one case from that study, a single misread character (an “i” read as “;”) produced three tokens where there had been one.
Character accuracy and token accuracy diverge. Overall OCR accuracy was 99.3%, but tokenization accuracy was 97.9%. On degraded images the counts climb. Missed and added tokenizations go from 0.5 and 1.0 on clean pages to 8.7 and 12.7 in the darkest degradation condition (Dark2). Each of those errors then feeds later processing and adds to the error cascade.
Numeric content is at a disadvantage:
- Texts of a numerical nature, such as invoices and payslips, have a significant disadvantage in OCR post-processing.
- OCR confuses visually similar characters. A “1” is most often misread as “i”, “t” or “l”.
- Dates are often several tokens long, frequently lowercase and full of numbers. Van Strien et al. (2020) found that named-entity recognition gets steadily worse as OCR quality falls, hitting geo-political entities hardest, then dates.
- The same study found a critical OCR quality threshold between 70 and 80%, below which most downstream tasks performed very poorly. The authors recommend OCR quality ideally above 90%.
A benchmark of LLM key-value extraction from OCR output names the effects together. Substitutions, token fragmentation, numeric corruption and line reordering hit key-value pairs that contain dates, monetary values, identifiers and addresses. The authors add that aggregate character and word error rates can hide errors in exactly those task-critical values. A stronger model or a better prompt cannot rebuild evidence that was lost or corrupted when the page was flattened into text.
Digital PDFs and DOCX files have embedded text layers. Parsers such as pdfplumber and PyMuPDF extract them with close to 100% accuracy, while the same study measured about 94% for Google Vision, 91% for DocTR and 85% for Tesseract v4 on scanned material. Documents that have a text layer can bypass OCR entirely. For the rest, OCR accuracy varies with document complexity, and that recognition stage is computer vision R&D work.
When Should an Extraction Pipeline Prefer Character or Byte Tokens?
We would choose character or byte tokens when critical fields (codes, amounts, dates) must be exact, the input is noisy, and the budget can absorb several times longer sequences. Otherwise, keep a subword model and protect the critical fields around it.
Models that work on raw bytes or characters handle any language without preparation, are more robust to noise and remove fragile preprocessing. ByT5 showed that byte-level models compete with token-level ones and perform better on tasks sensitive to spelling and pronunciation. Earlier work trained a byte-level transformer of about 836M parameters and brought tokenizer-free models level with word-based models on the One Billion Word benchmark. For English ASCII text, reading bytes is the same as reading one character per token, while non-ASCII characters usually take two or three bytes.
The cost is just as clear. According to the “Tokenizer Tax” study, character and byte models make sequences 3 to 5 times longer, and attention cost grows quadratically with length. The trade-off also depends on the task. The LongTail-Swap benchmark found that character-level models beat subword models on syntactic tasks involving rare words, while subword and word models do better on semantic tasks. The authors expected longer sequences to impair semantic tasks that need word co-occurrences learned.
For noisy numeric documents, one study compared byte-level ByT5 with subword BART on post-OCR denoising. ByT5 had the lowest average word error rate, and its results varied less between the numeric datasets FUNSD and SROIE. BART still won on Kleister-NDA. The authors also suspect that subword tokens model the long recurring sequences in SROIE better. So the result does not show that characters always win.
Choosing a Token Granularity for an Extraction Stage
| Situation | Leaning | Why |
|---|---|---|
| Born-digital PDFs, fields mostly free text | Subword model | Text layers extract near-perfectly, and semantic tasks favour subwords |
| Scanned pages, critical fields are codes, amounts or dates | Character or byte model for the correction stage | Byte models are more robust to noise and to spelling-sensitive content |
| Long documents, tight latency or cost budget | Subword model, with field-level safeguards | Character sequences run 3 to 5 times longer, with quadratic attention cost |
| Multilingual documents in high-fertility languages | Consider byte or character models | They remove the fertility disparity between languages |
| Fixed model behind an API | Test field-format normalisation before the prompt | Comma-grouping digits at inference time improved GPT-3.5 and GPT-4 arithmetic |
When the model is fixed, the tokenizer can still be inspected. Transformers v5 separates the tokenizer’s architecture (normalizer, pre-tokenizer, model type, post-processor, decoder) from its trained vocabulary and merges, and makes those components visible. That makes it possible to inspect how the pipeline’s real field formats split before choosing a model. We would also validate extracted identifiers against deterministic rules (check digits, format patterns, master data) outside the model, rather than trusting a value because the model produced it confidently. Character tokens are one stage among several in a staged extraction pipeline, not a replacement for it.
Measure Extraction per Field, on OCR-Derived Text
Testing has to look at the fields you care about, on OCR-derived text. The noisy-document benchmark above separates Key Recall (was the field found?) from Exact Match and Value F1 (was the value reproduced?). That separation shows whether OCR damage hits field detection or the values themselves. The same benchmark found that clean-text results do not predict results on OCR-derived text: the top-ranked model changed in 10 of 27 comparisons. So a model that looks better on clean annotations or aggregate CER can still be worse on task-critical values. We would report exact match by field type on real OCR output before accepting any change in token granularity. TechnoLynx covers that language-model side of document extraction through Generative & Agentic AI R&D. The open question for each pipeline is whether its critical fields fail at the OCR stage, at the token boundary or at the model.
FAQ
How Many Words Are 10,000 Tokens?
It depends on the language and the tokenizer. At the roughly 1.2 tokens per word measured for English, 10,000 tokens is about 8,300 words (10,000 ÷ 1.2). At about 3.1 for Greek, it is about 3,200 words. For budgeting by character count, see our quick answer on characters per token.
Is Tokenization Good or Bad?
It has both benefits and criticised shortcomings. Tokenization compresses the context and handles unknown words. It has also been criticised for causing sensitivity to spelling, language bias, weak arithmetic and poor performance in new domains.
What Is Document Intelligence in AI?
One proposed framework for document extraction merges OCR with language models to deliver structured outputs: scanned files go through OCR and digital files through layout-aware parsers, and a language model then identifies key-value pairs and resolves ambiguities in the extracted text.