Convert Text to Token Sequences: What Tokenizers Change and When to Use Them
A practical review of converting text to token sequences: what a tokenizer keeps and discards, how word IDs are assigned, and when to keep plain text instead.
Turning text into token sequences means splitting text into units, usually words in a word-level tokenizer, and replacing each unit with an integer from a vocabulary. The result is useful for machine learning pipelines, frequency analysis and other tasks where a model or script needs consistent numeric input. It is not a format for people to read, share or publish. This review explains what the conversion changes, what it discards, and when you should keep plain text alongside it or use plain text alone.
Is converting text to token sequences right for your use?
Use token sequences when the consumer of the output is software: training or running a text model, counting and comparing word usage across documents, or preparing fixed-length numeric input for a neural network. The main benefit is consistency, because the same word always maps to the same number under the same vocabulary, which makes text comparable and machine-processable.
The decisive tradeoff is information loss. A typical word-level tokenizer lowercases text, strips punctuation and discards spacing, and it may drop or merge words that are not in its vocabulary. A token sequence cannot be turned back into the exact original text, and it is meaningless without the vocabulary that produced it.
Plain text is preferable whenever a person will read, edit, search, quote or listen to the content; when exact wording, capitalization or punctuation matters, such as names, legal text, code or quotations; and when you need to archive the source. In those cases, store the original text and treat the token sequence as a derived, disposable artifact.
What the conversion actually changes
Unlike text reversal, mirrored lettering or Unicode font styling, tokenization does not change how text looks. It replaces the text with different data. The stored output is a list of integers, not characters, so there is no visual presentation layer to separate from stored content: the numbers are the content.
A word-level tokenizer typically works in two stages. First, it builds a vocabulary from a body of text, often called fitting. Second, it converts text into sequences by looking up each word's index in that vocabulary. Common processing steps include the following, though defaults vary by tool and should be checked in its documentation:
- Normalization: converting text to lowercase so that "The" and "the" share one index.
- Filtering: removing punctuation and certain symbols before splitting.
- Splitting: breaking text into words, often on whitespace.
- Indexing: assigning integers to words, frequently ranked so that more common words get smaller numbers.
- Vocabulary limits: keeping only the most frequent words and ignoring or replacing the rest.
- Out-of-vocabulary handling: either dropping unknown words silently or mapping them all to a single reserved token.
Here is an illustrative example using a frequency-ranked vocabulary with lowercasing and punctuation removal. Given the two sentences "The cat sat." and "The dog sat down.", the words "the" and "sat" each appear twice, while "cat", "dog" and "down" appear once. One possible vocabulary and the resulting sequences:
Vocabulary: the=1 sat=2 cat=3 dog=4 down=5
"The cat sat." -> [1, 3, 2]
"The dog sat down." -> [1, 4, 2, 5]
Several properties are visible here. The capital T and the periods are gone. The sequences have different lengths, so many pipelines add padding to make them equal, and some tools reserve index 0 for that purpose. Exact numbering for words with equal counts depends on each tool's tie-breaking rules, so another tokenizer could assign different numbers to the same corpus.
Unknown words show the biggest behavioral difference between configurations. If a new sentence such as "The bird sat." is converted with the vocabulary above, "bird" has no index. Without an out-of-vocabulary token, the word may simply disappear and the output looks like a shorter, valid sentence. With an out-of-vocabulary token, the word becomes a placeholder index, which preserves sentence length and signals that something was unrecognized, but it still loses which word it was. Configurations that reserve an index for unknown words usually shift other word indices, so vocabularies built with and without that option are not interchangeable.
In Python, a widely cited example of this workflow is the legacy Keras Tokenizer, which fits on texts and then converts them to sequences. Its module has been deprecated in newer Keras releases in favor of preprocessing layers, so check the documentation for the version you have installed. The pattern looks like this:
from tensorflow.keras.preprocessing.text import Tokenizer
texts = ["The cat sat.", "The dog sat down."]
tokenizer = Tokenizer(oov_token="<OOV>")
tokenizer.fit_on_texts(texts)
sequences = tokenizer.texts_to_sequences(texts)
Because this configuration sets an out-of-vocabulary token, its numbering will differ from the illustrative vocabulary above. Run the code against your own installed version rather than relying on the earlier numbers.
Word tokens versus subword tokens
The word "token" is used ambiguously. Word-level tokenizers, the focus here, map whole words to IDs. Many modern language models use subword tokenizers, which split rare words into smaller pieces so that unseen words can still be represented. The same sentence produces different sequences under different tokenizers, and token IDs from one tokenizer mean nothing to another. If your goal is to estimate token counts for a specific language model, a word-level tokenizer will not give you that model's numbers; use the tokenizer that belongs to that model.
Language and script limits
Splitting on whitespace assumes that words are separated by spaces. That assumption fails for languages written without spaces between words, such as Chinese, Japanese and Thai, where a whitespace tokenizer may treat a whole phrase or sentence as one token. Contractions, hyphenated compounds, apostrophes, emoji and accented characters are also handled differently across tools; some filters strip characters you may want to keep. If your text includes these, inspect the vocabulary after fitting rather than assuming the defaults suit it.
Will the result stay readable and usable after copying or sharing?
Token sequences copy and paste reliably as plain numbers, which is part of their appeal: integers survive almost any text field or file format. Their usability, however, depends entirely on context that does not travel with them.
| Concern | What happens with token sequences | What to do |
| Readability | A list of integers carries no meaning to a reader | Never use sequences as user-facing text |
| Accessibility | A screen reader would announce a string of numbers, not words | Provide the original text wherever people read or listen |
| Search | Searching for a word will not find its numeric ID | Keep the original text indexed for search |
| Editing | Changing a word means re-tokenizing; editing numbers directly is error-prone | Edit the source text, then regenerate sequences |
| Sharing | Sequences are meaningless without the exact vocabulary and settings used | Share or version the vocabulary together with the sequences |
| Reversal | Decoding with the vocabulary gives approximate text without case, punctuation or dropped words | Keep the original if exact wording matters |
Some tokenizers can map sequences back to words, but the result is a reconstruction, not a restoration. In the earlier example, decoding [1, 3, 2] yields "the cat sat" rather than "The cat sat.", and any word dropped as out-of-vocabulary cannot be recovered at all.
A plain-text equivalent is needed in every case where a person is the audience, where text must remain searchable, and where you may need to rebuild the vocabulary later with different settings. Treat the original text as the source of truth and the token sequences as output that can be regenerated.
Practical checks before you rely on the output
- Inspect the vocabulary after fitting to confirm that lowercasing and punctuation filtering suit your text.
- Decide deliberately whether unknown words should be dropped or mapped to a placeholder.
- Save the fitted vocabulary and settings; sequences produced with a different vocabulary are not comparable.
- Use the same fitted tokenizer for training data and for any new text you convert later.
- If you need counts for a particular language model, use that model's own tokenizer.
- If you use an online converter, do not assume anything about how it stores or retains your text unless its documentation states it.
Evidence gaps
This review is based on the general, documented behavior of word-level tokenizers. No specific tool was tested for this article, and no measurements of speed, accuracy or compatibility were available. Default settings, index numbering, handling of non-Latin scripts and deprecation status differ between tools and versions, so verify behavior against the documentation and a small test with your own text before building on it.