Structured Prediction and Parsing Evaluation › Span Scores and Constituency Decoding
Language AI HandbookAll chapters 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 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:
where:
- : a constituent spanning token indices through , using half-open boundaries , with label
- : the model's local score for that constituent given input
In a span-factored neural model, can score a label using contextual representations of the input span. A PCFG instead assigns local scores to productions such as and lexical rules. Its score is not, in general, a sum of scores depending only on , 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 and label , the best score is the best way to split the span into two children whose labels are licensed by a rule:
where:
- : the best score for label over token indices
- : the boundary dividing into children and
- : a binary grammar rule whose parent label is and whose child labels are and
- : the rule's score, for example a log PCFG probability
- and : the best scores of the left and right child constituents
A one-word span 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, and . 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 time when every binary rule is inspected at every split, with chart entries for category set .
In log-score space, maximum-score decoding combines child scores by addition and alternatives by . 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:
where:
- : the inside weight for category over
- : a subtree rooted at that constituent
- : the raw score of subtree
- : the unnormalized weight of , 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 ; otherwise their product would count them twice. For the finite binary/lexical derivations considered here, the context leaves a single category- hole at . This yields:
The marginal probability that a parse contains the constituent is
where:
- : the marginal probability that a parse contains constituent
- : the inside weight of the constituent
- : the outside weight of the constituent
- : the partition function, the sum over all trees rooted at the start symbol
With one fixed start category , sums all accepted full derivations and the root outside weight is one. The product sums derivations containing the particular chart item; division by positive finite 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 and random gold set , linearity of expectation gives
Here 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, . 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 copies of a labeled constituent and the gold count is , the expected number of matches for is . 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!