CKY Parsing & CNF Conversion
LING 571 — Deep Processing Techniques for NLP October 2, 2019 Shane Steinert-Threlkeld
1
CKY Parsing & CNF Conversion LING 571 Deep Processing - - PowerPoint PPT Presentation
CKY Parsing & CNF Conversion LING 571 Deep Processing Techniques for NLP October 2, 2019 Shane Steinert-Threlkeld 1 Announcements HW #1 due tonight at 11:00pm . If you want to use python3.6 on Patas:
LING 571 — Deep Processing Techniques for NLP October 2, 2019 Shane Steinert-Threlkeld
1
everything via Anaconda (download with wget).]
2
from typing import List from nltk.grammar import Production def fix_hybrid_production(hybrid_prod: Production) -> List[Production]: …
def fix_hybrid_productions(hybrid_prod): “”” This function takes a hybrid production and returns a list of new CNF productions :type hybrid_prod: Production :rtype: list[Production] “””
3
4
a language, and employ them in automatic parsing?
5
6
7
that derive input
8
production
9
10
11
12
13
Jurafsky & Martin, Speech and Language Processing, p.390
Grammar
Lexicon
S → NP VP Det → that | this | a S → Aux NP VP Noun → book | flight | meal | money S → VP Verb → book | include | prefer NP → Pronoun Pronoun → I | she | me NP → Proper-Noun Proper-Noun → Houston | NWA NP → Det Nominal Aux → does Nominal → Noun Preposition → from | to | on | near | through Nominal → Nominal Noun Nominal → Nominal PP VP → Verb VP → Verb NP VP → Verb NP PP VP → Verb PP VP → VP PP PP → Preposition NP
14
15
S S NP VP S NP VP Aux Start State 1 Rule 2 Rules S VP S VP S VP S NP VP Aux S NP VP Aux Det Nom PropN V NP V S NP VP PropN S NP VP Det Nom
16
S S NP VP S NP VP Aux Start State 1 Rule 2 Rules S VP S VP S VP S NP VP Aux S NP VP Aux Det Nom PropN V NP V S NP VP PropN S NP VP Det Nom
17
18
19
Book that flight
20
Book that flight Book that flight Noun Det Noun Book that flight Verb Det Noun
21
Book that flight Book that flight Noun Det Noun Book that flight Verb Det Noun Book that flight Noun Det Noun Nominal Nominal Book that flight Verb Det Noun Nominal
22
Book that flight Book that flight Noun Det Noun Book that flight Verb Det Noun Book that flight Noun Det Noun Nominal Nominal Book that flight Verb Det Noun Nominal Book that flight Noun Det Noun Nominal Nominal NP Book that flight Verb Det Noun Nominal VP Book that flight Verb Det Noun Nominal NP
23
Book that flight Book that flight Noun Det Noun Book that flight Verb Det Noun Book that flight Noun Det Noun Nominal Nominal Book that flight Verb Det Noun Nominal Book that flight Noun Det Noun Nominal Nominal NP Book that flight Verb Det Noun Nominal VP Book that flight Verb Det Noun Nominal NP Book that flight Verb Det Noun Nominal NP VP Book that flight Verb Det Noun Nominal NP VP
24
25
S S NP VP S NP VP Aux S VP S VP S VP S NP VP Aux S NP VP Aux Det Nom PropN V NP V S NP VP PropN S NP VP Det Nom
None of these nodes can produce book as first terminal
26
Book that flight Book that flight Noun Det Noun Book that flight Verb Det Noun Book that flight Noun Det Noun Nominal Nominal Book that flight Verb Det Noun Nominal Book that flight Noun Det Noun Nominal Nominal NP Book that flight Verb Det Noun Nominal VP Book that flight Verb Det Noun Nominal NP Book that flight Verb Det Noun Nominal NP VP Book that flight Verb Det Noun Nominal NP VP
None of these nodes lead lead to a RHS that can be combined with S on the LHS.
27
28
“One morning, I shot an elephant in my pajamas. How he got into my pajamas, I’ll never know.” — Groucho Marx
29
30
S NP Pronoun I VP Verb shot NP Det an Nominal Nominal Noun elephant PP in my pajamas S NP Pronoun I VP VP Verb shot NP Det an Nominal Nominal Noun elephant PP in my pajamas
31
32
NP JJ
NNS NNS men CONJ and NNS women NP NP JJ
NNS men CONJ and NP women
[old men] and [women]
(Only the men are old) (Both the men and women are old)
“old men and women”
33
34
35
36
VP ... V thought VP to have been seen PP by Mary VP ... V thought VP IP to have been VP V seen PP by Mary
[women]
37
NP JJ
NNS NNS men CONJ and NNS women NP NP JJ
NNS men CONJ and NP women
>
38
39
40 https://www.reuters.com/article/us-sport-california-education/california-to-let-college-athletes-be-paid-in-blow-to-ncaa-rules-idUSKBN1WF1SR
Disambiguation Strategy:
41
42
43
44
NP Det a Nominal Noun flight…
45
NP Det a Nominal Nominal Noun flight PP from Indianapolis…
NP Det a Nominal Nominal Nominal Noun flight PP from Indianapolis PP to Houston…
46
47
NP Det a Nominal Nominal Nominal Nominal Noun flight PP from Indianapolis PP to Houston PP
TWA
48
49
50
subproblems
51
52
53
54
55
56
1) Hybrid productions:
INF-VP → to VP
2) Unit productions:
A → B
3) Long productions:
A → B C D …
57
58
⃰ B and B → w, add A → w
⃰ B: B is reachable from A by a sequence of unit productions]
59
60
S → Aux NP VP S → X1 VP X1 → Aux NP
1) Convert terminals in hybrid rules to dummy non-terminals 2) Convert unit productions 3) Binarize long production rules
61
62
ℒ1 Grammar ℒ1 in CNF
S → NP VP S → NP VP S → Aux NP VP S → X1 VP X1 → Aux NP S → VP S → book | include | prefer S → Verb NP S → X2 PP S → Verb PP S → VP PP NP → Pronoun NP → I | she | me NP → Proper-Noun NP → TWA | Houston NP → Det Nominal NP → Det Nominal Nominal → Noun Nominal → book | flight | meal | money Nominal → Nominal Noun Nominal → Nominal Noun Nominal → Nominal PP Nominal → Nominal PP VP → Verb VP → book | include | prefer VP → Verb NP VP → Verb NP VP → Verb NP PP VP → X2 PP X2 → Verb NP VP → Verb PP VP → Verb PP VP → VP PP VP → VP PP PP → Preposition NP PP → Preposition NP
63
ℒ1 Grammar ℒ1 in CNF
S → NP VP S → NP VP S → Aux NP VP S → X1 VP X1 → Aux NP S → VP S → book | include | prefer S → Verb NP S → X2 PP S → Verb PP S → VP PP NP → Pronoun NP → I | she | me NP → Proper-Noun NP → TWA | Houston NP → Det Nominal NP → Det Nominal Nominal → Noun Nominal → book | flight | meal | money Nominal → Nominal Noun Nominal → Nominal Noun Nominal → Nominal PP Nominal → Nominal PP VP → Verb VP → book | include | prefer VP → Verb NP VP → Verb NP VP → Verb NP PP VP → X2 PP X2 → Verb NP VP → Verb PP VP → Verb PP VP → VP PP VP → VP PP PP → Preposition NP PP → Preposition NP
64
ℒ1 Grammar ℒ1 in CNF
S → NP VP S → NP VP S → Aux NP VP S → X1 VP X1 → Aux NP S → VP S → book | include | prefer S → Verb NP S → X2 PP S → Verb PP S → VP PP NP → Pronoun NP → I | she | me NP → Proper-Noun NP → TWA | Houston NP → Det Nominal NP → Det Nominal Nominal → Noun Nominal → book | flight | meal | money Nominal → Nominal Noun Nominal → Nominal Noun Nominal → Nominal PP Nominal → Nominal PP VP → Verb VP → book | include | prefer VP → Verb NP VP → Verb NP VP → Verb NP PP VP → X2 PP X2 → Verb NP VP → Verb PP VP → Verb PP VP → VP PP VP → VP PP PP → Preposition NP PP → Preposition NP
65
66
67
[3,4] [3,5] [0,5] [0,2] [0,3] [1,4] [0,1] [0,4] [2,5] [1,3] [2,3] [4,5] [2,4] [1,5] [1,2]
Book the flight through Houston
68
[ 3 , 4 ] [ 3 , 5 ] [ , 5 ] [ , 2 ] [ , 3 ] [ 1 , 4 ] [ , 1 ] [ , 4 ] [ 2 , 5 ] [ 1 , 3 ] [ 2 , 3 ] [ 4 , 5 ] [ 2 , 4 ] [ 1 , 5 ] [ 1 , 2 ]
Book the flight through Houston
69
Book the flight through Houston
[ 3 , 4 ] [ 3 , 5 ] [ , 5 ] [ , 2 ] [ , 3 ] [ 1 , 4 ] [ , 1 ] [ , 4 ] [ 2 , 5 ] [ 1 , 3 ] [ 2 , 3 ] [ 4 , 5 ] [ 2 , 4 ] [ 1 , 5 ] [ 1 , 2 ]
1 2 3 4 5
70
Book the flight through Houston
[ 3 , 4 ] [ 3 , 5 ] [ , 5 ] [ , 2 ] [ , 3 ] [ 1 , 4 ] [ , 1 ] [ , 4 ] [ 2 , 5 ] [ 1 , 3 ] [ 2 , 3 ] [ 4 , 5 ] [ 2 , 4 ] [ 1 , 5 ] [ 1 , 2 ]
1 2 3 4 5
parses
71
LING 571 Deep Processing Techniques for NLP October 2, 2019
72
73
74
75
76
77
>>> gr1 = nltk.data.load('grammars/large_grammars/ atis.cfg') >>> gr1.productions()[0] ABBCL_NP -> QUANP_DTI QUANP_DTI QUANP_CD AJP_JJ NOUN_NP PRPRTCL_VBG >>> gr1.productions()[0].lhs() ABBCL_NP >>> gr1.productions(lhs=gr1.productions()[1].lhs()) [ADJ_ABL -> only, ADJ_ABL->such]