Sub topic 10
Noun chunks and their roots
This chapter assumes basic Python, familiarity with spaCy pipelines and Doc objects, and basic grammar terms such as noun, verb, subject, and object. You should also know that a dependency parse connects each token to a syntactic head.
A noun chunk is a short, non-nested phrase centered on a noun. It usually includes the noun and words that describe or determine it. For example, the small team and a detailed report are noun chunks. Noun chunks are useful when you need complete noun phrases instead of individual noun tokens.
Finding noun chunks
spaCy exposes noun chunks through Doc.noun_chunks. The result is an iterator of Span objects. A Span represents a continuous section of a document.
import spacy
nlp = spacy.load("en_core_web_sm")
doc = nlp("The small team wrote a detailed report about the results.")
for chunk in doc.noun_chunks:
print(chunk.text)A typical output is:
The small team
a detailed report
the resultsThe exact chunks depend on the language and trained pipeline. The parser and tagger decide which words belong together, so noun chunks are model output rather than fixed rules.
Each chunk has a root. The root is the token that acts as the syntactic head of the chunk. In the small team, team is the root. The words the and small depend on team inside the phrase.
for chunk in doc.noun_chunks:
root = chunk.root
print(
chunk.text,
"| root:", root.text,
"| dependency:", root.dep_,
"| head:", root.head.text,
)The root's dep_ describes how the complete noun phrase functions in the sentence. The root's head is usually outside the chunk and connects the chunk to the larger dependency tree. For example, the root team may be the nominal subject of wrote, while report may be the direct object of wrote.
| Noun chunk | Root | Root relation | Root's head |
|---|---|---|---|
| The small team | team | `nsubj` | wrote |
| a detailed report | report | `obj` | wrote |
| the results | results | `pobj` | about |
chunk.root is different from chunk[0]. The first token is the leftmost word, while the root is the syntactic center. Determiners and adjectives often come before the root, but a noun phrase can also contain modifiers after it.
Reading a chunk in the dependency tree
This simplified view shows how the phrase root connects the chunk to the verb.
Noun chunks are especially convenient for lightweight information extraction. Instead of manually collecting determiners and adjectives around every noun, you can begin with the complete span and then inspect its root.
Some phrases will not appear as noun chunks. spaCy's noun-chunk iterator depends on a parser and on language-specific grammar rules. A malformed sentence, a domain-specific term, or a different language model can produce missing or unexpected chunks. Check examples from your own data before treating noun chunks as ground truth.
Exercise
In the phrase "Several careful reviewers examined the draft", which token is the root of "Several careful reviewers", and what is the likely dependency label of that root?
Show answer
"reviewers" is the root. Because the phrase performs the examining, its likely dependency label is nsubj.