Algorithm Search⌘K

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 G=(V,Σ,P,S)G = (V, \Sigma, P, S) is in Chomsky normal form: each production is A→BCA \to BC with B,C∈VB, C \in V, A→aA \to a with a∈Σa \in \Sigma, or S→εS \to \varepsilon with SS on no right side. Each production rr has a weight q(r)≥0q(r) \ge 0; the proof does not use that the weights of a nonterminal sum to 1. The input is w=a1⋯anw = a_1 \cdots a_n, and wi,j=ai⋯ajw_{i,j} = a_i \cdots a_j.

For a parse tree tt, P(t)P(t) is the product of q(r)q(r) over the nodes of tt, each node counted with the production it uses. For 1≤i≤j≤n1 \le i \le j \le n and A∈VA \in V, let T(A,i,j)\mathcal{T}(A, i, j) be the set of parse trees with root AA and yield wi,jw_{i,j}, and

μ(A,i,j)=max⁡{P(t):t∈T(A,i,j)},\mu(A, i, j) = \max \{ P(t) : t \in \mathcal{T}(A, i, j) \},

with μ(A,i,j)=0\mu(A, i, j) = 0 when the set is empty. The set is finite: in Chomsky normal form a tree with yield of length ℓ≥1\ell \ge 1 has exactly 2ℓ−12\ell - 1 internal nodes, so there are finitely many such trees, and the maximum exists. The table entry π[i,j,A]\pi[i, j, A] starts at 0, as in the pseudocode.

Lemma 1: the structure of the trees

A tree in T(A,i,i)\mathcal{T}(A, i, i) is the single node AA with the leaf aia_i, using A→aiA \to a_i. For i<ji < j, a tree t∈T(A,i,j)t \in \mathcal{T}(A, i, j) has a root production A→BCA \to BC and two subtrees t1∈T(B,i,k)t_1 \in \mathcal{T}(B, i, k) and t2∈T(C,k+1,j)t_2 \in \mathcal{T}(C, k + 1, j) for a unique kk with i≤k<ji \le k < j, and

P(t)=q(A→BC)⋅P(t1)⋅P(t2).P(t) = q(A \to BC) \cdot P(t_1) \cdot P(t_2).

Conversely, any such A→BCA \to BC, kk, t1t_1 and t2t_2 give a tree in T(A,i,j)\mathcal{T}(A, i, j) 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 SS yields a nonempty string, the root of a tree with a yield of length 1 must use A→aA \to a, and the root of a longer one must use A→BCA \to BC, whose two children yield a nonempty prefix and a nonempty suffix. The product formula is the definition of P(t)P(t), split at the root. □\square

Lemma 2: the recurrence

μ(A,i,i)=q(A→ai)\mu(A, i, i) = q(A \to a_i) if A→ai∈PA \to a_i \in P and 0 otherwise. For i<ji < j,

μ(A,i,j)=max⁡i≤k<j max⁡A→BC∈P q(A→BC)⋅μ(B,i,k)⋅μ(C,k+1,j),\mu(A, i, j) = \max_{i \le k < j}\ \max_{A \to BC \in P}\ q(A \to BC) \cdot \mu(B, i, k) \cdot \mu(C, k + 1, j),

where the maximum of an empty set is 0.

Proof. The first part is Lemma 1 for i=ji = j. For i<ji < j, by Lemma 1 the trees of T(A,i,j)\mathcal{T}(A, i, j) are the combinations of a split kk, a production A→BCA \to BC, and independent choices of t1t_1 and t2t_2. Since all factors are nonnegative, the product q⋅P(t1)⋅P(t2)q \cdot P(t_1) \cdot P(t_2) is nondecreasing in each of P(t1)P(t_1) and P(t2)P(t_2), so for fixed kk and A→BCA \to BC its maximum is reached with P(t1)=μ(B,i,k)P(t_1) = \mu(B, i, k) and P(t2)=μ(C,k+1,j)P(t_2) = \mu(C, k + 1, j). If one of the two sets of subtrees is empty, no tree arises from this kk and production, and the corresponding factor μ=0\mu = 0 makes the term 0, which does not change a maximum of nonnegative numbers. Taking the maximum over kk and the productions gives the formula. □\square

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, π[i,j,A]=μ(A,i,j)\pi[i, j, A] = \mu(A, i, j) for all 1≤i≤j≤n1 \le i \le j \le n and A∈VA \in V. Moreover, if μ(A,i,j)>0\mu(A, i, j) > 0, then back[i,j,A]back[i, j, A] is set and is either aia_i (for i=ji = j) or a triple (k,B,C)(k, B, C) with A→BC∈PA \to BC \in P, i≤k<ji \le k < j and

q(A→BC)⋅μ(B,i,k)⋅μ(C,k+1,j)=μ(A,i,j).q(A \to BC) \cdot \mu(B, i, k) \cdot \mu(C, k + 1, j) = \mu(A, i, j).

Proof. By induction on ℓ=j−i+1\ell = j - i + 1. For ℓ=1\ell = 1, line L3 sets π[i,i,A]=q(A→ai)\pi[i, i, A] = q(A \to a_i) and the back pointer aia_i 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 j>ij > i. So the claim holds by Lemma 2.

For ℓ≥2\ell \ge 2, the cell (i,j)(i, j) is written only in the iteration of lines L5 to L10 with len=ℓ\text{len} = \ell and this ii. In that iteration, lines L7 to L9 go through every pair of a split kk and a production A→BCA \to BC and compute p=q(A→BC)⋅π[i,k,B]⋅π[k+1,j,C]p = q(A \to BC) \cdot \pi[i, k, B] \cdot \pi[k + 1, j, C]. The cells read have lengths k−i+1k - i + 1 and j−kj - k, both less than ℓ\ell, so by the induction hypothesis they hold μ(B,i,k)\mu(B, i, k) and μ(C,k+1,j)\mu(C, k + 1, j), and pp is the term of Lemma 2. Line L10 keeps a running maximum: after each step, π[i,j,A]\pi[i, j, A] is the largest term seen so far, or 0, and when it changes, back[i,j,A]back[i, j, A] is set to the triple of the term that set it. At the end of the iteration π[i,j,A]\pi[i, j, A] is the maximum of all terms, which is μ(A,i,j)\mu(A, i, j) by Lemma 2. If μ(A,i,j)>0\mu(A, i, j) > 0, the last change set the back pointer to a triple whose term equals the final value. □\square

Lemma 4: the tree from the back pointers

If μ(A,i,j)>0\mu(A, i, j) > 0, following the back pointers from (i,j,A)(i, j, A) (the node (i,j,A)(i, j, A) with back pointer (k,B,C)(k, B, C) gets the children (i,k,B)(i, k, B) and (k+1,j,C)(k + 1, j, C), and a node (i,i,A)(i, i, A) gets the leaf aia_i) gives a tree t∈T(A,i,j)t \in \mathcal{T}(A, i, j) with P(t)=μ(A,i,j)P(t) = \mu(A, i, j).

Proof. By induction on j−ij - i. For i=ji = j the tree is A→aiA \to a_i, with probability q(A→ai)=μ(A,i,i)q(A \to a_i) = \mu(A, i, i). For i<ji < j, the triple (k,B,C)(k, B, C) of Lemma 3 has q(A→BC)⋅μ(B,i,k)⋅μ(C,k+1,j)=μ(A,i,j)>0q(A \to BC) \cdot \mu(B, i, k) \cdot \mu(C, k + 1, j) = \mu(A, i, j) > 0, so both μ(B,i,k)\mu(B, i, k) and μ(C,k+1,j)\mu(C, k + 1, j) are positive. By induction, the two children give trees t1∈T(B,i,k)t_1 \in \mathcal{T}(B, i, k) and t2∈T(C,k+1,j)t_2 \in \mathcal{T}(C, k + 1, j) with these probabilities, and by Lemma 1 the combined tree is in T(A,i,j)\mathcal{T}(A, i, j) with probability q(A→BC)⋅μ(B,i,k)⋅μ(C,k+1,j)=μ(A,i,j)q(A \to BC) \cdot \mu(B, i, k) \cdot \mu(C, k + 1, j) = \mu(A, i, j). The construction visits 2(j−i+1)−12(j - i + 1) - 1 nodes, so it stops. □\square

Theorem

PROBABILISTIC-CKY stops and returns μ(S,1,n)\mu(S, 1, n), the largest probability of a parse tree of ww, together with a tree of that probability when it is positive.

Proof. For n=0n = 0, the only tree with an empty yield in Chomsky normal form is the node SS with the production S→εS \to \varepsilon, since every other node yields a nonempty string; line L1 returns its weight, or 0. For n≥1n \ge 1, Lemma 3 gives π[1,n,S]=μ(S,1,n)\pi[1, n, S] = \mu(S, 1, n) and Lemma 4 gives the tree.

Termination. All loops are bounded: line L2 runs nn times, and lines L8 to L10 run once for each production and each triple (len,i,k)(\text{len}, i, k), of which there are (n+13)\binom{n + 1}{3}. The tree construction visits 2n−12n - 1 nodes. □\square

Remarks

The sum version. Replacing the maximum of line L10 by a sum, and the back pointers by nothing, computes β(A,i,j)=∑t∈T(A,i,j)P(t)\beta(A, i, j) = \sum_{t \in \mathcal{T}(A, i, j)} P(t), the inside probability. The proof is the same with Lemma 2 read with sums: the sum over the pairs (t1,t2)(t_1, t_2) of q⋅P(t1)⋅P(t2)q \cdot P(t_1) \cdot P(t_2) factors as q⋅β(B,i,k)⋅β(C,k+1,j)q \cdot \beta(B, i, k) \cdot \beta(C, k + 1, j) 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 −∞-\infty 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.

Back to Probabilistic CKY