Sub topic 1
What Information Extraction Covers
Information extraction turns free-form text into structured data. A document may contain useful facts, but those facts are mixed with grammar, formatting, and irrelevant details. An extraction system identifies the facts you need and returns them in a predictable form.
This chapter assumes you know basic Python, JSON, language models, and introductory precision, recall, and F1. Later chapters use these ideas to compare prompting with fine-tuned models.
Prerequisites
You should be able to:
- Read a JSON object and distinguish strings, numbers, arrays, and null values.
- Describe a language model as a system that predicts text from an input.
- Explain that precision measures the correctness of predictions, while recall measures how many relevant facts were found.
- Write and run a small Python program.
The main task types
Information extraction usually focuses on one or more of these tasks:
| Task | What it finds | Example result |
|---|---|---|
| Named-entity recognition | Mentions of people, organizations, places, dates, and other entity types | Paris → location |
| Relation extraction | Connections between entities | Angela Merkel → visited → Paris |
| Key-value extraction | Fields and their values from a document | total → 120.50 |
Named-entity recognition, or NER, labels a span of text. A span is a continuous range of characters or tokens. In the sentence “Acme paid 120 euros,” an NER system might label “Acme” as an organization and “120 euros” as a money amount.
Relation extraction adds meaning between entities. For example, “Maya works for Acme” contains a person entity, an organization entity, and an employment relation from Maya to Acme.
Key-value extraction is common in invoices, forms, receipts, and support messages. The system might return a JSON object with fields such as vendor, invoice number, total, and currency. A field can be absent, so the schema should define whether its value is null, an empty string, or omitted.
A single document can contain several tasks
Consider this sentence:
Acme issued invoice INV-1042 to Northwind on 2026-11-29 for EUR 120.50.Possible outputs include:
- Entities: Acme as a vendor, Northwind as a customer, INV-1042 as an invoice number, and EUR 120.50 as an amount.
- Relations: Acme issued INV-1042, and the invoice was issued to Northwind.
- Fields: vendor = Acme, invoice_id = INV-1042, date = 2026-11-29, total = 120.50, currency = EUR.
These outputs describe the same text at different levels. NER identifies pieces. Relation extraction connects pieces. Key-value extraction organizes selected facts for an application.
Define the extraction boundary
Before choosing a model, state exactly what counts as an answer. “Extract the important information” is too vague to annotate consistently or evaluate fairly.
Specify:
- The entity and field names.
- Whether the output preserves the original text or normalizes it.
- The allowed data types.
- What to do when information is missing.
- Whether overlapping or nested entities are allowed.
- Which relations are valid and which argument order they use.
For example, an amount might be stored as the original string “EUR 120.50” or as separate values:
{
"total": 120.5,
"currency": "EUR"
}The second representation is easier for calculations, but it requires rules for commas, decimal points, currency symbols, and ambiguous formats.
Extraction is not the same as summarization
A summary preserves the main idea of a document in natural language. Extraction returns selected facts in a fixed structure. A summary may say that an invoice requests payment. An extractor should return the exact total, currency, vendor, and invoice identifier.
This distinction matters when using a large language model. A fluent answer can sound reasonable while omitting a required field or inventing a value. The extraction contract must therefore be explicit, and later evaluation must compare the returned facts with labeled examples.
Exercise
A message says, “Jordan will meet Priya in Berlin on Friday.” Name one possible entity-extraction output and one possible relation-extraction output.
Show answer
Entity output: Jordan = person, Priya = person, Berlin = location, Friday = date. Relation output: Jordan meets Priya.