Structured Prediction and Parsing Evaluation › Span Scores and Constituency Decoding

Michael BrenndoerferNovember 17, 20267 min read
Language AI HandbookAll chapters
Part 7 of 67Linguistic Form: Morphology and Syntax
Chapter 49Structured Prediction and Parsing Evaluation › Span Scores and Constituency Decoding
Reading section 5 of 14 · Span Scores and Constituency Decoding · 7 minSection 5 of 14 · 7 min

Section 5 of 14 · 7 min read

Reading settings

Definitions

Choose how many terms have tooltips.

Article links

Make inline references clickable

Notes & comments

The dependency model above factors over arcs. A constituency model can instead factor over labeled spans or over grammar productions. Both can support dynamic programming, but they retain different states and combine different parts. Comparing them makes the general design visible without identifying CKY and Eisner as the same algorithm.

Span-Factored Scores

For scoring, collect the labeled spans (i,j,A)(i,j,A) in a multiset. This preserves repeated occurrences with the same span and label, but can lose the order of unary nodes over that span. The natural factorization scores each constituent independently:

s(x,y)=∑(i,j,A)∈yϕ(x,i,j,A)s(x, y) = \sum_{(i,j,A) \in y} \phi(x, i, j, A)

where:

  • (i,j,A)(i,j,A): a constituent spanning token indices ii through j−1j-1, using half-open boundaries [i,j)[i,j), with label AA
  • ϕ(x,i,j,A)\phi(x, i, j, A): the model's local score for that constituent given input xx

In a span-factored neural model, ϕ(x,i,j,A)\phi(x,i,j,A) can score a label using contextual representations of the input span. A PCFG instead assigns local scores to productions such as A→B CA\to B\,C and lexical rules. Its score is not, in general, a sum of scores depending only on (i,j,A)(i,j,A), because the chosen child labels and rule matter. Both admit chart recurrences under the appropriate factorization. A span-scored grammar-constrained chart adds the parent span score to the best licensed child combination; the PCFG recurrence below adds a production score. Stern, Andreas, and Klein (2017) give a neural example based on independent label and span scoring.

CKY as Structured Prediction

CKY fills a chart over half-open spans and labels. For a span [i,j)[i,j) and label AA, the best score is the best way to split the span into two children whose labels are licensed by a rule:

chart[i,j,A]=max⁡i<k<j max⁡A→B C(rule(A→B C)+chart[i,k,B]+chart[k,j,C])\text{chart}[i,j,A] = \max_{i < k < j}\ \max_{A \to B\,C}\left( \text{rule}(A \to B\,C) + \text{chart}[i,k,B] + \text{chart}[k,j,C] \right)

where:

  • chart[i,j,A]\text{chart}[i,j,A]: the best score for label AA over token indices i,…,j−1i,\ldots,j-1
  • kk: the boundary dividing [i,j)[i,j) into children [i,k)[i,k) and [k,j)[k,j)
  • A→B CA \to B\,C: a binary grammar rule whose parent label is AA and whose child labels are BB and CC
  • rule(A→B C)\text{rule}(A \to B\,C): the rule's score, for example a log PCFG probability
  • chart[i,k,B]\text{chart}[i,k,B] and chart[k,j,C]\text{chart}[k,j,C]: the best scores of the left and right child constituents

A one-word span [i,i+1)[i,i+1) receives its lexical/preterminal score. The displayed recurrence assumes binary rules; unary rules require a separate closure procedure or a preprocessing representation, and arbitrary unary cycles require additional care. The tutorial grammar below has only binary and lexical productions, so it needs no unary closure. Its supplied preterminal tags are fixed inputs, not predictions from another model.

The two algorithms share the same split-and-combine shape. Eisner combines inclusive intervals, and its complete joins share the boundary token. CKY combines two disjoint half-open subspans, [i,k)[i,k) and [k,j)[k,j). Eisner tracks which end holds the head and whether the span is complete. CKY tracks the category. Both combine reusable substructures. Eisner takes cubic time with quadratic chart storage; the shown CKY loops take O(n3∣R2∣)O(n^3|\mathcal{R}_2|) time when every binary rule is inspected at every split, with O(n2∣N∣)O(n^2|\mathcal{N}|) chart entries for category set N\mathcal{N}.

In log-score space, maximum-score decoding combines child scores by addition and alternatives by max⁡\max. Summing the weights of all derivations keeps the child-score additions but replaces the alternative maximum by log-sum-exp. In ordinary nonnegative weight space, these are max-product and sum-product recurrences instead. The change of algebra reuses the same legal decomposition; it does not mean that adding arbitrary raw scores sums probabilities. Decoding and partition-function computation are closely related chart operations when the factorization satisfies these assumptions.

Inside, Outside, and Marginals

The inside weight sums the nonnegative, unnormalized weights of all compatible subtrees rooted at a constituent:

α(i,j,A)=∑trees t rooted at (i,j,A)exp⁡s(t)\alpha(i,j,A) = \sum_{\text{trees } t \text{ rooted at } (i,j,A)} \exp s(t)

where:

  • α(i,j,A)\alpha(i,j,A): the inside weight for category AA over [i,j)[i,j)
  • tt: a subtree rooted at that constituent
  • s(t)s(t): the raw score of subtree tt
  • exp⁡s(t)\exp s(t): the unnormalized weight of tt, summed across all such subtrees

The outside weight sums compatible surrounding contexts, with the constituent's entire inside derivation removed. Its factors must exclude those already counted by α\alpha; otherwise their product would count them twice. For the finite binary/lexical derivations considered here, the context leaves a single category-AA hole at [i,j)[i,j). This yields:

β(i,j,A)=∑compatible contexts with a category-A hole at [i,j)exp⁡s(context)\beta(i,j,A) = \sum_{\text{compatible contexts with a category-}A\text{ hole at }[i,j)} \exp s(\text{context})

The marginal probability that a parse contains the constituent is

p(i,j,A)=α(i,j,A) β(i,j,A)Zp(i,j,A) = \frac{\alpha(i,j,A)\,\beta(i,j,A)}{Z}

where:

  • p(i,j,A)p(i,j,A): the marginal probability that a parse contains constituent (i,j,A)(i,j,A)
  • α(i,j,A)\alpha(i,j,A): the inside weight of the constituent
  • β(i,j,A)\beta(i,j,A): the outside weight of the constituent
  • Z=α(0,n,S)Z = \alpha(0,n,S): the partition function, the sum over all trees rooted at the start symbol SS

With one fixed start category SS, Z=α(0,n,S)Z=\alpha(0,n,S) sums all accepted full derivations and the root outside weight is one. The product αβ\alpha\beta sums derivations containing the particular chart item; division by positive finite ZZ gives its marginal. This interpretation assumes the item occurs at most once in each derivation, as in the binary/lexical charts here. Inside-outside plays the role on these trees that forward-backward plays on chains, rather than being an identical recurrence with the indices renamed. For the chain recursions and their use in computing marginals, see Sutton and McCallum (2010), §3.1.

Decoding for the Metric

Viterbi decoding returns a highest-probability complete derivation. When each scored tree corresponds to exactly one modeled derivation, Viterbi also selects a most probable tree. A most probable tree minimizes expected exact-tree zero-one loss. If several derivations represent the same scored tree, sum their probabilities before comparing trees. Other evaluation losses can prefer another tree. Constituent marginals aggregate probability over all trees containing each span, so a span can have high marginal probability even when the single most probable full tree omits it.

For a fixed predicted constituent set PP and random gold set GG, linearity of expectation gives

E[∣P∩G∣]=∑c∈PPr⁡(c∈G).\mathbb{E}[|P\cap G|]=\sum_{c\in P}\Pr(c\in G).

Here cc is a labeled constituent and the probability comes from the model's distribution over legal gold trees. A chart that maximizes the sum of these marginal scores, while still requiring a legal predicted tree, maximizes expected overlap. Greedily selecting high-marginal spans without a tree constraint can instead select crossing or otherwise incompatible spans. A marginal probability is also different from a max-marginal score, which uses the best complete structure containing a part rather than summing probabilities.

Expected F1 requires more care. For a positive combined scored count, F1(P,G)=2∣P∩G∣/(∣P∣+∣G∣)F_1(P,G)=2|P\cap G|/(|P|+|G|). If both scored constituent counts are fixed across all relevant trees and their sum is positive, maximizing expected overlap also maximizes expected F1. For multiset scoring, overlap counts matched occurrences with multiplicity. The fixed-count argument also applies to expected multiset overlap, but a single presence probability per constituent need not give that overlap. If a prediction contains pcp_c copies of a labeled constituent cc and the gold count is GcG_c, the expected number of matches for cc is ∑j=1pcPr⁡(Gc≥j)\sum_{j=1}^{p_c}\Pr(G_c\ge j). When both counts are zero, use the scorer’s declared convention. If unary chains, branching, or normalization make the counts vary, raw constituent marginals alone do not establish that equivalence. Goodman (1996) studies parsing algorithms matched to particular recall and tree criteria; it is important to retain the criterion and its assumptions when applying that result.

The practical lesson is to choose a decision rule for the intended loss and legal output space. Under additive per-token zero-one loss and unconstrained label choices, choosing the highest-marginal label at each token minimizes expected token error, but those choices may violate sequence constraints and they do not automatically optimize a sequence- or span-F1 metric. Loss-aware decoding is a modeling option, not a guarantee that one named decoder will improve every reported score.

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