liveBook · Manning

Constituency parsing

As explained in Natural Language Processing in Action, Second Edition

A constituency relation describes how words group together into nested grammatical phrases within a sentence.

Constituency parsing reveals how words group into nested grammatical phrases. Unlike dependency parsing, which connects words, it breaks a sentence into constituents such as noun phrases and verb phrases, building the structure from larger units downward. section 11.6

Common constituent labels include:

A practical implementation uses Berkeley Neural Parser through spaCy or NLTK. After adding benepar to spaCy’s pipeline, the parser returns a bracketed structure containing phrase groupings and token part-of-speech tags. The richer syntactic output can support sentence simplification and summarization, although it is slower to compute and harder to interpret. section 11.6.1 section 11.6

>>> import spacy
>>> nlp = spacy.load("en_core_web_md")
>>> if spacy.__version__.startswith('2'):
...     nlp.add_pipe(benepar.BeneparComponent("benepar_en3"))
... else:
...     nlp.add_pipe("benepar", config={"model": "benepar_en3"})
>>> doc = nlp("She and five others coauthored a research paper,'On the
      Dangers of Stochastic Parrots:  Can Language Models Be Too Big?'")
>>> sent = list(doc.sents)[0]
>>> print(sent._.parse_string)
(S (NP (NP (PRP She)) (CC and) (NP (CD five) (NNS others))) (VP (VBD coauthored) (NP (NP (DT a) (NN research) (NN paper)) (, ,) (`` ') (PP (IN On) (NP (NP (DT the) (NNS Dangers)) (PP (IN of) (NP (NNP Stochastic) (NNPS Parrots))))) (: :) (MD Can) (NP (NN Language) (NNS Models)) (VP (VB Be) (ADJP (RB Too) (JJ Big))))) (. ?) ('' '))

Run the spaCy and benepar pipeline on a sentence, then inspect its nested S, NP, VP, and PP structure. section 11.6.1

How Natural Language Processing in Action, Second Edition covers it

How deep it goes
Explains constituent grouping, labels, top-down parsing, and tooling, but stops short of parser internals.
Examples
Uses bracketed parses of research-paper sentences and identifies NP, VP, S, and PP labels.
What it assumes
Assumes familiarity with spaCy or NLTK pipelines and tokenization while defining phrase labels from examples.
What you can do after
Apply it via benepar and spaCy to inspect nested phrase structure for downstream text-processing tasks.
How it connects
Contrasts constituency parsing with dependency parsing and connects both to named entities, information extraction, and sentence interpretation.

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.