Linguistic Structure/CKY Scoring, Evaluation, and Shallow Parsing

Lesson 6.21,977 words

CKY Scoring, Evaluation, and Shallow Parsing

The CKY chart returns every parse but does not say which is correct. Disambiguation needs a score on trees.

╌╌╌╌

This builds on constituency parsing, which developed the context-free grammar, the structural ambiguity that gives one sentence many trees, and the CKY chart that recovers all of them in one cubic-time pass. CKY recovers all parses but does not rank them. Picking the right tree out of the many it produces, and measuring how well a parser does, is where we pick up.

From all parses to the right one

CKY hands back every parse; it does not say which is correct. Disambiguation needs a score on trees. The classical answer is the probabilistic CFG (PCFG): attach to each rule a probability , with the probabilities of all expansions of a given summing to one.1 The probability of a parse tree is the product of the rule probabilities used to build it,

and the best parse of a sentence is . A small change to CKY turns it into the parser that finds : each cell stores, for each nonterminal, the maximum-probability subtree spanning that cell, taking a max over split points instead of a union. The recurrence for the best score of nonterminal over span is

the same triangular fill, now carrying a probability and a back-pointer to the winning .

A probabilistic CFG attaches a probability to each expansion of a nonterminal (the numbers on each VP rule sum to 1). The parse probability is the product of the rule probabilities used; probabilistic CKY keeps the max-scoring subtree per cell.

Plain PCFGs are weak because the independence assumption is too strong: the probability of VP → Verb NP PP should depend on which verb, but the rule probability ignores the words. Lexicalization fixes this by annotating every nonterminal with its lexical head — the grammatically central word it dominates (N heads an NP, V heads a VP). A rule then reads VP(dumped) → VBD(dumped) NP(sacks) PP(into), and the probabilities can capture that dumped prefers a PP(into) complement. Heads propagate up the tree: each node inherits the head of its designated head child.2

A lexicalized parse tree: every nonterminal carries its lexical head word in parentheses. The head propagates up from the head child, so S(dumped) inherits its head from VP(dumped), which inherits from the verb.

Span-based neural parsing

Modern parsers drop the hand-written grammar's role in scoring and let a neural network score constituents directly.3 A span is a stretch between fenceposts and with a candidate label ; a classifier assigns it a score . The tokens are embedded by a pretrained encoder such as BERT, each fencepost is represented by a forward and a backward half-vector, and a span is encoded by differencing its endpoints,

which a small MLP maps to a score per possible label. A tree is a set of labeled spans, and its score is the sum over its spans,

Span-based neural parsing. An encoder embeds the words; each span (i, j) is scored per label by an MLP; a CKY-style recursion combines span scores into the best tree. The grammar's constraining role is replaced by the learned scores.

The best tree is found with the same CKY recursion, now maximizing summed span scores: for length-one spans , and for longer spans

The grammar's job — constraining which constituents may combine — is gone; the neural model learns those constraints from data instead. The chart machinery is unchanged; only the source of the scores is different.

Beyond the chart: self-attentive parsing and its results

The span-based parser above sketches the idea; the named work that made it the state of the art fixes where the span scores come from and how the model is trained. Three public papers trace the line; their measured numbers quantify the gain over the classical PCFG.

From RNN spans to a self-attentive encoder (Stern 2017; Kitaev and Klein, 2018)

The minimal-span parser of Stern, Andreas, and Klein (ACL 2017) established the approach: score every labeled span with a neural network, then run a CKY-style chart to assemble the highest-scoring tree, trained with a margin objective that pushes the gold tree's score above every wrong tree by a margin. It reached about labeled on the Penn Treebank Wall Street Journal test set, already competitive with the best lexicalized PCFGs without any explicit grammar.

Kitaev and Klein (ACL 2018) replaced the recurrent span encoder with a self-attentive encoder — a transformer stack — and found two design points that mattered. First, factoring the attention into separate content and position streams sharpened the span representations. Second, and more surprising, the parser improved when it was prevented from mixing content and position information too freely in early layers. On the same WSJ test set the self-attentive parser reached about ; adding ELMo contextual word representations pushed it near . The follow-up (Kitaev, Cao, and Klein, ACL 2019) swapped in BERT as the encoder and reported roughly on English, and — using a single multilingual model — strong results across ten languages at once, showing the span-scoring recipe is not English-specific.

Labeled F1 on the Penn Treebank WSJ test set as the span encoder changed: classical lexicalized PCFG (90), Stern et al. RNN spans (91.8), Kitaev-Klein self-attentive (93.6), with ELMo (95.1), with BERT (~95.6). The chart recursion is unchanged; only the encoder feeding the span scores improves.

Why the grammar could be dropped

The classical picture in this lesson makes the grammar do two jobs: it constrains which constituents may combine (an NP and a VP make an S, a Det and a Nominal make an NP), and a PCFG's rule probabilities score how likely each combination is. The neural parser drops the first job entirely — its chart allows any label on any span — and folds the second into learned span scores. What replaces the grammar's constraints is the encoder's context: a self-attentive representation of a span already encodes whether the surrounding words make an NP plausible there, so the model rarely proposes an incoherent tree even without a rule forbidding it. Gaddy, Stern, and Klein (NAACL 2018) observed that a greedy per-span labeling forms a valid tree about of the time, which is why the CKY step, though still used to guarantee a tree, matters less than it did for the hand-written grammar. The optimal-substructure argument that makes CKY correct is untouched; the source of the per-span evidence moved from counts over rules to a transformer over words.4

Evaluating parsers with PARSEVAL

To score a parser we compare its trees against gold trees from a treebank, using PARSEVAL.5 A constituent in the hypothesis is correct if the reference tree has a constituent with the same start point, end point, and nonterminal label. From that we compute the same precision and recall as in any tagging task:

reported together as their harmonic mean . A third metric, crossing brackets, counts constituents where the hypothesis brackets as but the reference brackets as — groupings that are structurally incompatible rather than merely missing.

Work a small case. Suppose the reference tree has 7 labeled constituents and the parser's hypothesis has 6, of which 5 match a reference constituent exactly (same span, same label). Then precision is , recall is , and

PARSEVAL on a worked example. Of 6 hypothesis constituents, 5 match a reference constituent exactly (span + label); the reference has 7. Precision = 5/6, recall = 5/7, F1 ~ 0.77. The unmatched brackets are the errors.

The canonical PARSEVAL implementation is evalb, which also applies a canonicalization step that strips grammar-specific details (auxiliaries, pre-infinitival to) so parsers built on different grammars can be compared fairly.

Chunking and shallow parsing

A full CKY parse is often more than a task needs. Many applications never use the deep hierarchy, only the flat phrases near the leaves — and recovering just those is far cheaper and far more robust than building the whole tree.6 A partial parse (or shallow parse) does exactly that: it identifies and classifies the basic phrases of a sentence without nesting them into a complete structure. Information-extraction systems, for instance, do not need every constituent; they need the noun phrases that name entities and little else.

Chunking

The standard form of shallow parsing is chunking: segmenting a sentence into flat, non-overlapping phrases that correspond to the major content parts-of-speech — noun phrases, verb phrases, adjective phrases, prepositional phrases.7 A chunk is a base (non-recursive) phrase: it never contains another phrase of its own type. Because chunks do not nest, a simple bracketing notation suffices — no tree needed:

text
[NP The morning flight] [PP from] [NP Denver] [VP has arrived.]

Chunking involves two coupled tasks, visible in that bracketing: segmenting, finding the non-overlapping extents of the chunks, and labeling, assigning each discovered chunk its phrase type. The most common special case is base-NP chunking — finding just the base noun phrases and ignoring everything else. There, some words belong to no chunk at all:

text
[NP The morning flight] from [NP Denver] has arrived.
A chunked sentence. Chunks are flat, non-overlapping base phrases: each noun phrase (NP), the preposition (PP), and the verb phrase (VP) is a single bracket with no nesting. Compare a full parse tree, which would nest these phrases into a hierarchy.

What counts as a base phrase depends on the application, but one guideline holds almost everywhere: a base phrase includes its headword and any pre-head material, but excludes all post-head modifiers. Dropping post-head material is what avoids the attachment ambiguities that made full parsing hard — there is no PP to attach high or low, because the PP is its own separate chunk. This does produce oddities: prepositional and verb phrases often shrink to just their heads. The phrase a flight from Indianapolis to Houston chunks flat as

text
[NP a flight] [PP from] [NP Indianapolis] [PP to] [NP Houston]

where each PP is a bare preposition and the noun phrases it would have contained stand alone.

BIO tagging for chunks

Chunking is a segmentation problem, and the standard way to cast segmentation as a tagging problem — one label per token — is BIO tagging.8 Each chunk type gets two tags: B-type marks the beginning of a chunk, I-type marks a token inside the same chunk, and a single O marks tokens outside any chunk. A supervised sequence labeler then learns to emit these tags token by token. The bracketed sentence above becomes, with every chunk type tagged:

BIO tags for full chunking. Each token gets B- (begin) or I- (inside) of a chunk type, so "The morning flight" is B-NP I-NP I-NP. The tag changes to B-PP at "from" and B-VP I-VP over "has arrived", marking each chunk boundary.

The O tag matters when only some phrases are wanted. In base-NP chunking, every non-NP word is simply O, so the same sentence tagged for base noun phrases alone reads:

BIO tags for base-NP chunking only. Now only noun phrases are marked; "from", "has", and "arrived" fall outside any chunk and receive O. The B-/I- distinction still marks where each NP starts and continues.

Training and using a chunker

Chunking is done by supervised learning: train a BIO sequence labeler — a CRF, RNN, or Transformer — on annotated data, exactly the machinery used for part-of-speech tagging and named-entity recognition.7 Hand-annotating chunks is expensive, so training data is usually extracted from an existing treebank like the Penn Treebank: read the full parse, find each phrase's head with head-finding rules, keep the head and the material to its left, and discard the material to its right. This is somewhat error-prone, since it inherits any mistakes in the head-finding rules. A trained chunker is scored the same way as any tagger, by comparing its output against gold-standard human chunks with precision, recall, and over the discovered chunks.

Shallow parsing suffices exactly when the downstream task needs which phrases are present and where, but not how they combine — entity extraction, keyword and noun-phrase indexing, and quick approximations of syntactic structure. When the task turns on how phrases relate (which argument attaches to which verb, what modifies what), the flat chunk view is not enough and a full parse, or the dependency parse of the next lesson, is needed.

Footnotes

  1. Jurafsky & Martin, §13.1 and Appendix C — probabilistic context-free grammars: rule probabilities, the most-probable parse, and probabilistic CKY.
  2. Jurafsky & Martin, §12.4.3 and §12.6 — Heads and Head Finding; Lexicalized Grammars: annotating nonterminals with lexical heads and the head child that propagates the head upward.
  3. Jurafsky & Martin, §13.3 — Span-Based Neural Constituency Parsing: scoring spans with a neural classifier over a pretrained encoder, the span representation, and a CKY variant that combines span scores.
  4. Neural constituency parsers. Stern, Andreas, and Klein, A Minimal Span-Based Neural Constituency Parser, ACL (2017) — the span-scoring plus chart-assembly recipe with a margin-based training objective (~91.8 WSJ ). Kitaev and Klein, Constituency Parsing with a Self-Attentive Encoder, ACL (2018) — a transformer encoder over spans with factored content/position attention (~93.6 , ~95.1 with ELMo). Kitaev, Cao, and Klein, Multilingual Constituency Parsing with Self-Attention and Pre-Training, ACL (2019) — a BERT encoder (~95.6 English) and a single multilingual model across ten languages. Gaddy, Stern, and Klein, What's Going On in Neural Constituency Parsers? An Analysis, NAACL (2018) — greedy per-span labeling forms a valid tree ~95% of the time. The reported figures are approximate and drawn from these papers' Penn Treebank evaluations.
  5. Jurafsky & Martin, §13.4 — Evaluating Parsers: PARSEVAL labeled precision, recall, and over constituents, crossing brackets, and evalb.
  6. Jurafsky & Martin, §13.5 — Partial Parsing: partial / shallow parses as a cheaper alternative to full trees, and their use in information extraction, which identifies segments likely to hold valuable information rather than parsing everything.
  7. Jurafsky & Martin, §13.5 — Chunking: flat, non-overlapping base (non-recursive) phrases; the segmenting-and-labeling split; base-NP chunking; base phrases keep the head plus pre-head material and drop post-head modifiers (avoiding attachment ambiguity); training a supervised labeler, extracting chunks from a treebank, and evaluating with precision, recall, and . 2
  8. Jurafsky & Martin, §13.5 (and Ch. 8) — BIO tagging for chunks: a B-type tag beginning each chunk, I-type inside it, and O for tokens outside any chunk, casting chunking as per-token sequence labeling.

╌╌ END ╌╌