Cky CNF
Cky CNF
Todays lecture
Parsing strategies
Parsing strategies
Name one reason why bottom-up parsing is inecient? The [search for Spock] was successful.
Parsing strategies
Name one reason why bottom-up parsing is inecient? The [search for Spock] was successful. And for top-down?
Parsing strategies
Name one reason why bottom-up parsing is inecient? The [search for Spock] was successful. And for top-down? Which would you like? That one.
Parsing strategies
Name one reason why bottom-up parsing is inecient? The [search for Spock] was successful. And for top-down? Which would you like? That one. And what makes naive search so inecient?
Parsing strategies
Name one reason why bottom-up parsing is inecient? The [search for Spock] was successful. And for top-down? Which would you like? That one. And what makes naive search so inecient? Theres no way to store intermediate solutions.
CKY algorithm
Cocke-Kasami-Younger (CKY) algorithm: a fast bottom-up parsing algorithm that avoids some of the ineciency associated with purely naive search with the same bottom-up strategy.
CKY algorithm
Cocke-Kasami-Younger (CKY) algorithm: a fast bottom-up parsing algorithm that avoids some of the ineciency associated with purely naive search with the same bottom-up strategy.
CKY algorithm
Cocke-Kasami-Younger (CKY) algorithm: a fast bottom-up parsing algorithm that avoids some of the ineciency associated with purely naive search with the same bottom-up strategy. Intermediate solutions are stored.
CKY algorithm
Cocke-Kasami-Younger (CKY) algorithm: a fast bottom-up parsing algorithm that avoids some of the ineciency associated with purely naive search with the same bottom-up strategy. Intermediate solutions are stored. Only intermediate solutions that contribute to a full parse are further pursued.
CKY algorithm
Cocke-Kasami-Younger (CKY) algorithm: a fast bottom-up parsing algorithm that avoids some of the ineciency associated with purely naive search with the same bottom-up strategy. Intermediate solutions are stored. Only intermediate solutions that contribute to a full parse are further pursued. The CKY is picky about what type of grammar it accepts.
CKY algorithm
Cocke-Kasami-Younger (CKY) algorithm: a fast bottom-up parsing algorithm that avoids some of the ineciency associated with purely naive search with the same bottom-up strategy. Intermediate solutions are stored. Only intermediate solutions that contribute to a full parse are further pursued. The CKY is picky about what type of grammar it accepts. We require that our grammar be in a special form, known as Chomsky Normal Form (CNF).
CKY algorithm
Cocke-Kasami-Younger (CKY) algorithm: a fast bottom-up parsing algorithm that avoids some of the ineciency associated with purely naive search with the same bottom-up strategy. Intermediate solutions are stored. Only intermediate solutions that contribute to a full parse are further pursued. The CKY is picky about what type of grammar it accepts. We require that our grammar be in a special form, known as Chomsky Normal Form (CNF). The rationale is to ll in a chart with the solutions to the subproblems encountered in the bottom-up parsing process.
Scott Farrar CLMA, University of Washington CKY Algorithm, Chomsky Normal Form
Dynamic programming
Denition Dynamic programming: a method of reducing the runtime of algorithms by discovering solutions to subproblems along the way to the solution of the main problem; to optimally plan a multi-stage process good for problems with overlapping subproblems generally involves the caching of partial results in a table for later retrieval many application (outside of NLP) What are the subproblems for the parsing task?
Denition A well-formed substring table is a data structure containing partial constituency structures. It may be represented as either a chart or a graph.
the DT1
brown JJ2
For an input of length=n, create a matrix (n + 1 x n + 1), indexed from 0 to n. Each cell in the matrix [i , j ] is the set of all categories of constituents spanning from position i to j . The algorithm forces you to ll in the table in the most ecient way. Process cells left to right (across columns), bottom to top (backwards across rows).
the DT1
brown JJ2
CKY: assumptions
Critical observation: any portion of the input string spanning i to j can be split at k , and structure can then be built using sub-solutions spanning i to k and sub-solutions spanning k to j . Example 0 the 1 brown 2 dog 3 k = 1: possible constituents are [0,1] and [1,3] k = 2: possible constituents are [0,2] and [2,3]
Simple grammar
S NP VBZ S NP VP VP VP PP VP VBZ NP VP VBZ PP VP VBZ NNS VP VBZ VP VP VBP NP VP VBP PP NP DT NN NP DT NNS PP IN NP DT the NN chef NNS sh NNS chopsticks VBP sh VBZ eats IN with
chef 2 [1,2]
eats 3
sh 4
with 5
the 6
chopsticks 7
[2,3] [3,4] [4,5] [5,6] [6,7] numbering of cells: [i,j]s represent spans.
the chef eats sh with the chopsticks 0 1 2 3 4 5 6 7 0 1 [1,2] 2 3 4 5 6 Notice how the spans (e.g, [1,2]) dier from the word indices (e.g, chef, 2).
0 0
the 1 DT [0,1]
chef 2
eats 3
sh 4
with 5
the 6
chopsticks 7
0 0
the 1 DT [0,1]
chef 2
eats 3
sh 4
with 5
the 6
chopsticks 7
0 0 1
the 1 DT [0,1]
chef 2 NP [0,2]
eats 3
sh 4
with 5
the 6
chopsticks 7
0 0 1 2
the 1 DT [0,1]
eats 3
sh 4
with 5
the 6
chopsticks 7
0 0 1 2
the 1 DT [0,1]
eats 3 S [0,3]
sh 4
with 5
the 6
chopsticks 7
3 4 5 6 Found an S: [0,2],[2,3]
0 0 1 2 3
the 1 DT [0,1]
eats 3 S [0,3]
sh 4
with 5
the 6
chopsticks 7
4 5 6 sh is labelled NNS
0 0 1 2 3
the 1 DT [0,1]
eats 3 S [0,3]
sh 4
with 5
the 6
chopsticks 7
4 5 6 sh is labelled VBP
0 0 1 2 3
the 1 DT [0,1]
eats 3 S [0,3]
sh 4
with 5
the 6
chopsticks 7
VBZ [2,3]
0 0 1 2 3
the 1 DT [0,1]
eats 3 S [0,3]
sh 4 S [0,4]
with 5
the 6
chopsticks 7
VBZ [2,3]
4 5 6 Found an S: [0,2],[2,4]
0 0 1 2 3
the 1 DT [0,1]
eats 3 S [0,3]
sh 4 S [0,4]
with 5
the 6
chopsticks 7
VBZ [2,3]
4 5 6 with is labelled IN
0 0 1 2 3
the 1 DT [0,1]
eats 3 S [0,3]
sh 4 S [0,4]
with 5
the 6
chopsticks 7
VBZ [2,3]
4 5 6 the is labelled DT
0 0 1 2 3 4 5 6
the 1 DT [0,1]
eats 3 S [0,3]
sh 4 S [0,4]
with 5
the 6
chopsticks 7
VBZ [2,3]
0 0 1 2 3 4 5 6
the 1 DT [0,1]
eats 3 S [0,3]
sh 4 S [0,4]
with 5
the 6
chopsticks 7
VBZ [2,3]
0 0 1 2 3 4 5 6
the 1 DT [0,1]
eats 3 S [0,3]
sh 4 S [0,4]
with 5
the 6
chopsticks 7
VBZ [2,3]
0 0 1 2 3 4 5 6
the 1 DT [0,1]
eats 3 S [0,3]
sh 4 S [0,4]
with 5
the 6
chopsticks 7
VBZ [2,3]
VP [2,4] NNS,VBP [3,4] IN [4,5] DT [5,6] VP [3,7] PP [4,7] NP [5,7] NNS [6,7]
0 0 1 2 3 4 5 6
the 1 DT [0,1]
eats 3 S [0,3]
sh 4 S [0,4]
with 5
the 6
chopsticks 7
VBZ [2,3]
0 0 1 2 3 4 5 6
the 1 DT [0,1]
eats 3 S [0,3]
sh 4 S [0,4]
with 5
the 6
chopsticks 7
VBZ [2,3]
0 0 1 2 3 4 5 6
the 1 DT [0,1]
eats 3 S [0,3]
sh 4 S [0,4]
with 5
the 6
chopsticks 7 S [0,7]
VBZ [2,3]
0 0 1 2 3 4 5 6
the 1 DT [0,1]
eats 3 S [0,3]
sh 4 S [0,4]
with 5
the 6
VBZ [2,3]
0 0 1 2 3 4 5 6
the 1 DT [0,1]
eats 3 S [0,3]
sh 4 S [0,4]
with 5
the 6
VBZ [2,3]
Found a second S node: also [0,2] [2,7] Recognition algorithm returns True when a root node is found in [0,n]
Returning the full parse requires storing more in a cell than just a node label. We also require back-pointers to constituents of that node. We could also store whole trees, but less space ecient. For parsing, we must add an extra step to the algorithm:
Returning the full parse requires storing more in a cell than just a node label. We also require back-pointers to constituents of that node. We could also store whole trees, but less space ecient. For parsing, we must add an extra step to the algorithm: follow pointers and return the parse
Eciency The CKY can be performed in cubic time: O (n3 ), where n=number of words in sentence. The complexity of the inner most loop is bounded by the square of the number of non-terminals. The more rules, the less ecient; but this increases at a constant rate L = r 2 where r is the number of non-terminals.
Binary tree
Grammar equivalence
Any CFG can be converted to a weakly equivalent grammar in CNF.
Grammar equivalence
Any CFG can be converted to a weakly equivalent grammar in CNF. Denition Weak equivalence: Two grammars are weakly equivalent if they generate the same set of strings (sentences). Transforming a grammar to CNF results in a new grammar that is weakly equivalent.
Grammar equivalence
Any CFG can be converted to a weakly equivalent grammar in CNF. Denition Weak equivalence: Two grammars are weakly equivalent if they generate the same set of strings (sentences). Transforming a grammar to CNF results in a new grammar that is weakly equivalent. Denition Strong equivalence: Two grammars are strongly equivalent if they generate the same set of strings AND the same structures over those strings. If only the variable names are di. then the grammar are said to be isomorphic.
Scott Farrar CLMA, University of Washington CKY Algorithm, Chomsky Normal Form
Use new symbols (binarization): X 1, X 2, . . . , Y 3 S NP VP PUNC becomes: S NP X 1, X 1 VP PUNC Delete a symbol (unary collapsing): SBAR S , S NP VP becomes SBAR NP VP
Removing unit-productions (unary collapsing): while there is a unit-production A B , Remove A B . foreach B u , add A u .
Removing unit-productions (unary collapsing): while there is a unit-production A B , Remove A B . foreach B u , add A u .
Remove terminals from mixed rules foreach production A B1 B2 ...Bk , containing a terminal x Add new non-terminal/production X 1 x (unless it has already been added) Replace every Bi = x with X 1
Removing unit-productions (unary collapsing): while there is a unit-production A B , Remove A B . foreach B u , add A u .
Remove terminals from mixed rules foreach production A B1 B2 ...Bk , containing a terminal x Add new non-terminal/production X 1 x (unless it has already been added) Replace every Bi = x with X 1
Remove rules with more than two nonterminals on the RHS (binarization) foreach rule p of form A B1 B2 ...Bk replace p with A B1 X 1, X 1 B2 X 2, X 2 B3 X 3, ..., X (k 2) Bk 1 Bk (Xi s are new variables.)
Scott Farrar CLMA, University of Washington CKY Algorithm, Chomsky Normal Form
Binarization
A sample CFG
S NP VP PUNC
A sample CFG
S NP VP PUNC
(non-binary)
A sample CFG
S NP VP PUNC S S and S
(non-binary)
A sample CFG
S NP VP PUNC S S and S
(non-binary) (mixed)
A sample CFG
S NP VP PUNC S S and S NP DT NP
(non-binary) (mixed)
A sample CFG
S NP VP PUNC S S and S NP DT NP
A sample CFG
S NP VP PUNC S S and S NP DT NP NP NN
A sample CFG
S NP VP PUNC S S and S NP DT NP NP NN
A sample CFG
A sample CFG
A sample CFG
A sample CFG
A sample CFG
A sample CFG
A sample CFG
A sample CFG
(non-binary) (mixed) (OK) (unit production) (OK) (OK) (OK) (unit production)
A sample CFG
(non-binary) (mixed) (OK) (unit production) (OK) (OK) (OK) (unit production)
A sample CFG
(non-binary) (mixed) (OK) (unit production) (OK) (OK) (OK) (unit production) (OK)
A sample CFG
S NP VP PUNC S S and S NP DT NP NP NN NN dog NN cat VP VBZ NP VP VBZ VBZ sleeps VBZ eats
(non-binary) (mixed) (OK) (unit production) (OK) (OK) (OK) (unit production) (OK)
A sample CFG
S NP VP PUNC S S and S NP DT NP NP NN NN dog NN cat VP VBZ NP VP VBZ VBZ sleeps VBZ eats
(non-binary) (mixed) (OK) (unit production) (OK) (OK) (OK) (unit production) (OK) (OK)
A sample CFG
S NP VP PUNC S S and S NP DT NP NP NN NN dog NN cat VP VBZ NP VP VBZ VBZ sleeps VBZ eats DT the
(non-binary) (mixed) (OK) (unit production) (OK) (OK) (OK) (unit production) (OK) (OK)
A sample CFG
S NP VP PUNC S S and S NP DT NP NP NN NN dog NN cat VP VBZ NP VP VBZ VBZ sleeps VBZ eats DT the
(non-binary) (mixed) (OK) (unit production) (OK) (OK) (OK) (unit production) (OK) (OK) (OK)
Non-CNF grammar
CNF grammar -
Action
Non-CNF grammar NP NN
CNF grammar -
Action
CNF grammar -
Action
CNF grammar -
Action
CNF grammar -
Action
NP dog
(collapse rule)
CNF grammar -
Action
NP dog NP cat
CNF grammar -
Action
CNF grammar -
Action
CNF grammar -
Action
CNF grammar -
Action
Non-CNF grammar
CNF grammar -
Action
CNF grammar -
Action
CNF grammar -
Action
CNF grammar S S X1
CNF grammar S S X1 X1 X2 S
Non-CNF grammar
CNF grammar -
Action
CNF grammar -
Action
CNF grammar S NP X 3
NP DT NP
NP DT NP
NP DT NP VP VBZ NP
NP DT NP VP VBZ NP
NP DT NP VP VBZ NP DT the
NP DT NP VP VBZ NP DT the
CFG in CNF
Homework 2 discussion