Lecture 07
Lecture 07
Processing
Lecture 7: Parsing with Context Free Grammars II.
CKY for PCFGs. Earley Parser.
11/13/2020
COMS W4705
Yassine Benajiba
Recall: Syntactic Ambiguity
S → NP VP NP → she
VP → V NP NP → glasses
VP → VP PP D → the
PP → P NP N → cat
NP →DN N → glasses
NP → NP PP V → saw
S S
P → with
VP[1,6] VP[1,6]
VP[2,4] NP[2,6]
NP PP[4,6] NP PP
NP V D N P NP NP V[1,2] D N P NP
she saw the cat with glasses she saw the cat with glasses
S → NP PP 1.0
VP → VP PP .4
VP → V NP
.6
NP → D N PP →P NP
.7 1.0
D→ the N→cat
NP→ she V→ saw saw cat P→with NP→ glasses
.05 1.0 1.0 .3 1.0 .05
S → NP PP 1.0
VP → V NP .6
NP → NP PP
.2
NP → D N PP →P NP
.7 1.0
D→ the N→cat
NP→ she V→ saw saw cat P→with NP→ glasses
.05 1.0 1.0 .3 1.0 .05
• Unsupervised training:
VP → V NP 1 x .0021 x .6 = .00126
NP → D N PP →P NP
1 x .3 x .7 = .21 1 x 1 x .05 = .05
D→ the N→cat
NP→ she V→ saw saw cat P→with NP→ glasses
.05 1.0 1.0 .3 1.0 .05
CKY for PCFG Parsing
• Let be the set of trees generated by grammar G
starting at nonterminal A, whose yield is string s
Base case:
Use backpointers to retrieve the highest-scoring parse tree (see previous lecture).
Probability of a Sentence
• The Earley parser instead starts at the start symbol and tries
to “guess” derivations top-down.
• for i = 0 to n:
• for each state in Chart[i]:
• if state is of form A →α ·s[i] β [k,i]:
scan(state)
• elif state is of form A →α ·B β [k,i]:
predict(state)
• for i = 0 to n:
• for each state in Chart[i]:
• if state is of form A →α ·s[i] β [k,i]:
scan(state) else then is states of form
A →α · β [k,i], i.e.
• elif state is of form A →α ·B β [k,i]:
predict(state) β is not s[i], in which case we
don’t want to do anything
• elif state is of form A →α · [k,i]
complete(state)
Earley Algorithm - Scan
• The scan operation can only be applied to a state if the dot is
in front of a terminal symbol that matches the next input
terminal.
• For each position on the chart, there are O(N) possible split
points where the dot could be.
• Total: O(N3)
Earley Algorithm -
Some Observations
• How do we recover parse trees?