Computational Semantics
LING 571 — Deep Processing for NLP October 23, 2019 Shane Steinert-Threlkeld
1
Computational Semantics LING 571 Deep Processing for NLP October - - PowerPoint PPT Presentation
Computational Semantics LING 571 Deep Processing for NLP October 23, 2019 Shane Steinert-Threlkeld 1 Announcements CatchBox: WiFi: (?!?!?!?!?) HW4: Helpful NLTK built-ins: nltk.tree.fromstring()
LING 571 — Deep Processing for NLP October 23, 2019 Shane Steinert-Threlkeld
1
2
3
(ROOT (S (NP (NNS Hospitals)) (VP (VBD named) (SBAR (IN after) (S (NP (NNS sandwiches)) (VP (VBP kill) (NP (CD five)))))) (. .))) (ROOT (S (NP (NNP Extinction) (NNP Rebellion) (NNP protester)) (VP (VBD dressed) (SBAR (IN as) (S (NP (NNP Boris) (NNP Johnson)) (VP (VBZ climbs) (NP (NNP Big) (NNP Ben)))))) (. .))) http://nlp.stanford.edu:8080/parser/index.jsp
https://www.theguardian.com/environment/video/2019/oct/18/extinction-rebellion-protester-dressed-as-boris-johnson-scales-big-ben-video4
5
6
S Q-WH-Obj Whwd What Aux do NP Pron I VP/NP V have NP/NP *t* PP Prep
NP N Thursday
Date=Thursday Cal=User Action: check(Cal=USER, Date=Thursday)
S Q-WH-Obj Whwd What Aux do NP Pron I VP/NP V have NP/NP *t* PP Prep
NP N Thursday
7
8
9
10
Psychology
Orange Green
Blue
Red Clouds
Sky
Earth
Epistemology Logic
∃x Sky(x) ∧ Blue(x)
Speech & Text
“The sky is blue.”
11
12
Street Car Truck Fire Engine House Fire Red Orange Yellow Green Apples Cherries Pears Sunsets Sunrises Clouds Violets Roses Flowers Violet Ambulance Bus Vehicle
13
14
15
by what appeared to be a coordinated group of Mubarak supporters.
16
input?
17
∃x (dog (x) ∧ disappear (x))
18
19
language inference (NLI)
20
infer?
21
22
23
First-Order Logic:
24
Having Haver Had-Thing Speaker Car
Semantic Network:
Car ⇑ POSS-BY Speaker
Conceptual Dependency: Frame-Based: Having Haver: Speaker HadThing: Car
∃e, y (Having (e) ∧ Haver (e, Speaker) ∧ HadThing (e, y) ∧ Car (y))
25
26
27
28
29
30
31
32
∃x Flight(x) ∧ Serves(x, Pittsburgh) ∧ Non-stop(x)
33
∀x Flight(x) ⇒ Includes(x, beverages)
34
35
Formula → AtomicFormula Connective → ∧ | ∨ | ⇒ | Formula Connective Formula Quantifier → ∀ | ∃ | Quantifier Variable, … Formula Constant → VegetarianFood | Maharani | … | ¬ Formula Variable → x | y | … | (Formula) Predicate → Serves | Near | … AtomicFormula → Predicate(Term,…) Function → LocationOf | CuisineOf | … Term → Function(Term,…) | Constant | Variable
J&M p. 556 (3rd ed. 16.3)
parts, and the rules for their combination.
36
37
38
39
λx.P(x) λx.P(x)(A) P(A)
λx.λy.Near(x, y) λx.λy.Near(x, y)(Midway) λy.Near(Midway, y) λy.Near(Midway, y)(Chicago) Near(Midway, Chicago)
40
41
λx.λy.Near(x, y) = Midway Chicago
42
λy.Near(x, y) Chicago = Midway
43
Near(x, y) Chicago Midway
parse tree
44
45
P Q ¬P P ∧Q P ∨Q P ⇒Q
F F T F F T F T T F T T T F F F T F T T F T T T
RHS=T
46
47
48
49
50
51
52
∧ Time(e, Saturday)
53
54
Meaning Representation for Computational Semantics
55
language
syntactic trees based on the principle of compositionality
analysis in more detail
56
57
{set of constraints} ⟨𝛾i feature path⟩ = Atomic value | ⟨𝛾j feature path⟩
58
S → NP VP Det → this ⟨NP AGREEMENT⟩ = ⟨VP AGREEMENT⟩ ⟨Det AGREEMENT NUMBER⟩ = sg S → Aux NP VP Det → these ⟨Aux AGREEMENT⟩ = ⟨NP AGREEMENT⟩ ⟨Det AGREEMENT NUMBER⟩ = pl NP → Det Nominal Verb → serve ⟨Det AGREEMENT⟩ = ⟨Nominal AGREEMENT⟩ ⟨NP AGREEMENT⟩ = ⟨Nominal AGREEMENT⟩ ⟨Verb AGREEMENT NUMBER⟩ = pl Aux → does Noun → flight ⟨AUX AGREEMENT NUMBER⟩ = sg ⟨AUX AGREEMENT PERSON⟩ = 3rd ⟨Noun AGREEMENT NUMBER⟩ = sg
precise grammar.
59
nltk.parse.FeatureEarleyChartParser or similar.
60
61
62
63
NPNUMsg DetNUMsg this NNUMsg dog NP DetNUMsg this NNUMsg dog
NP[NUM=?n] -> Det[NUM=?n] N[NUM=?n] Det[NUM=sg] -> ‘this’ | ‘that’ Det[NUM=pl] -> ‘these’ | ‘those’ N[NUM=sg] -> ‘dog’ | ‘cat’
NP DetNUMsg this N dog
64
NP[NUM=?n] -> Det[NUM=?n] N[NUM=?n] Det[NUM=sg] -> ‘this’ | ‘that’ Det[NUM=pl] -> ‘these’ | ‘those’ N[NUM=sg] -> ‘dog’ | ‘cat’
NP DetNUMpl these NNUMsg dog NPNUMFAIL DetNUMpl these NNUMsg dog
BUT…
65
>>> cp = load_parser('grammars/book_grammars/ feat0.fcfg’) >>> for tree in cp.parse(tokens): ... print(tree) (S[] (NP[NUM='sg'] (PropN[NUM='sg'] Kim)) (VP[NUM='sg', TENSE='pres'] (TV[NUM='sg', TENSE='pres'] likes) (NP[NUM='pl'] (N[NUM='pl'] children))))
66
67
68
units
69
70
Feature Grammar Practice: Animacy
71
S -> NP VP VP[subcat=ditrans] -> V NP NP NP -> NNP NP -> Det N NNP[animacy=True] -> 'Alex' | 'Ahmed' V[subcat=ditrans] -> 'gifted' Det -> 'a' | 'the' N[animacy=False] -> 'book' | 'rock'
72
S NP NNP animacy + Alex VP V gifted NP Det the N animacy
rock NP Det a N animacy
book
73
S NP NNP animacy + Alex VP V gifted NP NNP animacy + Ahmed NP Det a N animacy
book
get the right results:
74