Unigram tokenization
How Unigram tokenization splits text into subword pieces, what it changes about stored text, how it compares with BPE and WordPiece, and when plain text is the better choice.
Unigram tokenization is a subword segmentation method. It splits text into pieces smaller than words, such as roots, affixes or single characters, and chooses the split by scoring candidates with a simple probability model. Taku Kudo described it in 2018 alongside a technique called subword regularization. It is most often used through SentencePiece and is also available in the Hugging Face Tokenizers library. This review explains what the method changes, where it fits, and where its output stops being practical.
Short answer: is a Unigram tokenizer the right fit?
A Unigram tokenizer suits text that is being prepared for a machine learning model with a fixed vocabulary. It handles rare and unseen words without a huge word list, and it works for languages that do not mark word boundaries with spaces. It can also sample alternative segmentations, which some training setups use to make models more robust. The main tradeoff is that the output is a model-specific representation, not text for people. How a word is split depends on the training corpus and settings, and the normalization step that usually comes with it can alter characters. Use plain text when the result is meant for human readers, for exact-match search, for archival or legal fidelity, or for simple word counts.
Which kind of unigram is meant
The word unigram is ambiguous. In corpus linguistics and n-gram analysis, a unigram is a single item, so word unigram counts are a word frequency list built by splitting on spaces and punctuation. In current NLP tooling, Unigram tokenization or a Unigram tokenizer usually means the Unigram language model subword method, which can split one word into several pieces. The two produce different results, so check which one a tool means before comparing outputs.
How the Unigram model segments text
The tokenizer has a vocabulary of subword pieces, and each piece has a probability. A segmentation's score is the product of its pieces' probabilities. The pieces are treated as independent of each other, which is where the name unigram comes from. Most inputs can be segmented many ways, and the tokenizer normally picks the highest-scoring one with the Viterbi algorithm.
Illustrative only: not output from any trained model
Input: unhappiness
Candidate: un | happi | ness score = P(un) x P(happi) x P(ness)
Candidate: un | happ | iness score = P(un) x P(happ) x P(iness)
Candidate: u | n | h | a | p | ... single characters, usually a low score
Result: the candidate with the highest score
Training works top-down. It starts from a large seed vocabulary of candidate substrings and estimates their probabilities with the expectation-maximization algorithm. It then repeatedly removes the pieces whose loss hurts the corpus likelihood least, until the vocabulary reaches the target size. Single characters are kept, so any text made of characters seen in training can still be segmented. BPE works the other way: it starts from characters and merges frequent pairs into larger units.
| Method | How the vocabulary is built | How text is split when used |
| Unigram | Starts large and prunes pieces by likelihood | Most probable segmentation, or a sampled one if sampling is enabled |
| BPE | Starts from characters and merges frequent pairs | Applies the learned merges in order |
| WordPiece | Merges pairs chosen by a likelihood-based score | Greedy longest match from the start of each word |
Subword regularization means sampling a segmentation from the model's probability distribution instead of always taking the best one. It is mainly used during training as a form of data augmentation. If sampling is left on in a pipeline, the same input can produce different tokens on different runs. That matters for caching, deduplication and reproducibility.
What the transformation changes and what it leaves alone
Unigram segmentation does not reverse, mirror or restyle characters, and it is not a visual or CSS effect. It changes the representation: a string becomes a sequence of pieces, and usually then a sequence of integer IDs. The surrounding pipeline, however, can change the stored characters before segmentation happens.
- Normalization: SentencePiece applies NFKC-based normalization by default. This folds compatibility characters, such as full-width Latin letters to ordinary ones and the fi ligature to the letters f and i. It also turns the styled mathematical letters used by fancy-font generators into plain letters, and that styling cannot be recovered from the tokens.
- Whitespace: SentencePiece encodes spaces as a visible marker, the lower one-eighth block character U+2581, attached to the following piece. This is how spacing is restored when the tokens are decoded back to text.
- Unknown characters: characters outside the vocabulary become an unknown token, unless byte fallback is enabled, in which case they are split into UTF-8 bytes.
- Case and accents: some configurations lowercase text or strip accents. Check the tokenizer's settings rather than assuming either way.
Combining marks and emoji need extra care. The tokenizer works on code points after normalization, not on what a reader sees as a single character. NFKC composes a letter plus a combining accent into a precomposed character where one exists. Where none exists, the sequence stays as several code points, and they can end up in separate pieces. Multi-code-point emoji, such as zero-width-joiner sequences, skin-tone modified emoji and flags, can likewise be split across pieces or into bytes. Decoding with the same model reassembles them, but individual pieces shown on their own may render as fragments or replacement symbols.
Will the result stay readable and usable after copying or sharing?
Token IDs mean something only alongside the exact model file or vocabulary that produced them. Shared without it, they are unusable, and decoding them with a different version gives wrong text. Token pieces shown as strings are partly readable, but they contain marker characters and word fragments.
Decoding with the same model is designed to be lossless with respect to the normalized text, so a round trip returns the normalized form, not necessarily the original bytes. Styled Unicode, ligatures and full-width characters may come back as plain equivalents. If exact original text matters, store it alongside the tokens.
Readability for people is the weakest point. Debugging views and teaching demos that show pieces with markers or separators break words into fragments. A screen reader may read those fragments as nonsense or announce the marker character. No test with a specific screen reader was supplied for this review, so treat that as a likely risk rather than a measured result, and provide the plain-text version next to any tokenized display. Tokenization does not change the logical order of characters, and right-to-left scripts keep their stored order. Displaying pieces with separators in mixed-direction text can still look confusing because of how bidirectional rendering places neutral characters.
Tokens make a poor search index for user queries unless each query is tokenized by the same model. Even then, the same word can split differently depending on whether it follows a space. Editing tokenized text by hand is error-prone; edit the plain text and tokenize it again.
When plain text is the better choice
- The output will be read by people, quoted, or published.
- You need exact-string search, citation, legal or archival fidelity.
- The original Unicode styling, ligatures or full-width forms must survive.
- You need word counts or word frequency lists, where a word-level split fits better.
- The recipient does not have the same tokenizer model and version.
Evidence gaps
No benchmarks, test results, vocabulary sizes or version details were supplied. The points above describe the documented design of the Unigram method and common implementations, not measurements. Behavior varies with library version and configuration. Before relying on a specific tokenizer, run it on representative samples that include emoji, combining marks, styled Unicode, right-to-left text and unusual whitespace, and check that the round trip returns the text you need.