Extract facts from messy documents
Turn support messages into structured fields with spans, rules, validation and human review.
- Identify exact text spans for useful fields in a document
- Choose a rule, a statistical model or a combination for extraction
- Validate extracted values and handle uncertain or missing fields
A support agent receives “Please check order ORD-1042. I paid on Tuesday; reply to maya@example.com.” A useful system turns the text into fields: order ID, date and contact address. Information extraction is more than spotting a word: you must keep the exact span, assign the right field, validate its format and decide what to do when it is missing.
Try it
Up to 15 XPAnnotate a support message
Select a field type and mark only the tokens that contain the field. Leave ordinary words untagged. In a real project, record start and end offsets too so reviewers can see the evidence in the original message.
1. Choose a tag
2. Click words to tag them (click again to clear)
Rules are a useful baseline
If order IDs always follow ORD- plus four digits, a regular expression is cheap and explainable. It can still mistake a tracking number for an order number, and it will miss a new format. A statistical entity model helps when context matters and examples are labeled. Many systems combine both: a model proposes a span, rules validate it, and uncertain cases go to a person.
1import re
2text = 'Check ord-1042, not PREORD-9999 or ORD-12345.'
3pattern = re.compile(r'\bORD-\d{4}\b', re.IGNORECASE)
4print([match.group().upper() for match in pattern.finditer(text)])['ORD-1042']
From a demo to a workflow
A production extraction pipeline can follow six steps:
- Receive a document only with the permissions needed for the task.
- Preserve the original text and offsets so people can inspect evidence.
- Extract candidate spans with a rule or an entity model.
- Normalize and validate values (for example, uppercase an order ID).
- Ask for review when two IDs conflict or a required field is absent.
- Store only the fields and source references needed for the workflow; protect contact details.
In invoice processing, the same pattern can extract invoice numbers, totals and due dates. In healthcare or legal work, the review and privacy requirements are even higher. spaCy’s rule-matching guide explains when patterns, models and combinations are useful.
Try it
Up to 15 XPChoose the extraction method
Decide which approach fits each field. A combined approach lets a model suggest a span while a rule checks its format.
“Order IDs always start ORD- and have four digits.”
“Find the person referred to by “she” across a paragraph.”
“Find an invoice total in varied layouts, then verify it is a valid currency amount.”
“Identify every email address in a support note.”
Key takeaways
Extraction maps spans in raw text to fields a system can use.
Stable formats favor rules; ambiguous meaning needs context and often labeled examples.
Validate values, keep source evidence and review uncertain cases before acting.
Lesson quiz
5 questions · pass with 4 correct · up to 50 XP
Passing this quiz completes the lesson and keeps your streak going. Questions you miss come back in review sessions later.
Practice: apply NLP with Python
Try each text-processing idea in Python, run it against sample inputs, and use the results to see where the method works or falls short.
Extract and normalize order IDs
Read all input lines. Find IDs matching ORD- followed by exactly four digits, ignoring letter case. Print each distinct ID in uppercase, in first-seen order, one per line. Do not match the ID inside a longer word or a five-digit ID. If none are found, print none.
- Repeated and lowercase IDs
- Reject lookalikes
- No IDs
Python runs in a sandboxed browser worker with a 60 second time limit. Its runtime loads from the Pyodide CDN; your code stays in this browser.
Questions about this lesson
Stuck? Ask. Figured something out? Share it. Explaining is one of the best ways to learn.
Loading posts…