Different Tokenization Techniques: How They Work and When Each One Fits
A practical review of different tokenization techniques (whitespace, rule-based, character, subword and segmentation methods) covering what each changes, what it preserves, and when plain text is the better choice.
Tokenization splits text into units, called tokens, that a program can count, index, search or feed to a model. The different types of tokenization disagree about where those boundaries go. That choice decides whether punctuation, word forms, rare words and non-Latin scripts survive processing in a usable form. This review explains the main techniques, what each one does to text, and how to judge whether one fits your workflow.
A note on evidence: no tool-specific documentation, measurements or test results were supplied for this article. Everything below is based on general, verifiable properties of the techniques. It is not based on benchmarks of particular libraries. Where a claim depends on a specific tokenizer or destination, it is flagged as something to check yourself.
Which tokenization technique suits your intended use?
Recommendations depend on the task, so here they are bounded by use case. No single method is best overall.
- Quick counts, rough keyword lists or log scanning in space-separated languages: whitespace or simple regex tokenization is usually enough. Its main benefit is predictability. The tradeoff is that punctuation stays attached to words, so "km." and "km" become different tokens.
- Linguistic analysis such as part-of-speech tagging, concordances or frequency studies: use a rule-based word tokenizer designed for your language. It handles contractions, punctuation and numbers consistently. The tradeoff is that its rules are language-specific and may mis-split unfamiliar patterns such as URLs, hashtags or chemical names.
- Feeding text to a modern language model: use the exact subword tokenizer that ships with that model. Its tokens only make sense against that model's vocabulary, and any other tokenizer produces mismatched input.
- Languages written without spaces between words, such as Chinese, Japanese or Thai: you need a dictionary-based or statistical segmenter, or a subword method that does not depend on spaces. Whitespace splitting will not find word boundaries there.
- Highly inflected languages such as Russian, Finnish or Turkish: word-level tokens multiply quickly because each lemma has many surface forms. Subword tokenization, or word tokenization followed by lemmatization, reduces that sparsity.
- Text meant for people to read, quote or share: keep plain text. Tokenized output is an intermediate representation for software, not a readable format.
What tokenization actually changes
Tokenization by itself does not rewrite the characters in your text. It adds boundaries: a list of segments, often with offsets pointing back into the original string. This sets it apart from transformations that store different characters, such as reversing a string or substituting stylized Unicode "font" letters. It also differs from visual presentation, where CSS or bidirectional display changes how text looks without altering the stored characters. When people say a tokenizer "changed" their text, the change usually comes from a separate step bundled into the pipeline. Common examples are lowercasing, Unicode normalization or accent stripping.
Whitespace and regex tokenization
The simplest approach splits on spaces, or on a regular expression such as "runs of letters and digits." It is fast and transparent. The cost is that each token's boundaries depend entirely on how the writer used spaces and punctuation.
Input: Don't stop—it's 3.5 km.
Split on whitespace:
["Don't", "stop—it's", "3.5", "km."]
In this example the em dash joins two words into one token, and the final period sticks to "km." A regex that keeps only letter runs would fix that. But it would break "3.5" into "3" and "5" and drop the apostrophe, showing how each simple rule trades one error for another.
Rule-based word tokenization
Rule-based tokenizers apply language-aware rules. They separate punctuation, keep decimals and abbreviations intact, and split contractions in a defined way. Treebank-style conventions for English, for example, split "Don't" into a verb and a clitic.
Input: Don't stop—it's 3.5 km.
Treebank-style rules (illustrative):
["Do", "n't", "stop", "—", "it", "'s", "3.5", "km", "."]
This output is easier to analyze statistically. But it no longer matches how a reader sees the words, and rejoining tokens with spaces would not reproduce the original sentence. Exact behavior differs between implementations, so check the documentation of the one you use rather than assuming this split.
Character-level tokenization
Character tokenization treats each character as a token. It never meets an unknown word, which helps with typos and rare terms. The tradeoff is much longer sequences and units that carry little meaning on their own. It also raises a question that matters for any transformation working character by character: what counts as a character?
# Python counts code points, not visible characters
len("e\u0301") # "é" built from e + combining acute accent -> 2
len("👨👩👧") # family emoji: 3 people joined by 2 zero-width joiners -> 5
Splitting by code point can separate an accent from its letter or break an emoji sequence into separate people and invisible joiners. The same problem makes naive string reversal garble accented text and emoji. A character tokenizer intended for human-facing text should work on grapheme clusters, meaning user-perceived characters as defined by Unicode text segmentation rules. Normalizing text to a consistent form first (for example, NFC) also reduces surprises.
Subword tokenization: BPE, WordPiece, Unigram and SentencePiece
Subword methods sit between words and characters. Frequent words stay whole, while rare words are broken into smaller, reusable pieces. The main variants are:
- Byte Pair Encoding (BPE) builds a vocabulary by repeatedly merging the most frequent adjacent pair of symbols in training data.
- Byte-level BPE runs the same process over raw bytes, so any input can be encoded without an "unknown" token.
- WordPiece chooses merges based on how much they improve a language-model likelihood rather than raw frequency. It marks word-internal pieces with a prefix such as "##".
- Unigram language-model tokenization starts from a large candidate vocabulary and prunes it. It can consider several possible segmentations of the same word.
- SentencePiece is a framework that implements BPE and Unigram directly on raw text. It treats the space as an ordinary symbol, often shown as "▁", so it does not need a language-specific pre-tokenizer.
Illustrative only. Real splits depend on the trained vocabulary.
WordPiece-style: ["un", "##happi", "##ness"]
SentencePiece-style: ["▁un", "happi", "ness"]
The main benefit is a fixed, manageable vocabulary that still covers rare words, names and inflected forms. The decisive tradeoff is that the pieces do not necessarily match morphemes or anything a linguist would recognize. The same word can also split differently in different contexts or vocabularies. Token counts from one subword tokenizer cannot be compared with counts from another.
Segmentation for languages without spaces
In scripts that do not mark word boundaries with spaces, word tokenization is really a segmentation problem. Tools use dictionaries, statistical models or neural models to decide where words begin and end, and the result can be ambiguous even for human annotators. For these languages, the quality of the segmenter and its dictionary matters more than the general technique. Evaluate it on text from your own domain.
Sentence tokenization
Sentence tokenization splits text into sentences rather than words. Its main difficulty is the period, which also appears in abbreviations, decimals, initials and URLs. Errors here carry into any later word-level analysis, so it is worth spot-checking on your own material.
How the techniques compare
| Technique | Unit | Main strength | Main tradeoff | Can the original be rebuilt from tokens alone? |
| Whitespace / regex | Space-separated strings | Fast, transparent | Punctuation and spacing errors pass straight through | Partly; exact spacing is lost unless offsets are kept |
| Rule-based word | Words, punctuation, clitics | Consistent linguistic units | Language-specific; may mis-split unusual strings | Not reliably without offsets |
| Character / grapheme | Characters or grapheme clusters | No unknown words | Long sequences; little meaning per unit | Yes, if spaces are kept as tokens |
| WordPiece | Subwords with continuation marker | Compact vocabulary, good coverage | Pieces need not match morphemes; normalization may be lossy | Often approximate |
| BPE / byte-level BPE | Subwords or byte sequences | Covers any input (byte-level) | Vocabulary-specific; counts not comparable across models | Generally yes for byte-level designs |
| SentencePiece (BPE or Unigram) | Subwords with space symbol | Language-independent, no pre-tokenizer | Pieces can look arbitrary to readers | Designed to be reversible, subject to its normalization settings |
| Dictionary/statistical segmentation | Words in unspaced scripts | Finds boundaries spaces cannot show | Ambiguity; depends on dictionary coverage | Yes; text is segmented, not altered |
The last column summarizes design intent, not measured results. Whether a particular library round-trips text exactly depends on its configuration. Lowercasing, accent stripping and compatibility normalization such as NFKC are irreversible steps that some pipelines apply before tokenizing. If exact reconstruction matters, keep the original text and token offsets rather than relying on detokenization.
Will tokenized output stay readable and usable when copied or shared?
Tokens are meant for software, so treat them as a working format rather than something to publish. Copying a token list into a document, chat or web page carries along whatever markers the tokenizer uses, such as "##", "▁" or byte-level symbols. These are ordinary characters once pasted. A reader sees them as clutter, and a search for the original word will not match "##ness" or "▁un".
Accessibility is an open question here rather than a verified result. No screen reader or other assistive technology was tested for this review. Because the markers are real characters, assistive tools are likely to announce them or read fragments as separate words, but behavior varies by tool and settings. If tokenized output must appear in front of people, test it with the specific assistive technology your audience uses. Always provide the plain-text original alongside it.
Editing has a similar limit. Changing a token in a list does not update the source text, and re-tokenizing edited text can shift every later boundary and offset. Keep the original string as the source of truth, and regenerate tokens from it rather than editing tokens by hand.
Plain text is the right choice whenever the result will be read, quoted, searched or edited by people. Tokenized output belongs inside the analysis or model pipeline that consumes it.
Gaps to close before choosing
- No performance, speed or accuracy figures were available for any tokenizer; compare candidates on a sample of your own text.
- Exact splits shown above are illustrative; confirm real output with the tokenizer and vocabulary you intend to use.
- Round-trip behavior and normalization settings vary by library and configuration; check the documentation and test with accented letters, emoji, numbers and URLs.
- Assistive-technology and destination behavior (editors, messaging apps, search tools) was not tested; verify any destination that matters to you.