liveBook · Manning

Named entity recognition

As explained in Natural Language Processing in Action, Second Edition

Named entity recognition identifies spans of text that refer to entities such as people, places, organizations, dates, or locations and assigns them entity categories.

Named entity recognition (NER) finds spans referring to people, places, organizations, dates, locations, and other information, then assigns each span an entity category. It turns unstructured text into pieces that can populate a knowledge graph, where entities become nodes and relations become edges. section 11.4 section 11.0

NER can use two complementary approaches:

  • Pattern matching, including regular expressions, can be especially precise for GPS locations, dates, prices, and numbers. section 11.4
  • Neural systems use surrounding context to recognize boundaries and categories; common architectures include CNNs, bidirectional transformers, and bidirectional LSTMs with CRFs. section 11.4.2
  • Segmentation determines whether text such as “New York” forms one entity, while categorization distinguishes context-dependent meanings such as person, location, organization, or sports team. section 11.4.2

Extract entities with spaCy

Run a spaCy model over an article, then inspect the document’s entities: `nlp = spacy.load('en_core_web_lg')`; `doc = nlp(text)`; `doc.ents[:6]` can return entities such as `Timnit Gebru`, `Amharic`, `13`, `May 1983`, `Ethiopian`, and `Black in AI`. Each token also exposes `ent_type_`, allowing the extracted span’s category to be examined alongside part-of-speech and dependency information. section 11.4.2

>>> doc = nlp(text)    #1
>>> doc.ents[:6]               #2
(Timnit Gebru, Amharic, 13, May 1983, Ethiopian, Black in AI)

Inspect the spaCy output listing to see extracted entity spans in context. section 11.4.2

NER is a foundation for information extraction: combine it with coreference resolution and relation extraction to build larger knowledge graphs or check facts generated by language models. Part-of-speech tagging supports recognition, while dependency parsing helps connect entities through sentence relations. section 11.3 section 11.4.2

How Natural Language Processing in Action, Second Edition covers it

How deep it goes
Explains spans, categories, pattern matching, neural architectures, ambiguity, and spaCy inspection, but defers model construction.
Examples
Uses a Timnit Gebru Wikipedia article, spaCy entity output, and ambiguous examples including New York and Washington.
What it assumes
Assumes basic NLP familiarity and connects recognition to part-of-speech tagging, while using spaCy without requiring neural-network construction.
What you can do after
Apply NER via spaCy, inspect extracted spans and categories, and prepare entities for relation extraction or knowledge-graph construction.
How it connects
Connects named entity recognition with part-of-speech tagging, dependency parsing, coreference resolution, relation extraction, and knowledge graphs.

Also explained in

Compare how 4 books explain named entity recognition →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Natural Language Processing in Action, Second Edition. The section links point to the parts of the book it draws on.