Inspecting spaCy Token Attributes: What They Change, What They Preserve, and When to Use Them

A practical review of spaCy token attributes: how tokenization keeps the original text recoverable, which attributes are derived views, and where Unicode-styled or reversed input weakens results.

spaCy splits text into tokens and attaches attributes to each one, such as the token's text, its character offset, its lemma, its part-of-speech tag and its lexical flags. If you treat that step as a text transformation, the practical question is whether the output keeps enough of the original meaning and structure for your use: search indexing, annotation review, data cleaning, or feeding a downstream model. This review covers what the attributes represent, what they leave untouched, and where they become unreliable.

Is inspecting token attributes suitable for your use?

For most analysis tasks, yes, within clear limits. The main benefit is that spaCy's tokenization is non-destructive. Each token records its own text and the whitespace that followed it, so the original string can be rebuilt exactly from the tokens. Attributes like lemma, lowercase form or normalized form are stored alongside the token rather than replacing it. You can work with a simplified view and still trace every result back to the exact characters in the source.

The main tradeoff is that the linguistic attributes are model predictions, not facts about the text. Part-of-speech tags, dependency labels, lemmas from rule-based or lookup lemmatizers, and entity types depend on the pipeline you load and on how closely your input resembles that pipeline's training data. A blank pipeline gives you tokenization and lexical flags only. Trained pipelines add predicted attributes that can be wrong, especially on informal, stylized or non-standard text.

Plain text, or plain string operations, are the better choice in three situations:

  • You only need character counts, simple splitting or exact substring matching. A tokenizer adds overhead and its own segmentation decisions without adding value.
  • Your input is mostly Unicode-styled lettering, reversed strings or decorative symbols. Predicted attributes will be unreliable, and you should normalize or recover the plain text first.
  • You are handing results to people rather than programs. A readable excerpt of the original sentence usually communicates better than a table of tags.

What token attributes actually change

Nothing in the stored text. Creating a Doc does not rewrite, reverse, mirror or restyle any characters. The Doc holds the original string, and each token is a view onto a slice of it. The attributes fall into a few groups.

Group | Examples | What it represents
Position and surface | text, text_with_ws, whitespace_, idx, i | The exact characters of the token, the whitespace after it, its character offset in the Doc, and its index among tokens
Lexical views | lower_, norm_, shape_, prefix_, suffix_ | Derived string forms computed from the token text; they sit beside the original rather than replacing it
Lexical flags | is_alpha, is_digit, is_punct, is_space, like_num, is_stop | Boolean checks on the token text or on a word list
Predicted linguistic | lemma_, pos_, tag_, dep_, morph, head, ent_type_ | Output of pipeline components; empty or default if the relevant component is not loaded

There is one naming convention to check before you trust an export. Many attributes come in two forms. The version without a trailing underscore, such as pos or lemma, returns an integer hash. The version with the underscore, such as pos_ or lemma_, returns the readable string. If a spreadsheet of results is full of large integers, the underscore was probably left off.

The following snippet uses a blank English pipeline, which needs no model download, to show the surface attributes for a short input.

import spacy

nlp = spacy.blank("en")
doc = nlp("Don't stop.")

for token in doc:
    print(repr(token.text), token.idx, repr(token.whitespace_), token.is_alpha)

# The original string is recoverable from the tokens
assert "".join(t.text_with_ws for t in doc) == doc.text

The English tokenizer splits the contraction into "Do" and "n't" and separates the final period. Reading each row against the source string:

text | idx | whitespace_ | is_alpha
Do | 0 | (empty) | True
n't | 2 | (single space) | False
stop | 6 | (empty) | True
. | 10 | (empty) | False

The offsets line up with the original characters, and the whitespace field shows exactly where the single space sits. That is what makes the transformation safe to reverse. The split itself is still a decision the tokenizer made. A tool that expects "Don't" as one word will disagree with it, so check whether your downstream step uses the same segmentation.

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

These terms come up when people feed transformed text into spaCy, and they mean different things.

  • Reversed text is a stored change. The code points really are in a different order, so the tokenizer sees different strings, and trained components see words they were not trained on.
  • Mirrored or upside-down text usually means substituting look-alike characters from other Unicode blocks. That is also a stored change. The tokens contain those substitute characters, not the letters they resemble.
  • Stylized "fonts" made by copying characters from the Unicode mathematical alphanumeric range are stored substitutions, not fonts. They are distinct code points from ordinary Latin letters, so lower_, lemma_ and stop-word checks will not treat them as the familiar words.
  • Real fonts, CSS styling and right-to-left visual display change only how text looks on screen. spaCy never sees them. It processes the underlying string in its stored logical order.

In practice, if you are inspecting token attributes to judge whether a styled or reversed string still reads as language, the attributes will mostly tell you that the pipeline does not recognize it. That is useful as a diagnostic. It does not tell you how a human reader will perceive the text.

Unicode details that affect offsets and splits

The idx attribute is a character offset into the Python string, so it counts code points, not bytes and not user-perceived characters. Two cases need care.

  • Combining marks: a letter followed by a separate combining accent occupies two code points, so offsets and token lengths include both. If your source mixes precomposed and decomposed forms, apply Unicode normalization consistently before processing. Otherwise identical-looking words can produce different token text and different lexical attributes.
  • Multi-code-point emoji: sequences joined with zero-width joiners, skin-tone modifiers or flag pairs are several code points that display as one symbol. The material provided here includes no tested evidence of how a given spaCy version and language tokenizer segment these sequences. Test with your own pipeline before relying on token boundaries around emoji.

Character-level operations on token text have the same problem. Reversing or slicing a token string in Python works on code points, so it can detach a combining mark from its base letter or break an emoji sequence apart. If your workflow reverses or mirrors token text after inspection, operate on grapheme clusters rather than raw code points.

Will the results stay readable and usable after export or sharing?

Token attributes are ordinary strings, integers and booleans, so they copy cleanly into CSV, JSON or a spreadsheet as long as you export the underscore string forms. Usability problems tend to come from the way results are presented rather than from the data itself.

  • Reading order: a token-per-row table breaks sentences into fragments. Keep the original sentence, or the span text plus its character offsets, next to the token rows so a reader can see the context.
  • Whitespace: exports that drop whitespace_ lose the information needed to rebuild the text. Include text_with_ws or the whitespace field if anyone needs to reconstruct the source.
  • Editing and search: if someone edits token text in an exported file, the offsets no longer match the original document. Treat exported attributes as read-only annotations, and re-run the pipeline on edited text rather than patching tokens by hand.
  • Assistive technology: the material provided here includes no documentation or test results on how screen readers handle spaCy's built-in visualizations or particular export formats. Do not assume they are accessible. For shared reports, include a plain-text or simple table version of any visual output and test it with the assistive technology your readers actually use.

Provide a plain-text equivalent whenever the audience is not working in code: reviewers checking annotations, stakeholders reading a summary, or anyone using a screen reader. Short excerpts of the original sentences, with the relevant tokens and their attributes described in prose, carry the meaning more reliably than raw attribute dumps.

Evidence gaps

This review relies on spaCy's documented design: non-destructive tokenization, the hash-versus-string attribute convention, and the split between lexical and predicted attributes. It does not include measured accuracy figures for any trained pipeline. It also does not include tested behavior for emoji or for styled Unicode input in a specific version, or accessibility testing of visual outputs. Verify those points against your own pipeline, version and destination before depending on them.