Knowledge Extraction from Text: NER, Relation Extraction, and Knowledge Graph Construction

Knowledge Extraction (KE) from unstructured text is the core subfield of Natural Language Processing (NLP) and Information Extraction (IE) focused on transforming unstructured natural language corpora into structured, queryable knowledge representations—such as relational tables, property graphs, and formal ontologies.

This article details the end-to-end knowledge extraction pipeline: Named Entity Recognition (NER), Relation Extraction (RE), Coreference Resolution, Entity Linking, and modern LLM-driven structured extraction architectures.


1. The Information Extraction Pipeline Architecture

Transforming raw unstructured text into structured Knowledge Graph triples (h, r, t) requires a multi-stage sequential or joint extraction pipeline:

+-------------------------------------------------------------------------------+
|                       INFORMATION EXTRACTION PIPELINE                         |
+-------------------------------------------------------------------------------+
| Raw Document Corpus ("Albert Einstein was born in Ulm and developed GR.")    |
|                                     |                                         |
|                                     v                                         |
| [ Named Entity Recognition (NER) ] ---> Identifies [Albert Einstein (PER)],   |
|                                         [Ulm (LOC)], [General Relativity (THY)]|
|                                     |                                         |
|                                     v                                         |
| [ Coreference Resolution ] -----------> Resolves "he", "the physicist" -> AE  |
|                                     |                                         |
|                                     v                                         |
| [ Entity Linking / Wikification ] ----> Maps [Albert Einstein] -> Q937        |
|                                         Maps [Ulm] -> Q3012                   |
|                                     |                                         |
|                                     v                                         |
| [ Relation Extraction (RE) ] ---------> Extracts:                             |
|                                         (Albert Einstein, bornIn, Ulm)        |
|                                         (Albert Einstein, developed, GenRel)  |
|                                     |                                         |
|                                     v                                         |
| [ Knowledge Graph Materialization & Canonical Entity Resolution ]             |
+-------------------------------------------------------------------------------+

2. Named Entity Recognition (NER)

Named Entity Recognition identifies and classifies spans of text into predefined entity categories (e.g., Person, Organization, Location, Chemical, Disease).

Sequence Tagging and the BIO Scheme

In token-level sequence classification, entity boundaries are demarcated using the BIO (Begin, Inside, Outside) or BIOES scheme:

Token Sequence Example:
Token:   [ Albert ]   [ Einstein ]   [ published ]   [ in ]   [ Berlin ]
Tag:      B-PER        I-PER          O               O        B-LOC

Neural Sequence Labeling: BiLSTM-CRF vs. Transformer Encoders

  1. BiLSTM-CRF: Passes token embeddings through a Bidirectional LSTM to capture left-to-right and right-to-left contextual representations, followed by a Conditional Random Field (CRF) layer that enforces global sequence transition constraints (e.g., preventing I-PER directly following O). The score of a sequence of tags \mathbf{y} = (y_1, \dots, y_T) given input tokens \mathbf{x} is:
    s(\mathbf{x}, \mathbf{y}) = \sum_{t=1}^T P_{t, y_t} + \sum_{t=1}^{T+1} A_{y_{t-1}, y_t}

    where P is the emission matrix from the BiLSTM and A is the learnable transition matrix.

  2. Transformer-Based Token Classification (e.g., RoBERTa, DeBERTa): Applies linear projection directly over token hidden states H \in \mathbb{R}^{T \times D} with cross-entropy loss.

3. Relation Extraction (RE) and Entity Linking

Relation Extraction determines semantic relationships between identified entity pairs within a sentence or document context.

Relation Extraction Classification Framework:
Input: "Subbarow discovered tetracycline at Lederle Laboratories in 1948."
Entities: E1 = [Subbarow], E2 = [tetracycline], E3 = [Lederle Laboratories]

Candidate Pair 1: (E1, E2) ---> [ RE Model ] ---> relation: DISCOVERED
Candidate Pair 2: (E1, E3) ---> [ RE Model ] ---> relation: EMPLOYED_BY
Candidate Pair 3: (E2, E3) ---> [ RE Model ] ---> relation: DEVELOPED_AT

Classification Paradigms

  1. Span-Based Cross-Encoders: Formulates relation extraction as classifying the concatenated sequence: [CLS] Text with [E1] Entity 1 [/E1] and [E2] Entity 2 [/E2] [SEP]
  2. Joint Entity and Relation Extraction: Avoids error propagation from pipeline cascades by training a unified model to predict entities and directed relational edges simultaneously (e.g., table filling or graph parsing).

Entity Linking (Wikification)

Raw textual mentions are often ambiguous (e.g., "Apple" as fruit vs. corporation). Entity Linking resolves ambiguous strings to unique canonical identifiers in a knowledge base (e.g., Wikidata ID Q312 for Apple Inc.):

\hat{e} = \arg\max_{e \in \mathcal{K}} \left[ \operatorname{Prior}(m \to e) + \operatorname{CosineSimilarity}(\mathbf{c}_{\text{text}}, \mathbf{e}_{\text{description}}) \right]

Modern dense entity retrieval uses dual-encoder architectures (e.g., BLINK) to retrieve candidate entities using FAISS index similarity, followed by a cross-encoder reranker.


4. Modern LLM-Driven Information Extraction

Large Language Models (LLMs) enable high-precision zero-shot and few-shot knowledge extraction without requiring extensive supervised token-level annotations.

LLM Structured Extraction Workflow:
Unstructured Input Text
          |
  [ Prompt + Few-Shot Examples + Pydantic / JSON Schema Definition ]
          |
          v
  [ Constrained Decoding Engine (Outlines / Guidance / SGLang) ]
  - Enforces Context-Free Grammar (CFG) at token generation level
  - Guarantees 100% valid JSON matching the schema
          |
          v
Validated Pydantic Graph Objects (Entities, Attributes, Relations)
from pydantic import BaseModel, Field
from typing import List

class ExtractedEntity(BaseModel):
    name: str = Field(description="Canonical name of the entity")
    category: str = Field(description="Entity type: PERSON, ORG, CONCEPT, EVENT")
    aliases: List[str] = Field(default_factory=list)

class ExtractedRelation(BaseModel):
    subject: str = Field(description="Subject entity name")
    predicate: str = Field(description="Normalized relationship predicate")
    object: str = Field(description="Object entity name")
    confidence: float = Field(ge=0.0, le=1.0)

class KnowledgeExtractionResult(BaseModel):
    entities: List[ExtractedEntity]
    relations: List[ExtractedRelation]

Grammar-Constrained Decoding

By constructing a deterministic finite automaton (DFA) from a JSON schema, modern inference engines mask out invalid vocabulary tokens at each generation step, guaranteeing that the model produces syntactically and semantically valid structured outputs.


5. Knowledge Graph Fusion and Canonicalization

Raw extractions across thousands of documents require entity deduplication and graph canonicalization before ingestion into production triple stores:

  1. Entity Resolution (Record Linkage): Matches duplicate node mentions using graph topological similarity and embedding distance.
  2. Schema Alignment and Ontology Mapping: Maps heterogeneous predicates (e.g., born_in, birthPlace, native_of) to standardized ontology object properties (dbo:birthPlace).
  3. Knowledge Graph Triplet Scoring: Validates extracted edges against pre-existing knowledge base constraints (e.g., domain and range typing: \operatorname{domain}(\text{bornIn}) \subseteq \text{Person}).

6. Information Extraction Methods Summary

+---------------------------+-----------------------------------+------------------------+
| Technique                 | Strengths                         | Limitations            |
+---------------------------+-----------------------------------+------------------------+
| Rule-Based (Regex/SpaCy)  | Deterministic, zero latency, cheap| Brittle to syntax shift|
| Supervised BiLSTM/BERT    | High speed, domain-tuned precision| Requires labeled data  |
| Dual-Encoder (BLINK)      | Millions of candidate entities    | Requires entity catalog|
| LLM Zero-Shot Extraction  | High semantic nuance, flexible    | High token cost, slower|
| LLM + Constrained Decode  | Guaranteed schema compliance      | Requires GPU serving   |
+---------------------------+-----------------------------------+------------------------+

References

  1. Jurafsky, D., & Martin, J. H. (2024). Speech and Language Processing (3rd ed. draft). Stanford University.
  2. Lample, G., et al. (2016). Neural Architectures for Named Entity Recognition. NAACL-HLT.
  3. Wu, L., et al. (2020). Scalable Zero-shot Entity Linking with Prior-informed Dual Encoders. EMNLP.
  4. Willard, B. T., & Louf, R. (2023). Efficient Guided Generation for Large Language Models. arXiv preprint.
  5. Hogan, A., et al. (2021). Knowledge Graphs. ACM Computing Surveys, 54(4), 1–37.