AI Glossary / AI and machine learning / Beginner
Text span
Definition
A text span is a specific continuous portion of text identified by its start and end positions. It lets a system point to the exact characters or tokens associated with an extracted phrase, label or answer.
What it means
An application might identify a company name inside an email or highlight the phrase that answers a question. Returning only the extracted words can be ambiguous when the same phrase occurs several times. A span also identifies where those words occur.
Positions need a defined convention. Some systems count characters, others count tokens or bytes. Some include the end position; others use an exclusive end that points just after the selected text.
These details are easy to overlook because the highlighted words look obvious to a reader. They become important when annotations move between tools, when text includes unusual characters or when the underlying document changes.
For business readers, spans connect an AI output to evidence. They can make extraction easier to review, provided the displayed highlight really corresponds to the source version being used.
How it works
The system first stores a reference text and defines its indexing rules. An extraction or annotation process identifies the start and end of the relevant portion.
The resulting record may include the span, a label and the document identifier. For example, a named-entity system may associate an organization label with a specific range of characters.
When the result is displayed, the application applies those positions to the same text representation. If punctuation, whitespace or encoding has changed, the stored offsets may no longer locate the intended phrase.
Quality checks therefore test both semantic correctness and alignment. A model may identify the right organization but include an extra word, omit part of the name or point to the wrong repeated occurrence. Those are distinct errors with different effects on downstream use.
Three practical examples
- Document review: highlight the exact passage supporting an extracted renewal date so a reviewer can inspect its context.
- Customer support: mark the product name in a message rather than returning an unlocated string.
- Search assistance: show a relevant answer passage within the source document, preserving the surrounding text for verification.
Think of it this way
Think of placing a transparent marker over a phrase on a printed page. The marker tells the reader both what the phrase says and where it appears.
The analogy has a limit. Digital offsets depend on an exact representation of the text. Adding one character near the beginning can shift later positions, whereas a physical mark moves with the printed page. Version control and alignment checks prevent apparently precise highlights from becoming misleading.
Worked example
Using an exclusive end position
Take the invented text Send blue box. Under zero-based character indexing, Send occupies positions zero through three, the first space is position four, and blue occupies positions five through eight.
With an exclusive end convention, the span for blue is start five, end nine. Its length is nine minus five, or four characters. The end position points to the following space, which is not included in the selected slice.
With an inclusive end convention, the same phrase would be represented as five through eight. Both can describe the same text if the convention is explicit.
If another system treats the exclusive end nine as inclusive, it will include an unwanted space. The example illustrates why exchanging two numbers without their indexing rules is insufficient.
Illustrative case study
A fictional document-processing team stores character spans for supplier names. A later cleaning step replaces repeated spaces and changes line breaks before displaying the text. The extracted names remain correct in a table, but some highlights point to neighboring words.
The team preserves the original text version and either displays spans against that version or maintains a tested mapping to the cleaned version. It adds checks that the text selected by each span matches the expected extracted phrase.
The lesson is that extraction and presentation must agree on the source representation. A highlight can look authoritative while pointing to the wrong evidence if its offsets have become stale.
Common misconceptions and mistakes
- A span is just the extracted words. It also specifies their location under an indexing convention.
- Character positions and token positions are interchangeable. Tokenization can split or combine text differently, so conversion requires alignment information.
- Any edit leaves old spans valid. Changes before or within a span can invalidate its positions or meaning.
Business use
Text spans are useful in document extraction, annotation, search and evidence review. They help users inspect where an answer came from and correct errors precisely.
Ask whether the system retains the source version, offset convention and surrounding context. Test repeated phrases, accented characters, emoji and line breaks. The aim is dependable evidence navigation, not merely a visually attractive highlight. For audited workflows, preserve the relationship between the output and the exact source text reviewed.
People also ask
Can a span cover several words?
Yes. It can identify any continuous region allowed by the representation, including a sentence or paragraph.
Can one entity occupy several separate spans?
Some annotation systems support discontinuous mentions as multiple spans, but one ordinary span describes a continuous interval.
Is a text span proof that the extracted claim is correct?
No. It identifies a location. A reviewer must still decide whether the passage supports the claim and whether relevant context was omitted.
Check your understanding
A system stores start five and end nine using an exclusive end convention. How many indexed elements are selected?
Answer: Four. Subtract the start from the end. The element at position nine is outside the selected span.
Related terms
- Named entity recognition
- Information extraction
- Token
- annotation
- character offset
- provenance
Learn next
Read information extraction and token. Inspect one highlighted result and verify its source version, indexing units and end-position convention before moving annotations between tools.
More in AI and machine learning
- Termination condition - A termination condition is a rule that determines when a process stops.
- Test set - A test set is a collection of examples reserved for assessing a model after its development choices have been made.
- Text classification - Text classification assigns one or more categories to a piece of text.
- Three-factor learning - Three-factor learning is a family of synaptic learning rules in which changes depend on presynaptic activity, postsynaptic activity and an additional...
- Threshold (for decision trees) - A threshold in a decision tree is a value used in a comparison at a branching point.
- Time travel (for features) - Time travel for features is the ability to retrieve historical versions of model-input values.
Sources
Google, Machine Learning Glossary, text span: https://developers.google.com/machine-learning/glossary#text_span. Core terminology consulted. The example deliberately states an exclusive-end convention to avoid ambiguity; all scenarios are original.
Previous: Text simplification Next: Text-to-image personalization