Dependency Parsing
Dependency parsing draws one arrow from each word to the word it modifies, so a sentence becomes a tree headed by its main verb.
Why Does This Exist?
Parts of speech tell you "cat" is a noun and "chased" is a verb, but they never say who chased whom. "The cat chased a mouse" and "A mouse chased the cat" carry identical tags in a different order, yet mean opposite things. Part-of-speech tagging labels words. Dependency parsing connects them.
The connection is one arrow per word: each word points to its head, the word it modifies, with a label like nsubj (subject) or dobj (object). The main verb heads the whole sentence. That tree answers "who did what to whom" directly, which is why relation extraction and semantic role labeling both consume it. Without it, an extractor guessing from word order breaks on every passive or reordered sentence.
This page covers the tree and the two classic ways to build it. Tagging is the prerequisite: you cannot label relations well if you do not know nouns from verbs, so read the POS page first if tags like DET and NOUN feel new.
Think of It Like This
An org chart for one sentence
Picture a small company where everyone has exactly one manager except the CEO. The CEO of "The cat chased a mouse" is "chased". "Cat" and "mouse" report to "chased" as subject and object. "The" reports to "cat" and "a" reports to "mouse", like assistants to their managers. Follow any word upward and you reach the verb, just as any employee chain reaches the CEO.
Where it stops: a real company can have dotted-line reports to two managers. A dependency tree cannot. Each word gets exactly one head, so shared modifiers in coordinations like "old cats and dogs" must pick one parent even when both readings feel natural.
How It Actually Works
A dependency tree over words through plus an artificial ROOT is a directed graph . Here is the word set including ROOT, and each arc runs from head to dependent with relation label . A valid tree has three properties: every word except ROOT has exactly one incoming arc, every word is reachable from ROOT, and no cycles exist.
The worked sentence
"The cat chased a mouse" has words, so a valid tree carries exactly arcs:
- chased heads the sentence (child of ROOT)
- cat points to chased with nsubj
- mouse points to chased with dobj
- The points to cat with det
- a points to mouse with det
That is the picture above: the focal spine from ROOT to the verb, two long argument arcs, two short article arcs. Five words, five arcs, one head each.
Two builders
Transition parsing reads left to right with a stack and a buffer, predicting Shift, Left-Arc, or Right-Arc at each step. It finishes in steps for words, so our 5-word sentence takes transitions, which is why it runs in linear time. Graph parsing instead scores every possible arc and extracts the maximum spanning tree with the Chu-Liu-Edmonds algorithm in roughly . The first is fast and greedy, the second is slower and globally optimal, and on long sentences the global view wins.
Code
This checks the three tree properties on a head array where heads[i] is the index of the head of word i, with 0 meaning ROOT.
def is_tree(heads: list[int]) -> tuple[bool, str]: n = len(heads) - 1 for d in range(1, n + 1): if heads[d] < 0 or heads[d] > n or heads[d] == d: return False, f"bad head for {d}" kids: dict[int, list[int]] = {i: [] for i in range(n + 1)} for d in range(1, n + 1): kids[heads[d]].append(d) seen = {0} stack = [0] while stack: node = stack.pop() for c in kids[node]: if c not in seen: seen.add(c) stack.append(c) ok = len(seen) == n + 1 return ok, "5 words, 5 arcs, one ROOT child" if ok else "not connected"print(is_tree([0, 2, 3, 0, 5, 3])) # -> (True, '5 words, 5 arcs, one ROOT child')Watch Out For
Assuming trees never cross
English arcs rarely cross, so projective parsers feel safe. Free word order languages cross often, and the basic arc-standard system cannot produce a crossing tree at all. If you parse Czech or Latin with a projective decoder, complex sentences fail structurally before scoring even matters. Check the non-projective rate of your treebank first.
Attaching prepositions by habit
"In the park with a telescope" attaches "with" to the verb or the noun depending on meaning, and parsers learn the frequent case. On your domain the frequent case may flip, so "cut the box with a knife" versus "cut the box with a logo" need different heads. When extraction precision drops, inspect PP attachments before retraining anything else.
The Quick Version
- Dependency parsing points every word at its head with a labeled relation, forming a tree headed by the main verb.
- The tree for "The cat chased a mouse" has 5 arcs: nsubj, dobj, two det labels, and the ROOT link to chased.
- Transition parsers build the tree in 2n greedy steps, so 5 words take 10 transitions; graph parsers score all arcs and decode the best tree globally.
- Subjects, objects and modifiers become explicit, which is what extraction and role labeling consume.
- Each word takes exactly one head, so shared modifiers and crossing arcs need deliberate handling.