liveBook · Manning

spaCy

As explained in Natural Language Processing in Action, Second Edition

spaCy is an open-source software library for advanced natural-language processing, including tokenization and syntactic analysis.

spaCy is an open-source natural-language-processing library that turns text into structured documents. Its tokenizer splits words and punctuation while a language model adds sentence boundaries, part-of-speech tags, lemmas, and syntax-tree relationships. section 2.1.4

A typical workflow loads an English model, processes text into a Doc object, and inspects its tokens. The same document exposes sentences, entities, token attributes, dependency roles, and fine-grained grammatical tags. section 2.1.4 section 11.4.2

>>> import spacy                             #1
>>> spacy.cli.download('en_core_web_sm')    #2
>>> nlp = spacy.load('en_core_web_sm')    #3
>>> doc = nlp(texts[-1])
>>> type(doc)
spacy.tokens.doc.Doc

>>> tokens = [tok.text for tok in doc]
>>> tokens[:9]
['There', "'s", 'no', 'such', 'thing', 'as', 'survival', 'of', 'the']

>>> tokens[9:17]
['fittest', '.', 'Survival', 'of', 'the', 'most', 'adequate', ',']

Load an English model, process text, and inspect the resulting Doc and token sequence. section 2.1.4

Inspecting entities and syntax

After processing text, doc.ents returns detected named entities. Token attributes can be collected into a table containing the original token, POS tag, entity type, dependency role, and children. For example, a token can be identified as a proper noun, a PERSON entity, and a passive nominal subject. displaCy can render dependency relationships as an SVG file, a browser view, or inline notebook output. section 11.4.2 section 2.1.4

spaCy’s breadth has a cost. Processing roughly 160,000 characters took about 4.67 seconds, or 7,000 words per second, while disabling pipeline components reduced the measured time to about 199 milliseconds. When linguistic annotations are unnecessary, a regular-expression tokenizer can be substantially faster; when accuracy and annotations matter, spaCy provides the fuller pipeline. section 2.1.5 section 2.1.5

How Natural Language Processing in Action, Second Edition covers it

How deep it goes
Explains runnable model loading, token attributes, visualization, pipeline timing, and NER architecture without teaching neural-network construction.
Examples
Uses thinker quotations, an AsciiDoc chapter, medical-record workloads, dependency diagrams, and text about Timnit Gebru.
What it assumes
Assumes basic Python and introduces model downloading, loading, Doc objects, token attributes, and tag explanations through executable examples.
What you can do after
Apply it via spaCy to tokenize text, inspect grammatical structure, render dependencies, extract entities, and tune pipeline speed.
How it connects
Connects tokenization with sentence boundary detection, POS tagging, lemmatization, dependency parsing, named entity recognition, and displaCy.

Also explained in

Compare how 5 books explain spaCy →

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.