Structured Prediction and Parsing Evaluation › Dynamic Programming over Trees

Michael BrenndoerferNovember 17, 20269 min read
Language AI HandbookAll chapters
Part 7 of 67Linguistic Form: Morphology and Syntax
Chapter 49Structured Prediction and Parsing Evaluation › Dynamic Programming over Trees
Reading section 3 of 14 · Dynamic Programming over Trees · 9 minSection 3 of 14 · 9 min

Section 3 of 14 · 9 min read

Reading settings

Definitions

Choose how many terms have tooltips.

Article links

Make inline references clickable

Notes & comments

Dynamic programming reuses solutions to subproblems that recur. The maximum-score charts here use boundary states that preserve which continuations are legal and what score each continuation adds, regardless of the internal derivation. Once the state is fixed, we can keep its best internal derivation. A tree-shaped output alone is insufficient; the factorization and the chart state must make that replacement valid.

The Recursive Decomposition of a Projective Tree

Take a complete rooted subtree whose descendants occupy positions ii through jj. Its root rr is the one node whose parent lies outside this subtree, unless it is the sentence root. Projectivity requires every descendant subtree to occupy a contiguous interval. The child subtrees on each side of rr therefore partition the remaining positions on that side without gaps or overlaps. An arbitrary interval of a projective tree need not be a complete subtree and need not have only one node with an outside parent.

That gives the fundamental recursion: a projective tree over [i,j][i,j] with head rr is a head rr plus a sequence of projective subtrees to its left and a sequence of projective subtrees to its right. Every subtree is itself a projective tree over a contiguous subspan, so the same problem recurs on smaller inputs.

Memoizing an arbitrary span [i,j][i,j] together with a free internal head rr would create O(n3)O(n^3) states: two endpoints and one head index. Eisner's construction instead uses one-sided structures whose head is always an endpoint. That reduces the state space to O(n2)O(n^2) entries, with a small constant number of direction and completeness types. The four charts below encode those boundary distinctions.

Eisner's Four Charts

We use a four-chart formulation of the projective parsing approach introduced by Eisner (1996), indexed by span endpoints and a direction bit. The four charts are not arbitrary; each one corresponds to a distinct state of a partially assembled subtree, and the distinction between them is what allows the recurrence to close without circular dependencies.

  • C[i,j,→]C[i,j,\rightarrow]: a complete right half headed by endpoint ii. The represented descendants cover the inclusive interval i..ji..j, and that side is complete. The full subtree of ii may also have a left half outside this interval.
  • C[i,j,←]C[i,j,\leftarrow]: a complete left half headed by endpoint jj, covering i..ji..j. The full subtree of jj may also have a right half outside the interval.
  • I[i,j,→]I[i,j,\rightarrow]: an incomplete span. It contains the arc i→ji \to j, plus the subtrees hanging between them. The dependent jj can still grow children to its right, outside the span.
  • I[i,j,←]I[i,j,\leftarrow]: the mirror, containing arc j→ij \to i.

The distinction between complete and incomplete is the crux. A complete span is finished on its represented side; an incomplete span is a head that has claimed one dependent but not yet finished building that dependent's subtree. These recurrences need the incomplete item to record the chosen arc while its dependent’s outward side is still unfinished. Concretely, when ii takes jj as a dependent you have committed to the arc but you have not yet committed to everything that hangs off jj, and that unfinished business is exactly what the II chart records.

The Recurrences

Each single-token span is complete with score zero, C[i,i,→]=C[i,i,←]=0C[i,i,\rightarrow] = C[i,i,\leftarrow] = 0. Work in order of increasing span width. For each wider span, fill its two incomplete directions before either complete direction, because a complete item can use an incomplete item of that same span. Write s(h,d)s(h,d) for the arc score.

I[i,j,→]=s(i,j)+max⁡i≤k<j(C[i,k,→]+C[k+1,j,←])I[i,j,\rightarrow] = s(i,j) + \max_{i \le k < j}\left( C[i,k,\rightarrow] + C[k+1,j,\leftarrow] \right)

where:

  • I[i,j,→]I[i,j,\rightarrow]: the best score of an incomplete span from ii to jj headed at ii, with jj as a rightward dependent
  • s(i,j)s(i,j): the arc score for the head ii taking dependent jj
  • C[i,k,→]C[i,k,\rightarrow]: the best complete rightward span headed at ii covering i..ki..k
  • C[k+1,j,←]C[k+1,j,\leftarrow]: the best complete leftward span headed at jj covering k+1..jk+1..j
  • kk: the last position of the complete rightward span headed at ii before attaching jj

To build the item for i→ji \to j, put the split between kk and k+1k+1. The complete span headed at ii covers i..ki..k, and the complete span headed at jj covers k+1..jk+1..j. Either piece can consist of its head alone. The two pieces are contiguous and disjoint before the link. Adding the arc makes the descendants in jj's left piece descendants of ii as well. Interleaving the two pieces would violate projectivity.

I[i,j,←]=s(j,i)+max⁡i<k≤j(C[i,k−1,→]+C[k,j,←])I[i,j,\leftarrow] = s(j,i) + \max_{i < k \le j}\left( C[i,k-1,\rightarrow] + C[k,j,\leftarrow] \right)

The mirror image, for a leftward arc.

C[i,j,→]=max⁡i<k≤j(I[i,k,→]+C[k,j,→])C[i,j,\rightarrow] = \max_{i < k \le j}\left( I[i,k,\rightarrow] + C[k,j,\rightarrow] \right)

where:

  • C[i,j,→]C[i,j,\rightarrow]: the best complete rightward span headed at ii covering i..ji..j
  • I[i,k,→]I[i,k,\rightarrow]: the best incomplete rightward span headed at ii with dependent kk
  • C[k,j,→]C[k,j,\rightarrow]: the best complete rightward span headed at kk covering k..jk..j, giving kk its right subtree
  • kk: the rightmost child of ii that closes the span

The rightmost child of ii is some kk. The incomplete item I[i,k,→]I[i,k,\rightarrow] already contains the arc i→ki \to k. The complete item C[k,j,→]C[k,j,\rightarrow] supplies the rest of kk's subtree on the right. This finishes the subtree rooted at kk and completes the right half headed at ii.

C[i,j,←]=max⁡i≤k<j(C[i,k,←]+I[k,j,←])C[i,j,\leftarrow] = \max_{i \le k < j}\left( C[i,k,\leftarrow] + I[k,j,\leftarrow] \right)

In the mirror recurrence, kk is jj's leftmost child. The incomplete item I[k,j,←]I[k,j,\leftarrow] already contains j→kj \to k. Its partner C[i,k,←]C[i,k,\leftarrow] supplies kk's left half and completes jj's left half. For the whole sentence, choose a root rr. Everything to its left is a left-complete span headed at rr, and everything to its right is a right-complete span headed at rr.

best=max⁡0≤r<n(C[0,r,←]+C[r,n−1,→])\text{best} = \max_{0 \le r < n}\left( C[0,r,\leftarrow] + C[r,n-1,\rightarrow] \right)

where:

  • best\text{best}: the score of the best projective tree over the whole sentence
  • rr: the index of the sentence's root token
  • C[0,r,←]C[0,r,\leftarrow]: the best complete leftward span headed at rr covering tokens 0..r0..r
  • C[r,n−1,→]C[r,n-1,\rightarrow]: the best complete rightward span headed at rr covering tokens r..n−1r..n-1

Because the root is chosen once and the two halves share only the root node (whose base score is zero), no arc is counted twice and exactly one root exists.

Projectivity follows from the chart

Every chart entry covers a contiguous span. Incomplete items combine two disjoint spans. Complete items join spans that share a boundary token. Neither join interleaves the spans. So the algorithm cannot produce crossing arcs. Projectivity is enforced by the shape of the state space, not by a check after the fact. No separate post-decoding crossing check is needed for this algorithm. Building and combining the chart states still has the computational cost derived below.

Complexity

There are O(n2)O(n^2) inclusive intervals, two directions, and complete and incomplete states. Each recurrence considers O(n)O(n) split positions, giving O(n3)O(n^3) time and O(n2)O(n^2) space, including backpointers and excluding score preparation. The illustrative quantity n3n^3 is one million at n=100n=100 and one billion at n=1000n=1000, but those are growth-function values, not exact instruction counts or wall-clock predictions. Constants, implementation, batching, and hardware still matter.

Adding output interactions can enlarge the chart, but the cost must be derived for the particular state design. An adjacent-sibling chart can retain cubic time by sharing sibling subproblems. Adding a free grandparent index gives a quartic example, while selected third-order grand-sibling and tri-sibling factorizations also admit quartic algorithms. These examples show why “second-order” or “third-order” alone is not a complexity bound. They also explain why a sentence-wide encoder and an arc-factored decoder can remain attractive: the encoder supplies input context without introducing interactions among selected output arcs.

When the Tree Is Not Projective

Some dependency annotations contain non-projective arcs. When a gold tree is outside the projective output space, a projective decoder cannot reproduce it exactly, regardless of its scores. A parser can retain those annotations and use a suitable non-projective decoder, or train with an explicitly described projectivization and recovery procedure. The prevalence of such cases depends on the language, annotation scheme, and treebank; it should be measured rather than inferred from a language label alone.

For an arc-factored score without projectivity constraints, Chu-Liu/Edmonds finds a maximum-weight directed arborescence rooted at a specified artificial root. Build candidate edges from a head to each possible dependent, omitting self-edges and edges into the artificial root. The arborescence gives every lexical word one incoming edge and reaches every word from that root. An additional annotation requirement may demand exactly one lexical child of the artificial root, as in UD basic trees. An ordinary arborescence does not enforce that degree-one requirement automatically; it needs an explicit single-root restriction or a procedure such as conditioning on the lexical root candidate.

The algorithm starts with the best incoming edge for each non-root node. If these edges already form a rooted arborescence, they are optimal: no competing tree can improve any node's selected incoming score. If a directed cycle appears, the algorithm contracts it to one node. An entering edge carries its original weight plus the total weight of the cycle edges that would remain after it displaces the selected edge into its destination. For an edge leaving the cycle, keep its original weight. When several edges collapse to the same endpoints, keep a highest-weight representative and remember its original endpoints. Solve the reduced problem, then restore every cycle edge except the one displaced by the chosen entering edge. Simply deleting the smallest original cycle edge is not a general solution. The independently maximized incoming-score sum is an upper bound on the constrained maximum, because the relaxed selection ignores tree constraints.

The non-projective search space contains the projective trees, so its maximum model score cannot be smaller when all other score and root conventions match. This inclusion gives no guarantee about gold attachment accuracy: a higher-scoring tree can still be wrong. Compare decoders on the relevant development data, record the output-space restrictions, and inspect the non-projective cases separately. This separates a mathematical inclusion result from an empirical choice of parser.

Comments

Add to the conversation

A question, a correction, or an example from your own work.

No comments yet. Be the first to share your thoughts!

Newsletter

Stay up to date

Get new articles, book updates, and notes on AI and technology.

Unsubscribe at any time. Privacy policy