Once named entities have been extracted from text (via NER), the next step in knowledge graph construction is relation extraction (RE): identifying typed, directed relationships between entity pairs. Given a sentence like “Marie Curie was born in Warsaw”, an RE system should output the triple (Marie Curie, born_in, Warsaw). These triples become the edges that connect entity nodes in a knowledge graph.
Relation extraction has evolved from hand-crafted pattern matching and distant supervision to modern neural approaches that achieve strong zero-shot generalization. Three dominant paradigms exist today: encoder-based classifiers (fine-tuned BERT variants that classify entity pairs), seq2seq generative models (like REBEL, which outputs triples as text), and zero-shot matching models (like GLiREL, the relation-extraction companion to GLiNER). LLM prompting adds a fourth option for prototyping and low-volume extraction.
For production knowledge graph pipelines, the choice hinges on whether you have labeled training data (use an encoder classifier), need to handle open-ended relation types (use GLiREL or LLM prompting), or want a pre-trained model covering 200+ Wikipedia relations out of the box (use REBEL).
Formally, given a sentence s and two entity mentions e1 and e2 within it, relation extraction predicts a relation label r from a predefined set (or “no relation”). The output is a triple (e1, r, e2). In the end-to-end setting (no pre-identified entities), the model must also detect entity spans — combining NER and RE in a single pass.
In a pipeline approach, NER runs first to extract entities, then RE classifies relationships between all entity pairs. This is modular but propagates NER errors. In an end-to-end approach (e.g., REBEL), a single model jointly extracts entities and relations. End-to-end avoids error propagation but is harder to debug and customize per stage.
The most common supervised approach fine-tunes a pre-trained encoder (BERT, RoBERTa, DeBERTa) for relation classification. The input is the sentence with special markers around entity mentions:
# Input format with entity markers
"[E1] Marie Curie [/E1] was born in [E2] Warsaw [/E2]"
# The model outputs: born_in (confidence: 0.96)
The [CLS] token representation (or pooled entity representations) is fed through a classification head. This approach achieves high accuracy when labeled training data is available, but each new relation type requires labeled examples and retraining.
REBEL (Relation Extraction By End-to-end Language generation, Cabot & Navigli, EMNLP 2021) takes a fundamentally different approach: it fine-tunes BART (a seq2seq model) to generate relation triples as linearized text.
# Input: "Marie Curie was born in Warsaw and studied at the University of Paris."
# Output: "<triplet> Marie Curie <subj> Warsaw <obj> place of birth
# <triplet> Marie Curie <subj> University of Paris <obj> educated at"
REBEL is trained on a dataset derived from Wikipedia and Wikidata, covering 220+ relation types. Because it generates triples autoregressively, it can extract multiple triples from a single sentence naturally. The pre-trained Babelscape/rebel-large model on Hugging Face is a popular starting point for Wikipedia-domain knowledge graph construction.
GLiREL (Generalist Lightweight model for zero-shot Relation Extraction, Boylan et al., NAACL 2025) extends the GLiNER paradigm to relations. Like GLiNER, it uses a bidirectional encoder (DeBERTa V3-large) to jointly encode the input text and a set of candidate relation labels. It then computes matching scores between entity-pair representations and relation-label representations.
The most practical zero-shot extraction pipeline today combines GLiNER (for entity extraction) with GLiREL (for relation extraction). Both use the same architectural paradigm — bidirectional encoding with matching-based classification — and both generalize to arbitrary label sets at inference time. This gives you a complete NER + RE pipeline without any task-specific training data.
Large language models can extract relations via few-shot prompting. This is the most flexible approach — you describe the desired relations in natural language — but also the most expensive and least reliable for production use. LLMs hallucinate relations, struggle with complex multi-hop extraction, and are 10–100× slower than encoder-based models.
# LLM prompt for relation extraction
prompt = """Extract (subject, relation, object) triples from this text.
Relations: works_for, located_in, born_in, founded
Text: "Elon Musk founded SpaceX in Hawthorne, California."
Triples:"""
# LLM output: (Elon Musk, founded, SpaceX), (SpaceX, located_in, Hawthorne)
LLM prompting is best suited for prototyping, low-volume extraction, or as a fallback for relation types that neither REBEL nor GLiREL handle well.
A persistent challenge in RE is obtaining labeled training data. Distant supervision addresses this by aligning a knowledge base (e.g., Wikidata) with text: if a KB contains (Marie Curie, born_in, Warsaw) and a sentence mentions both entities, that sentence is labeled with the born_in relation. This is noisy (some sentences mentioning both entities may not express the relation) but generates large-scale training data cheaply. GLiREL also contributes a protocol for synthetically generating diverse relation-labeled datasets.
The canonical application: process a corpus of documents through an NER + RE pipeline to automatically populate a knowledge graph. In a typical setup:
In a GraphRAG system, relation extraction enhances retrieval by building a structured knowledge layer over unstructured documents. When a user asks a multi-hop question (“Which drugs interact with medications prescribed for condition X?”), the graph’s relational structure enables traversal-based retrieval that vector similarity alone cannot achieve.
Relation extraction is heavily used in biomedical NLP to extract drug-drug interactions, gene-disease associations, and protein-protein interactions from scientific papers. Models like BioBERT fine-tuned for RE, or zero-shot approaches like GLiREL with biomedical relation labels, enable automated literature curation at scale.
Business intelligence teams use RE to extract organizational relationships (acquires, partners_with, competes_with, supplies_to) from news articles and SEC filings, building competitive landscape graphs that update automatically as new documents arrive.