Dependency Parsing Tutorial Section

Dependency Parsing

Understand how to map direct grammatical relationships between words without hierarchical phrasing.

Dependency Parsing

Unlike Constituency Parsing (which builds nested phrase boxes), Dependency Parsing directly draws directional linkages between the words themselves. It maps out which word is the grammatical "Head" and which word is its "Dependent".

Dependency parsing is much more popular than constituency parsing in modern NLP (especially through spaCy) because it is faster, lighter, and easier to use for Information Extraction.

Head vs Dependent

Dependency links are directional (). In the phrase "clever dog":

  • "dog" is the Head word (ROOT concept).
  • "clever" is the Dependent word (it modifies the dog).
  • Link type: amod (Adjectival Modifier).
Visualizing Dependencies
The
det
clever
amod
dog
nsubj
chased ROOT
the
det
ball
dobj

Universal Dependency Tags

Tag Meaning Example Relation
nsubjNominal SubjectProvides the subject to the verb. (dog → chased)
dobjDirect ObjectThe entity acted upon. (chased → ball)
amodAdjectival ModifierModifies the noun. (clever → dog)
prepPrepositional ModifierLinks preposition to its head. (sat → on)
ROOTRoot of SentenceThe central active verb. (chased)
Extracting Dependencies with spaCy
import spacy

nlp = spacy.load("en_core_web_sm")
doc = nlp("The clever dog chased the ball.")

# Print Subject-Verb-Object relationships!
print(f"{'Text':<10} | {'Dependent Tag':<15} | {'Head Word':<10}")
print("-" * 40)
for token in doc:
    print(f"{token.text:<10} | {token.dep_:<15} | {token.head.text:<10}")

'''
Output:
Text       | Dependent Tag   | Head Word 
----------------------------------------
The        | det             | dog       
clever     | amod            | dog       
dog        | nsubj           | chased     <-- We found the subject!
chased     | ROOT            | chased     <-- Core verb of sentence
the        | det             | ball      
ball       | dobj            | chased     <-- We found the object!
.          | punct           | chased    
'''