Text tokenization methods and strategies

A practical review of tokenization methods, from whitespace and rule-based splitting to subword schemes used in LLMs, and how to pick one that preserves meaning.

Tokenization splits text into smaller units, called tokens, that software can count, index, compare or feed to a model. The units might be words, punctuation marks, characters, bytes or fragments of words. Which strategy fits depends on what happens to the tokens next: a search index, a classic NLP pipeline and a large language model each place different demands on the split. This review explains what tokenization changes, compares the main methods, and covers the points where a tokenized result can lose meaning or stop being usable.

What tokenization actually changes

Segmentation by itself does not alter the stored characters. It records where one unit ends and the next begins, usually as a list of strings, a list of integer IDs, or both. Many tokenizers, however, run preprocessing steps first, and those steps do change the text: lowercasing, stripping accents, Unicode normalization (for example NFKC, which folds some visually similar or compatibility characters into a single form), and collapsing or removing whitespace. Whether a pipeline preserves the original text therefore depends on these steps more than on the splitting rule.

Tokenization is also not a visual transformation. Unlike reversed or mirrored text, Unicode lookalike "fonts" or CSS styling, it does not change what a reader sees in the source document. When people talk about "reversing" tokenization, they usually mean detokenization: mapping tokens or IDs back into a string. That reverse step is exact only if the tokenizer was designed to be lossless and no lossy normalization was applied.

The main tokenization methods

  • Whitespace splitting: breaks text on spaces and line breaks. Simple and fast, but leaves punctuation attached to words and does not work for languages written without spaces between words, such as Chinese, Japanese or Thai.
  • Rule-based word tokenization: uses rules or regular expressions to separate punctuation, contractions, numbers and similar cases. Unicode's word-boundary rules (Unicode Standard Annex #29) are a common basis for language-neutral defaults.
  • Dictionary or statistical word segmentation: uses a lexicon or trained model to find word boundaries in scripts that do not mark them with spaces.
  • Character tokenization: treats each character as a token. There are no unknown words, but sequences get much longer and the definition of "character" matters (see the edge cases below).
  • Byte tokenization: treats each byte of the encoded text, typically UTF-8, as a unit. Any input can be represented, at the cost of even longer sequences.
  • Subword tokenization: splits text into frequent fragments learned from a training corpus, so common words stay whole and rare words break into pieces. The main algorithms are Byte Pair Encoding (BPE), WordPiece and the Unigram language model.
  • Sentence segmentation: splits text into sentences rather than words. It is often run before word or subword tokenization and has its own ambiguity, such as periods in abbreviations.
Method | Typical unit | Handles unseen words | Exact round trip to original text | Main tradeoff
Whitespace | Space-separated chunk | No | No; whitespace type and count are lost | Fast but crude; fails on unspaced scripts
Rule-based word | Word or punctuation mark | No | Usually not, unless character offsets are kept | Readable tokens; rules are language-specific
Character | Character or code point | Yes | Yes, if no normalization is applied | Long sequences; little built-in meaning per token
Byte | Byte | Yes | Yes | Longest sequences
Byte-level BPE | Learned byte sequence | Yes | Yes, by design | Token boundaries can fall inside a character
WordPiece (BERT-style) | Learned subword | Mostly | Often not; whitespace handling and optional lowercasing or accent stripping lose information | Tied to a fixed vocabulary and normalization setup
Unigram or BPE via SentencePiece | Learned subword, whitespace encoded as a symbol | Yes | Whitespace is preserved, but configured normalization rules can still change characters | Language-neutral; normalization settings need checking

Types of tokenization in LLMs

Large language models almost always use subword tokenization. Common families include byte-level BPE, Unigram or BPE models trained with the SentencePiece library, and WordPiece, which is associated with BERT and related encoder models. Each model ships with a fixed vocabulary learned from its training data, and text has to be split with that exact tokenizer. Using a different tokenizer, even one built on the same algorithm, produces IDs the model was not trained on.

Token counts matter in practice because context limits and usage-based pricing are usually measured in tokens, not words or characters. The same sentence can produce very different counts under different tokenizers. Text in languages or scripts that were less common in a tokenizer's training data tends to split into more pieces per word, so it uses more of the context window. No measurements for specific models were supplied for this review, so any count comparison should be made by running the target tokenizer on representative text.

Subword tokenizers mark word boundaries in different ways, which affects how raw token lists look when printed. WordPiece marks a fragment that continues a word with a leading "##". SentencePiece replaces spaces with the symbol "▁" attached to the following piece. GPT-2-style byte-level BPE displays a leading space as "Ġ" in its printable vocabulary. The segmentations below illustrate these conventions; they are not output from any particular trained vocabulary, and real splits depend on the vocabulary.

Input:            The tokenizer splits unhappiness

Whitespace:       [The] [tokenizer] [splits] [unhappiness]
WordPiece style:  [the] [token] [##izer] [splits] [un] [##happiness]
SentencePiece:    [▁The] [▁token] [izer] [▁splits] [▁un] [happiness]
Byte-level BPE:   [The] [Ġtoken] [izer] [Ġsplits] [Ġun] [happiness]

Edge cases: combining marks, emoji and scripts without spaces

What a reader perceives as one character can be several Unicode code points. An accented letter such as "é" can be stored as a single precomposed code point or as "e" followed by a combining acute accent. Many emoji are sequences: a family emoji, for instance, is several person emoji joined by zero-width joiner characters. Unicode calls the user-perceived unit a grapheme cluster.

"é" (precomposed)   U+00E9
"é" (decomposed)    U+0065 U+0301
family emoji        U+1F468 U+200D U+1F469 U+200D U+1F467

Tokenizers handle these sequences differently. A character tokenizer that splits by code point separates the accent from its letter and breaks the emoji into parts plus invisible joiners. A byte-level tokenizer may place a token boundary inside a single code point, so an individual token may not decode to valid text on its own even though the full sequence round-trips correctly. A grapheme-aware segmenter keeps each cluster together. Unicode normalization also matters: the two forms of "é" look identical but tokenize differently unless both are normalized to the same form first. For scripts written without spaces, whitespace splitting returns whole phrases or sentences as single tokens, so a dictionary-based, statistical or subword method is needed.

Will the result remain readable and usable?

Tokens are an internal representation, not a format meant for people. A copied token list carries brackets, separators and boundary markers such as "##", "▁" or "Ġ", and joining the pieces correctly requires the matching detokenizer rather than simple concatenation. Token IDs are meaningful only alongside the vocabulary that produced them.

  • Reading order and meaning: segmentation keeps tokens in their original order, but lossy normalization can merge distinctions that matter, such as case in names or accents that change a word's meaning.
  • Editing: changes made to a token sequence have to be detokenized before they read as normal text. Keeping character offsets for each token lets edits and highlights be mapped back to the original string.
  • Search: the same tokenizer and normalization must be applied when indexing documents and when processing queries. A mismatch, such as accent stripping at index time but not at query time, causes missed matches.
  • Accessibility: if tokenized text is displayed to readers, for example in a debugging or teaching interface, screen readers may announce marker symbols or read fragments as separate words. No assistive-technology testing was supplied for this review, so that behavior should be checked with the specific tools involved rather than assumed.
  • Plain-text equivalent: any human-facing use, including storage, sharing, quoting and display, should keep the original untokenized text. Tokenization is best applied as a processing step, not as a replacement for the source.

Choosing a tokenization strategy

For work with a specific language model, use that model's own tokenizer without modification. The main benefit is correct input; the decisive constraint is that no alternative strategy is compatible. For keyword search and classic NLP tasks such as tagging or counting words, rule-based word tokenization built on Unicode word boundaries gives readable tokens, with dictionary-based segmentation added for languages written without spaces. For noisy text, unusual spellings or mixed scripts, character or byte tokenization avoids unknown-token problems, at the cost of much longer sequences. Subword methods sit between these options and are the usual choice when training a new model.

Whatever the method, decide early whether an exact round trip matters. If it does, choose a lossless design such as byte-level BPE, or keep character offsets, and avoid lowercasing, accent stripping and compatibility normalization. Plain, untokenized text remains the better choice whenever the output is for human readers, needs to be copied or shared, or must stay editable.

Gaps in the evidence

No benchmarks, token counts, vocabulary sizes or tool-specific test results were supplied for this review, so it does not compare named tokenizers on speed, efficiency or accuracy. The behaviors described are general properties of the methods. Before relying on a tokenizer, run it on representative samples, including accented text, emoji, numbers and every language you expect, and confirm that detokenizing the output reproduces the original string where that matters.