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:
- NP: noun phrase, such as “My new computer.” section 11.6
- VP: verb phrase, such as “has memory issues.” section 11.6
- S: sentence, and PP: prepositional phrase. section 11.6.1
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
