Tokenization for Sentence Transformers

How sentence transformer tokenizers split text, what they change, how they handle reversed, mirrored or Unicode-styled input, and when to normalize to plain text first.

A sentence transformer turns a piece of text into a single embedding vector, but it never sees your text directly. A tokenizer first breaks the input into subword units and maps them to integer IDs. This review explains what that step changes and what it leaves alone. It also covers how the tokenizer copes with reversed, mirrored or Unicode-styled text, and when you should convert input to plain text before embedding it.

Short answer: is tokenization a safe transformation for your text?

For ordinary, plainly written text, yes. A sentence transformer's tokenizer is designed to keep enough of the input that the model can produce a meaningful embedding, and you rarely need to configure it. Its main benefit is consistency: the same text always produces the same token IDs for a given model.

The key tradeoff is that tokenization is lossy and tied to one model. Depending on the tokenizer, it may lowercase text, strip accents, replace unknown characters with a placeholder token, or cut off input beyond the model's maximum sequence length. None of this matters when the input is clean prose. It matters a lot when the input contains decorative Unicode letters, reversed strings, upside-down lookalike characters, or very long passages.

Plain text is preferable whenever the input has been visually styled. Bold or script Unicode letters, mirrored or upside-down text, and character-reversed text all carry the meaning in how they look, not in the characters the tokenizer receives. Convert such input back to ordinary characters before embedding it, and keep the original text, not the tokenizer's decoded output, as your record of what was said.

What the tokenizer actually changes

In the Sentence Transformers library, the tokenizer comes from the underlying Hugging Face model. It is exposed as the model's tokenizer attribute, and the model's tokenize method returns the tensors the network consumes, chiefly input IDs and an attention mask. The tokenizer does not edit the string you pass in. It produces a separate, model-specific representation of that string.

Most tokenizers work in three stages, and each stage has a different effect on your text:

  • Normalization: optional rewriting of characters, such as Unicode normalization, lowercasing or accent removal. Which of these happen depends on the specific model.
  • Pre-tokenization and subword splitting: the text is split on whitespace and punctuation, then into pieces from a fixed vocabulary using an algorithm such as WordPiece (common in BERT-derived models), byte-pair encoding, or a SentencePiece unigram model (common in some multilingual models).
  • Post-processing and truncation: special tokens are added at the start and end, and anything beyond the model's maximum sequence length is dropped.

Because the vocabulary is fixed, a word the tokenizer has not seen as a whole is split into smaller known pieces. Characters that no vocabulary piece covers may become an unknown token, depending on the algorithm. Byte-level tokenizers avoid unknown tokens by falling back to raw bytes, but the resulting pieces carry little meaning the model has learned.

Clarifying "reverse", "mirror" and "font" in this context

These words describe very different operations, and the tokenizer treats each one differently. What decides the outcome is whether the stored characters changed or only the way they are displayed.

Transformation | What is stored | What the tokenizer receives
Character reversal ("text" becomes "txet") | New character order | A different, usually unfamiliar sequence that splits into many fragments
Word-order reversal | Same words, new order | Familiar tokens, but sentence meaning and the embedding can shift
Upside-down or "mirror" lookalike characters | Different code points that resemble flipped letters | Unrelated characters, often rare or unknown tokens
Unicode "fonts" (mathematical bold, script, double-struck and similar) | Different code points from the plain letters | Plain letters only if the normalizer folds them, otherwise rare or unknown tokens
CSS styling or a visual mirror transform | Unchanged characters | The original text, if you extract the underlying characters rather than an image
Right-to-left (bidirectional) display | Characters in logical order | Logical order, unaffected by how the text is visually reordered on screen

Character reversal needs extra care. Reversing a string code point by code point detaches combining marks from their base letters and breaks multi-code-point emoji, such as sequences joined with zero-width joiners or flags built from paired regional indicators. The reversed string can therefore contain stray accents or broken emoji fragments that were never in the original. The tokenizer encodes those faithfully, and that adds noise to the embedding.

Unicode-styled "fonts" depend most on the model. Compatibility normalization (NFKC) maps many styled letters, such as mathematical bold, back to their plain equivalents. Some tokenizers apply a normalization of this kind and some do not. An uncased BERT-style tokenizer, for example, lowercases text and strips accents, but that does not guarantee that styled letters are folded to plain ones. Check the specific model rather than assuming either way.

How to check your own model

The source material gave no test results, so this review reports no observed outputs. The snippet below shows how to inspect the tokens a model produces for plain, styled and reversed versions of the same phrase, and how to view its normalizer and maximum sequence length. Replace the model name with the one you actually use.

from sentence_transformers import SentenceTransformer

model = SentenceTransformer("sentence-transformers/all-MiniLM-L6-v2")
tok = model.tokenizer

samples = ["plain text", "𝐛𝐨𝐥𝐝 𝐭𝐞𝐱𝐭", "txet nialp"]
for text in samples:
    ids = tok(text)["input_ids"]
    print(repr(text), tok.convert_ids_to_tokens(ids))

print("max_seq_length:", model.max_seq_length)
print("normalizer:", tok.backend_tokenizer.normalizer)

If the styled sample comes out as unknown tokens or many fragments while the plain sample yields whole words, normalize the input before embedding it. You can apply compatibility normalization yourself with Python's standard library:

import unicodedata

def to_plain(text: str) -> str:
    return unicodedata.normalize("NFKC", text)

NFKC is not a neutral cleanup. It also rewrites superscripts, full-width characters, ligatures and some symbols, so test it on representative data if those characters carry meaning in your domain. It does not undo character reversal or upside-down lookalike substitutions. Those need a dedicated reverse mapping, or better, the original text.

Will tokenized text stay readable and usable?

Token IDs are not meant to be read, copied or shared. They only mean something to the model whose vocabulary produced them. Decoding them back to a string is useful for debugging, but the decoded text is not guaranteed to match the input. Depending on the tokenizer, it may lose case, accents, original spacing around punctuation, or characters that became unknown tokens. Always store and display the original text, and treat token IDs and embeddings as derived data.

Truncation is the most common silent usability problem. Text longer than the model's maximum sequence length is cut off without an error, so the embedding reflects only the first part of a long document. Split long inputs into chunks if the later content matters for search or comparison.

Readability for people is a separate question that affects the source text, not the tokens. Styled Unicode letters, mirrored lookalikes and reversed strings can be hard to search, edit and copy, and accessibility guidance commonly cautions that assistive technology may read them poorly or not at all. This review had no documentation or scoped test for any particular screen reader, platform or search engine, so it makes no claim about a specific destination. Wherever such text is shown to readers, provide a plain-text equivalent. That same plain version is also the right input for a sentence transformer.

Gaps in the available evidence

  • No measurements were supplied for how much styled, reversed or mirrored input changes embedding similarity compared with plain text. The direction of the effect follows from how tokenizers work, but its size for any given model is unverified.
  • No per-model inventory of normalizers or sequence-length limits was supplied. Inspect your model as shown above instead of relying on defaults.
  • No assistive-technology or platform tests were supplied, so compatibility statements here stay general.

Bottom line

A sentence transformer's tokenizer is a reliable, model-specific encoding step for plain text, but it does not repair visually transformed input. Clean up styled, reversed or mirrored text into ordinary characters before embedding it, keep the original text as the source of truth, and check your model's normalizer and length limit before trusting its embeddings on unusual input.