An extraction label names a half-open character span in a specific text revision, with an explicit policy for overlap and normalization.
Entity spans: align annotations to the original text
Store coordinates with identity
A ticket might mention an invoice ID, product and date. Store start and end character offsets against the exact raw text revision that annotators saw. If a later normalization collapses spaces, old offsets may point to different characters. Save the selected substring and a text hash beside offsets to catch drift. Corpus identity] makes that pairing stable.
Define overlap semantics
A product code may appear inside a longer order reference. Decide whether overlapping spans are allowed and whether nested labels are meaningful. If a model or library supports only non-overlapping entities, do not quietly drop valid nested annotations; change the representation or define a priority policy. State whether offsets count Unicode code points, bytes or another unit at every API boundary.
Align without guessing
Token-based models need character spans mapped to token spans. A strict mapping may reject an annotation cutting through a token. A permissive expansion can change the labeled text. Count rejected alignments and inspect them before training. Tokenization changes] can alter these counts even when raw documents are unchanged.
Evaluate exact and partial errors
Exact span match is strict; a prediction missing one character can be wrong even when its label looks right. Report exact boundary errors, wrong labels and missed spans separately. Add fixtures for repeated identical IDs in one ticket, punctuation next to an ID and a corrected ticket revision. A raw substring check prevents stale offsets from passing silently.
Implementation
def validate_span(ticket_text, start_char, end_char, selected_text):
if not (0 <= start_char < end_char <= len(ticket_text)):
raise ValueError("span outside ticket")
observed = ticket_text[start_char:end_char]
if observed != selected_text:
raise ValueError("annotation offsets no longer match text")
return {"start": start_char, "end": end_char, "text": observed}Performance and operating cost
One span validation is O(L) for substring length L; validating S spans costs the total selected length. Token alignment adds tokenizer work over document length and storage for offset maps.
Common Mistakes
- Do not reuse offsets after changing text normalization.
- Do not silently expand misaligned spans.
- Do not assume repeated strings identify the intended occurrence.
Read next
- Unicode and tokenization: preserve meaning at the text boundary
- Text corpus contracts: identity, label timing and annotation rules
- Text inference: package tokenizer, labels and reject paths
- Reproducible analysis snapshots: pin data, code and cutoff together
Continue the workflow: BIO labels and subword alignment for entity extraction.
Continue the workflow: Document summaries with sentence-level evidence contracts.
Continue the workflow: Coreference chains: track mentions without guessing identity.
Continue the workflow: Aspect sentiment: bind opinions to targets and negation.
Continue the workflow: Extractive QA: answer spans, context windows and no-answer cases.
Continue the workflow: Grammar correction: edit spans without changing protected meaning.
Continue the workflow: Keyphrase candidates: spans, nesting and document context.
Continue the workflow: OCR text identity: geometry, reading order and offsets.
Continue the workflow: Time expressions: anchors, zones and unresolved dates.
Continue the workflow: Speech transcripts: segments, recognition errors and entity risk.
Continue the workflow: Abbreviations: definition scope, collisions and unknown forms.
Continue the workflow: Unicode normalization: search keys without losing source offsets.
Continue the workflow: Schema-bound extraction: typed fields and exact source spans.
