Proofs: Probabilistic CKY
These are the human proofs of Probabilistic CKY, at full length.
Probabilistic CKY returns the largest probability of a parse tree and a tree that has it, and it stops full
This proof shows: correctness, termination.
We use the notation of the context-free grammar page and the pseudocode PROBABILISTIC-CKY of the page. The grammar is in Chomsky normal form: each production is with , with , or with on no right side. Each production has a weight ; the proof does not use that the weights of a nonterminal sum to 1. The input is , and .
For a parse tree , is the product of over the nodes of , each node counted with the production it uses. For and , let be the set of parse trees with root and yield , and
with when the set is empty. The set is finite: in Chomsky normal form a tree with yield of length has exactly internal nodes, so there are finitely many such trees, and the maximum exists. The table entry starts at 0, as in the pseudocode.
Lemma 1: the structure of the trees
A tree in is the single node with the leaf , using . For , a tree has a root production and two subtrees and for a unique with , and
Conversely, any such , , and give a tree in with this probability.
Proof. This is the structure part of Lemmas 1 and 2 of the CYK correctness proof: a node labeled with a nonterminal other than an empty yields a nonempty string, the root of a tree with a yield of length 1 must use , and the root of a longer one must use , whose two children yield a nonempty prefix and a nonempty suffix. The product formula is the definition of , split at the root.
Lemma 2: the recurrence
if and 0 otherwise. For ,
where the maximum of an empty set is 0.
Proof. The first part is Lemma 1 for . For , by Lemma 1 the trees of are the combinations of a split , a production , and independent choices of and . Since all factors are nonnegative, the product is nondecreasing in each of and , so for fixed and its maximum is reached with and . If one of the two sets of subtrees is empty, no tree arises from this and production, and the corresponding factor makes the term 0, which does not change a maximum of nonnegative numbers. Taking the maximum over and the productions gives the formula.
This is the principle of optimality: a best tree is built from best subtrees. It needs the monotonicity of the product, which is why weights must be nonnegative.
Lemma 3: the table holds the recurrence
When line L11 is reached, for all and . Moreover, if , then is set and is either (for ) or a triple with , and
Proof. By induction on . For , line L3 sets and the back pointer for every lexical production; if the same production is listed twice, the larger weight is kept. The entries of other nonterminals stay 0. Later iterations write only cells with . So the claim holds by Lemma 2.
For , the cell is written only in the iteration of lines L5 to L10 with and this . In that iteration, lines L7 to L9 go through every pair of a split and a production and compute . The cells read have lengths and , both less than , so by the induction hypothesis they hold and , and is the term of Lemma 2. Line L10 keeps a running maximum: after each step, is the largest term seen so far, or 0, and when it changes, is set to the triple of the term that set it. At the end of the iteration is the maximum of all terms, which is by Lemma 2. If , the last change set the back pointer to a triple whose term equals the final value.
Lemma 4: the tree from the back pointers
If , following the back pointers from (the node with back pointer gets the children and , and a node gets the leaf ) gives a tree with .
Proof. By induction on . For the tree is , with probability . For , the triple of Lemma 3 has , so both and are positive. By induction, the two children give trees and with these probabilities, and by Lemma 1 the combined tree is in with probability . The construction visits nodes, so it stops.
Theorem
PROBABILISTIC-CKY stops and returns , the largest probability of a parse tree of , together with a tree of that probability when it is positive.
Proof. For , the only tree with an empty yield in Chomsky normal form is the node with the production , since every other node yields a nonempty string; line L1 returns its weight, or 0. For , Lemma 3 gives and Lemma 4 gives the tree.
Termination. All loops are bounded: line L2 runs times, and lines L8 to L10 run once for each production and each triple , of which there are . The tree construction visits nodes.
Remarks
The sum version. Replacing the maximum of line L10 by a sum, and the back pointers by nothing, computes , the inside probability. The proof is the same with Lemma 2 read with sums: the sum over the pairs of factors as by distributivity. Both versions are instances of one algorithm over a semiring, (max, ·) and (+, ·).
Log space. Replacing each weight by its logarithm and the products by sums keeps every comparison of line L10, because the logarithm is increasing. Weights equal to 0 become and can be dropped.
Negative weights. Lemma 2 fails for weights of mixed sign: a best tree may then use a subtree of smallest, not largest, value. The implementation rejects negative weights.