liveBook · Manning

Relation extraction

As explained in Graph Algorithms for Data Science

Relation extraction identifies semantic relationships expressed between entities in text.

Relation extraction identifies semantic relationships between entities in unstructured text. Its usual output is a triple: a head entity, a relationship type, and a tail entity. For example, “Google acquired YouTube” becomes Google, ACQUIRED, YouTube. These triples can directly form graph relationships, while values such as dates may sometimes fit better as node properties. section 12.0 section 12.3

It is a step in an information-extraction pipeline that turns text into graph-ready facts. Coreference resolution helps connect references to the same entity, named entity recognition identifies entity spans and types, and entity linking can attach entities to knowledge-base identifiers for later enrichment. section 12.0 section 12.6

Two main approaches extract relations:

  • Rule-based extraction applies predefined heuristics, often using part-of-speech tags and dependency parses. A simple rule can connect a verb’s subject and object, but practical rules quickly become more complex. section 12.3
  • Deep-learning extraction uses training data to identify relationships. Models may work within one sentence or across a document. section 12.3
  • End-to-end extraction detects entities and their relationships in one model, combining work otherwise handled by separate entity and relation stages. section 12.4.3 section 12.6

Extracting company relationships

A practical pipeline can process text about Apple Inc. and return facts such as Apple Inc—founded by→Steve Jobs, Steve Wozniak, and Ronald Wayne. It can also return employer, member-of, and part-of relationships. Results require review: the model may hallucinate relationships that are not stated in the input. section 12.4 section 12.4.3

Listing 12.9 Extracting relationships from text
doc = nlp(ctext)
for value, rel_dict in doc._.rel.items():
   print(rel_dict)

After loading a SpaCy pipeline with the REBEL component, process the text and iterate over doc._.rel.items() to retrieve extracted relation records. section 12.4.3

For an initial implementation, REBEL can run as a SpaCy component. The pipeline processes text once, then exposes relation records containing a relation label plus head and tail spans. Its output is useful for constructing a graph, but domain fit matters because named entity recognition and relation extraction depend heavily on the use case. section 12.4.3 section 12.6

How Graph Algorithms for Data Science covers it

How deep it goes
Defines triples, compares rule-based and deep-learning approaches, and implements end-to-end extraction without training a custom model.
Examples
Uses Google acquiring YouTube and Apple Inc. founding, employment, acquisition, and product text to inspect extracted triples.
What it assumes
Starts from unstructured text and plain graph triples; custom model training is not required for the initial pipeline.
What you can do after
Apply it via SpaCy and REBEL to extract relation records from text, inspect results, and construct graph relationships.
How it connects
Connects information extraction with coreference resolution, named entity recognition, entity linking, knowledge graphs, and labeled-property graphs.

Also explained in

Compare how 3 books explain relation extraction →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Graph Algorithms for Data Science. The section links point to the parts of the book it draws on.