Three Useful PCFG Tasks
1
PCFG: Most Likely Derivation
2
S → NP VP
S → VP
NP → Det A N
NP → NP PP
NP → PropN
A → ε
A → Adj A
PP → Prep NP
VP → V NP
VP → VP PP
0.9
0.1
0.5
0.3
0.2
0.6
0.4
1.0
0.7
0.3
English
PCFG
Parser
John liked the dog in the pen.
S
NP VP
John V NP
liked the dog in the pen
Probabilistic CKY
Probabilistic Grammar Conversion
S → NP VP
S → Aux NP VP
S → VP
NP → Pronoun
NP → Proper-Noun
NP → Det Nominal
Nominal → Noun
Nominal → Nominal Noun
Nominal → Nominal PP
VP → Verb
VP → Verb NP
VP → VP PP
PP → Prep NP
Original Grammar
Chomsky Normal Form
S → NP VP
S → X1 VP
X1 → Aux NP
S → book | include | prefer
0.01 0.004 0.006
S → Verb NP
S → VP PP
NP → I | he | she | me
0.1 0.02 0.02 0.06
NP → Houston | NWA
0.16 .04
NP → Det Nominal
Nominal → book | flight | meal | money
0.03 0.15 0.06 0.06
Nominal → Nominal Noun
Nominal → Nominal PP
VP → book | include | prefer
0.1 0.04 0.06
VP → Verb NP
VP → VP PP
PP → Prep NP
0.8
0.1
0.1
0.2
0.2
0.6
0.3
0.2
0.5
0.2
0.5
0.3
1.0
0.8
0.1
1.0
0.05
0.03
0.6
0.2
0.5
0.5
0.3
1.0
Probabilistic CKY Parser
5
Book the flight through Houston
S :.01, VP:.1,
Verb:.5
Nominal:.03
Noun:.1
Det:.6
Nominal:.15
Noun:.5
None
NP:.6*.6*.15
=.054
S → NP VP
S → X1 VP
X1 → Aux NP
S → book | include | prefer
0.01 0.004 0.006
S → Verb NP
S → VP PP
NP → I | he | she | me
0.1 0.02 0.02 0.06
NP → Houston | NWA
0.16 .04
NP → Det Nominal
Nominal → book | flight | meal | money
0.03 0.15 0.06 0.06
Nominal → Nominal Noun
Nominal → Nominal PP
VP → book | include | prefer
0.1 0.04 0.06
VP → Verb NP
VP → VP PP
PP → Prep NP
Det → the | a
.6 .4
0.8
0.1
1.0
0.05
0.03
0.6
0.2
0.5
0.5
0.3
1.0
Probabilistic CKY Parser
6
Book the flight through Houston
S :.01, VP:.1,
Verb:.5
Nominal:.03
Noun:.1
Det:.6
Nominal:.15
Noun:.5
None
NP:.6*.6*.15
=.054
VP:.5*.5*.054
=.0135
S → NP VP
S → X1 VP
X1 → Aux NP
S → book | include | prefer
0.01 0.004 0.006
S → Verb NP
S → VP PP
NP → I | he | she | me
0.1 0.02 0.02 0.06
NP → Houston | NWA
0.16 .04
NP → Det Nominal
Nominal → book | flight | meal | money
0.03 0.15 0.06 0.06
Nominal → Nominal Noun
Nominal → Nominal PP
VP → book | include | prefer
0.1 0.04 0.06
VP → Verb NP
VP → VP PP
PP → Prep NP
Det → the | a
.6 .4
0.8
0.1
1.0
0.05
0.03
0.6
0.2
0.5
0.5
0.3
1.0
Probabilistic CKY Parser
7
Book the flight through Houston
S :.01, VP:.1,
Verb:.5
Nominal:.03
Noun:.1
Det:.6
Nominal:.15
Noun:.5
None
NP:.6*.6*.15
=.054
VP:.5*.5*.054
=.0135
S:.05*.5*.054
=.00135
S → NP VP
S → X1 VP
X1 → Aux NP
S → book | include | prefer
0.01 0.004 0.006
S → Verb NP
S → VP PP
NP → I | he | she | me
0.1 0.02 0.02 0.06
NP → Houston | NWA
0.16 .04
NP → Det Nominal
Nominal → book | flight | meal | money
0.03 0.15 0.06 0.06
Nominal → Nominal Noun
Nominal → Nominal PP
VP → book | include | prefer
0.1 0.04 0.06
VP → Verb NP
VP → VP PP
PP → Prep NP
Det → the | a
.6 .4
0.8
0.1
1.0
0.05
0.03
0.6
0.2
0.5
0.5
0.3
1.0
Probabilistic CKY Parser
8
Book the flight through Houston
S :.01, VP:.1,
Verb:.5
Nominal:.03
Noun:.1
Det:.6
Nominal:.15
Noun:.5
None
NP:.6*.6*.15
=.054
VP:.5*.5*.054
=.0135
S:.05*.5*.054
=.00135
None
None
None
Prep:.2
S → NP VP
S → X1 VP
X1 → Aux NP
S → book | include | prefer
0.01 0.004 0.006
S → Verb NP
S → VP PP
NP → I | he | she | me
0.1 0.02 0.02 0.06
NP → Houston | NWA
0.16 .04
NP → Det Nominal
Nominal → book | flight | meal | money
0.03 0.15 0.06 0.06
Nominal → Nominal Noun
Nominal → Nominal PP
VP → book | include | prefer
0.1 0.04 0.06
VP → Verb NP
VP → VP PP
PP → Prep NP
Det → the | a
.6 .4
0.8
0.1
1.0
0.05
0.03
0.6
0.2
0.5
0.5
0.3
1.0
Probabilistic CKY Parser
9
Book the flight through Houston
S :.01, VP:.1,
Verb:.5
Nominal:.03
Noun:.1
Det:.6
Nominal:.15
Noun:.5
None
NP:.6*.6*.15
=.054
VP:.5*.5*.054
=.0135
S:.05*.5*.054
=.00135
None
None
None
Prep:.2
NP:.16
PropNoun:.8
PP:1.0*.2*.16
=.032
S → NP VP
S → X1 VP
X1 → Aux NP
S → book | include | prefer
0.01 0.004 0.006
S → Verb NP
S → VP PP
NP → I | he | she | me
0.1 0.02 0.02 0.06
NP → Houston | NWA
0.16 .04
NP → Det Nominal
Nominal → book | flight | meal | money
0.03 0.15 0.06 0.06
Nominal → Nominal Noun
Nominal → Nominal PP
VP → book | include | prefer
0.1 0.04 0.06
VP → Verb NP
VP → VP PP
PP → Prep NP
Det → the | a
.6 .4
0.8
0.1
1.0
0.05
0.03
0.6
0.2
0.5
0.5
0.3
1.0
Probabilistic CKY Parser
10
Book the flight through Houston
S :.01, VP:.1,
Verb:.5
Nominal:.03
Noun:.1
Det:.6
Nominal:.15
Noun:.5
None
NP:.6*.6*.15
=.054
VP:.5*.5*.054
=.0135
S:.05*.5*.054
=.00135
None
None
None
Prep:.2
NP:.16
PropNoun:.8
PP:1.0*.2*.16
=.032
Nominal:
.5*.15*.032
=.0024
S → NP VP
S → X1 VP
X1 → Aux NP
S → book | include | prefer
0.01 0.004 0.006
S → Verb NP
S → VP PP
NP → I | he | she | me
0.1 0.02 0.02 0.06
NP → Houston | NWA
0.16 .04
NP → Det Nominal
Nominal → book | flight | meal | money
0.03 0.15 0.06 0.06
Nominal → Nominal Noun
Nominal → Nominal PP
VP → book | include | prefer
0.1 0.04 0.06
VP → Verb NP
VP → VP PP
PP → Prep NP
Det → the | a
.6 .4
0.8
0.1
1.0
0.05
0.03
0.6
0.2
0.5
0.5
0.3
1.0
Probabilistic CKY Parser
11
Book the flight through Houston
S :.01, VP:.1,
Verb:.5
Nominal:.03
Noun:.1
Det:.6
Nominal:.15
Noun:.5
None
NP:.6*.6*.15
=.054
VP:.5*.5*.054
=.0135
S:.05*.5*.054
=.00135
None
None
None
Prep:.2
NP:.16
PropNoun:.8
PP:1.0*.2*.16
=.032
Nominal:
.5*.15*.032
=.0024
NP:.6*.6*
.0024
=.000864
S → NP VP
S → X1 VP
X1 → Aux NP
S → book | include | prefer
0.01 0.004 0.006
S → Verb NP
S → VP PP
NP → I | he | she | me
0.1 0.02 0.02 0.06
NP → Houston | NWA
0.16 .04
NP → Det Nominal
Nominal → book | flight | meal | money
0.03 0.15 0.06 0.06
Nominal → Nominal Noun
Nominal → Nominal PP
VP → book | include | prefer
0.1 0.04 0.06
VP → Verb NP
VP → VP PP
PP → Prep NP
Det → the | a
.6 .4
0.8
0.1
1.0
0.05
0.03
0.6
0.2
0.5
0.5
0.3
1.0
Probabilistic CKY Parser
12
Book the flight through Houston
S :.01, VP:.1,
Verb:.5
Nominal:.03
Noun:.1
Det:.6
Nominal:.15
Noun:.5
None
NP:.6*.6*.15
=.054
VP:.5*.5*.054
=.0135
S:.05*.5*.054
=.00135
None
None
None
Prep:.2
NP:.16
PropNoun:.8
PP:1.0*.2*.16
=.032
Nominal:
.5*.15*.032
=.0024
NP:.6*.6*
.0024
=.000864
S:.05*.5*
.000864
=.0000216
S → NP VP
S → X1 VP
X1 → Aux NP
S → book | include | prefer
0.01 0.004 0.006
S → Verb NP
S → VP PP
NP → I | he | she | me
0.1 0.02 0.02 0.06
NP → Houston | NWA
0.16 .04
NP → Det Nominal
Nominal → book | flight | meal | money
0.03 0.15 0.06 0.06
Nominal → Nominal Noun
Nominal → Nominal PP
VP → book | include | prefer
0.1 0.04 0.06
VP → Verb NP
VP → VP PP
PP → Prep NP
Det → the | a
.6 .4
0.8
0.1
1.0
0.05
0.03
0.6
0.2
0.5
0.5
0.3
1.0
Probabilistic CKY Parser
13
Book the flight through Houston
S :.01, VP:.1,
Verb:.5
Nominal:.03
Noun:.1
Det:.6
Nominal:.15
Noun:.5
None
NP:.6*.6*.15
=.054
VP:.5*.5*.054
=.0135
S:.05*.5*.054
=.00135
None
None
None
Prep:.2
NP:.16
PropNoun:.8
PP:1.0*.2*.16
=.032
Nominal:
.5*.15*.032
=.0024
NP:.6*.6*
.0024
=.000864
S:.0000216
S:.03*.0135*
.032
=.00001296
S → NP VP
S → X1 VP
X1 → Aux NP
S → book | include | prefer
0.01 0.004 0.006
S → Verb NP
S → VP PP
NP → I | he | she | me
0.1 0.02 0.02 0.06
NP → Houston | NWA
0.16 .04
NP → Det Nominal
Nominal → book | flight | meal | money
0.03 0.15 0.06 0.06
Nominal → Nominal Noun
Nominal → Nominal PP
VP → book | include | prefer
0.1 0.04 0.06
VP → Verb NP
VP → VP PP
PP → Prep NP
Det → the | a
.6 .4
0.8
0.1
1.0
0.05
0.03
0.6
0.2
0.5
0.5
0.3
1.0
Probabilistic CKY Parser
14
Book the flight through Houston
S :.01, VP:.1,
Verb:.5
Nominal:.03
Noun:.1
Det:.6
Nominal:.15
Noun:.5
None
NP:.6*.6*.15
=.054
VP:.5*.5*.054
=.0135
S:.05*.5*.054
=.00135
None
None
None
Prep:.2
NP:.16
PropNoun:.8
PP:1.0*.2*.16
=.032
Nominal:
.5*.15*.032
=.0024
NP:.6*.6*
.0024
=.000864
S:.0000216
Pick most probable
parse, i.e. take max to
combine probabilities
of multiple derivations
of each constituent in
each cell.
PCFG: Observation Likelihood
15
S → NP VP
S → VP
NP → Det A N
NP → NP PP
NP → PropN
A → ε
A → Adj A
PP → Prep NP
VP → V NP
VP → VP PP
0.9
0.1
0.5
0.3
0.2
0.6
0.4
1.0
0.7
0.3
English
The dog big barked.
The big dog barked
O1
O2
?
?
P(O2 | English) > P(O1 | English) ?
Inside Algorithm
16
Probabilistic CKY Parser �for Inside Computation
17
Book the flight through Houston
S :.01, VP:.1,
Verb:.5
Nominal:.03
Noun:.1
Det:.6
Nominal:.15
Noun:.5
None
NP:.6*.6*.15
=.054
VP:.5*.5*.054
=.0135
S:.05*.5*.054
=.00135
None
None
None
Prep:.2
NP:.16
PropNoun:.8
PP:1.0*.2*.16
=.032
Nominal:
.5*.15*.032
=.0024
NP:.6*.6*
.0024
=.000864
S:.0000216
S:..00001296
Probabilistic CKY Parser �for Inside Computation
18
Book the flight through Houston
S :.01, VP:.1,
Verb:.5
Nominal:.03
Noun:.1
Det:.6
Nominal:.15
Noun:.5
None
NP:.6*.6*.15
=.054
VP:.5*.5*.054
=.0135
S:.05*.5*.054
=.00135
None
None
None
Prep:.2
NP:.16
PropNoun:.8
PP:1.0*.2*.16
=.032
Nominal:
.5*.15*.032
=.0024
NP:.6*.6*
.0024
=.000864
+.0000216
=.00003456
S: .00001296
Sum probabilities
of multiple derivations
of each constituent in
each cell.
PCFG: Supervised Training
19
.
.
.
Tree Bank
Supervised
PCFG
Training
S → NP VP
S → VP
NP → Det A N
NP → NP PP
NP → PropN
A → ε
A → Adj A
PP → Prep NP
VP → V NP
VP → VP PP
0.9
0.1
0.5
0.3
0.2
0.6
0.4
1.0
0.7
0.3
English
S
NP VP
John V NP PP
put the dog in the pen
S
NP VP
John V NP PP
put the dog in the pen
Estimating Production Probabilities
20
PCFG: Maximum Likelihood Training
21
PCFG: Maximum Likelihood Training
22
John ate the apple
A dog bit Mary
Mary hit the dog
John gave Mary the cat.
.
.
.
Training Sentences
PCFG
Training
S → NP VP
S → VP
NP → Det A N
NP → NP PP
NP → PropN
A → ε
A → Adj A
PP → Prep NP
VP → V NP
VP → VP PP
0.9
0.1
0.5
0.3
0.2
0.6
0.4
1.0
0.7
0.3
English
Learn the grammar itself!
Inside-Outside
Vanilla PCFG Limitations: Missing Lexical Context
24
Example of Importance of Lexicalization
25
S → NP VP
S → VP
NP → Det A N
NP → NP PP
NP → PropN
A → ε
A → Adj A
PP → Prep NP
VP → V NP
VP → VP PP
0.9
0.1
0.5
0.3
0.2
0.6
0.4
1.0
0.7
0.3
English
PCFG
Parser
S
NP VP
John V NP PP
put the dog in the pen
John put the dog in the pen.
Example of Importance of Lexicalization
26
S → NP VP
S → VP
NP → Det A N
NP → NP PP
NP → PropN
A → ε
A → Adj A
PP → Prep NP
VP → V NP
VP → VP PP
0.9
0.1
0.5
0.3
0.2
0.6
0.4
1.0
0.7
0.3
English
PCFG
Parser
S
NP VP
John V NP
put the dog in the pen
X
John put the dog in the pen.
Head Words
Lexicalized Productions
S
VP
VBD NP
DT Nominal
Nominal PP
liked
IN NP
in
the
dog
NN
DT Nominal
NN
the
pen
NNP
NP
John
pen-NN
pen-NN
in-IN
dog-NN
dog-NN
dog-NN
liked-VBD
liked-VBD
John-NNP
Nominaldog-NN → Nominaldog-NN PPin-IN
Lexicalized Productions
S
VP
VP PP
DT Nominal
put
IN NP
in
the
dog
NN
DT Nominal
NN
the
pen
NNP
NP
John
pen-NN
pen-NN
in-IN
dog-NN
dog-NN
put-VBD
put-VBD
John-NNP
NP
VBD
put-VBD
VPput-VBD → VPput-VBD PPin-IN
Evaluation of Parsing: Treebanks
30
First WSJ Sentence
31
( (S
(NP-SBJ
(NP (NNP Pierre) (NNP Vinken) )
(, ,)
(ADJP
(NP (CD 61) (NNS years) )
(JJ old) )
(, ,) )
(VP (MD will)
(VP (VB join)
(NP (DT the) (NN board) )
(PP-CLR (IN as)
(NP (DT a) (JJ nonexecutive) (NN director) ))
(NP-TMP (NNP Nov.) (CD 29) )))
(. .) ))
Parsing Evaluation Metrics
32
Constituent: N,<start>, <end>
Computing Evaluation Metrics
Correct Tree T
S
VP
Verb NP
Det Nominal
Nominal PP
book
Prep NP
through
Houston
Proper-Noun
the
flight
Noun
Computed Tree P
VP
Verb NP
Det Nominal
book
Prep NP
through
Houston
Proper-Noun
the
flight
Noun
S
VP
PP
# Constituents: 12
# Constituents: 12
# Correct Constituents: 10
Recall = 10/12= 83.3%
Precision = 10/12=83.3%
F1 = 83.3%
Treebank Results
34
>96% with RNNs/LSTMs/Transformers
Near-perfect accuracy now (other than
human errors)
Dependency Grammars
35
liked
John
dog
pen
in
the
the
liked
John
dog
pen
in
the
the
nsubj
dobj
det
det
Typed
dependency
parse
Dependency Graph from Parse Tree
36
S
VP
VBD NP
DT Nominal
Nominal PP
liked
IN NP
in
the
dog
NN
DT Nominal
NN
the
pen
NNP
NP
John
pen-NN
pen-NN
in-IN
dog-NN
dog-NN
dog-NN
liked-VBD
liked-VBD
John-NNP
liked
John
dog
pen
in
the
the
Head of a VP is the main verb
Head of an NP is the main noun
Head of a PP is the preposition
Head of a sentence is the head of its VP