CYK Parsing Notes
CYK Parsing Notes
Basics
In addition, the CYK algorithm uses the dynamic programming or table filling algorithm.
CNF
CNF Rules
The grammar will be in CNF if each rule has one of the following forms:
Step 1:
Original Grammar
S → NP VP
NP → Det N | N
VP → V NP
N → 'cat' | 'dog'
V → 'chased'
S → NP VP
NP → Det N
VP → V NP
N → 'cat' | 'dog'
V → 'chased'
We construct a CYK table where row i, column j represents the non-terminals that
can derive the substring from position iii to jjj.
Count the number of words in the sentence and construct a matrix accordingly.
1 2 3 4 5
[0,1] [1,2]
0 Det
1 N
2
3
4
Check the CNF rule and find if there are any non-terminal contains Det and V;
Yes, we have :
NP → Det N
1 2 3 4 5
[0,1] [1,2]
0 Det NP
1
N
2
1 2 3 4 5
[0,1] [1,2] [2,3]
0 Det NP
1
N
2 V
4
Next , we have ‘a’ which occurs between 3 and 4 and similarly ‘dog’ occurs between 4
and 5:
1 2 3 4 5
[0,1] [1,2] [2,3] [3,4] [4,5]
0 Det NP
1
N
2 V
3 Det NP
4
N
1 2 3 4 5
[0,1] [1,2] [2,3] [3,4] [4,5]
0 Det NP
1
N
2 V VP
3 Det NP
4
N
Now, check VP and NP in the rule, which is there in S→ NP VP
1 2 3 4 5
[0,1] [1,2] [2,3] [3,4] [4,5]
0 Det NP S
1
N
2 V VP
3 Det NP
4
N
Advantages: