liveBook · Manning

spaCy

As explained in AI-Powered Search

spaCy is an open-source Python library for natural language processing that provides pretrained models and linguistic analysis pipelines.

spaCy is an open-source Python NLP library for turning text into structured linguistic data. Its pretrained pipelines support part-of-speech tagging, dependency parsing, text categorization, and named-entity recognition. section 5.3.1

A spaCy pipeline parses documents into sentences, tokens, linguistic labels, dependencies, phrases, and sometimes coreference information. Application code can then apply rules to those outputs—for example, mapping subjects, verbs, and objects into RDF triples for a knowledge graph. section 5.3.1

Common implementation patterns include:

  • Extract relationships from sentence structure, then prune or merge noisy verb-based relationships. section 5.3.1
  • Use Matcher patterns to collect noun and verb phrases for vocabulary, autocomplete, or semantic-search preparation. section 13.5.1
  • Process corpora with nlp.pipe in parallel batches and filter concepts by frequency to reduce rare-term noise. section 13.5.1

From sentence to graph fact

For “Colin attends Riverside High School,” dependency and part-of-speech analysis can support the triple ("Colin", "attends", "Riverside High School"). Similar processing extracts facts such as ("Companies", "employ", "Data Scientists"). section 5.3.1

Listing 5.1 Extracting relationships and resolving co-references
def extract_relationships(text, lang_model, coref_model):
  resolved_text = resolve_coreferences(text, coref_model)  #1
  sentences = get_sentences(resolved_text, lang_model)  #2
  return resolve_facts(sentences, lang_model) #3

text = """
Data Scientists build machine learning models. They also write code.
Companies employ Data Scientists.
Software Engineers also write code. Companies employ Software Engineers.
"""
lang_model = spacy.load("en_core_web_sm")
coref_model = spacy.load("en_coreference_web_trf")  #4
graph = extract_relationships(text, lang_model, coref_model)
print(graph)

The pipeline resolves coreferences, obtains sentences from the language model, and resolves facts into graph-ready relationships. section 5.3.1

How AI-Powered Search covers it

How deep it goes
Explains pipeline outputs and implementation patterns, but stops short of detailing model architectures or training procedures.
Examples
Uses school-attendance and employment sentences, relationship triples, Matcher patterns, corpus frequencies, and batched document processing.
What it assumes
Assumes basic Python and text-processing familiarity while demonstrating model loading, pattern matching, and document batching.
What you can do after
Builds Python pipelines that extract linguistic concepts, relationships, graph facts, and filtered vocabulary from text.
How it connects
Connects NLP pipelines with part-of-speech tagging, dependency parsing, coreference resolution, RDF, knowledge graphs, and semantic search.

Also explained in

Compare how 5 books explain spaCy →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of AI-Powered Search. The section links point to the parts of the book it draws on.