Upload
hakien
View
239
Download
2
Embed Size (px)
Citation preview
Class 1 reminder
We learned to manually write down logical forms for various naturallanguage constructs
• Entities
• Relations
• Superlatives
• Events
• · · ·
But how do we build logical forms automatically?
1
Outline
• Compositionality
– Grammars and derivations
– Example
– Lexicon
– Modeling
– CCG
– Exercise
2
Outline
• Compositionality
– Grammars and derivations
– Example
– Lexicon
– Modeling
– CCG
– Exercise
3
Grammars and derivations
Simple grammar
(lexicon) Set ⇒ Phrase Chicago ⇒ Chicago
(lexicon) Binary⇒ Phrase PlacesLived⇒ lived in
(join) Set ⇒ Binary Set b.s ⇒ b s
(intersect) Root ⇒ Set Set s1 u s2 ⇒ s1 s2
4
Grammars and derivations
Simple grammar
(lexicon) Set ⇒ Phrase Chicago ⇒ Chicago
(lexicon) Binary⇒ Phrase PlacesLived⇒ lived in
(join) Set ⇒ Binary Set b.s ⇒ b s
(intersect) Root ⇒ Set Set s1 u s2 ⇒ s1 s2
Type.PersonuPlaceLived.Chicago
Type.Person
people
who PlaceLived.Chicago
PlaceLived
lived in
Chicago
Chicago
lexicon
lexiconlexicon
join
intersect
4
Grammar
Simple grammar
(lexicon) Set ⇒ Phrase Chicago ⇒ Chicago
(lexicon) Binary⇒ Phrase PlacesLived⇒ lived in
(join) Set ⇒ Binary Set b.s ⇒ b s
(intersect) Root ⇒ Set Set s1 u s2 ⇒ s1 s2
A grammar G is a 4-tuple:
V: chicago, live in
N : Binary,Set,Root
Root ∈ N : start symbol
R: grammar rules
5
Grammar rules
Simple grammar
(lexicon) Set ⇒ Phrase Chicago ⇒ Chicago
(lexicon) Binary⇒ Phrase PlacesLived⇒ lived in
(join) Set ⇒ Binary Set b.s ⇒ b s
(intersect) Root ⇒ Set Set s1 u s2 ⇒ s1 s2
A rule r ∈ R has:
A ∈ N : left-hand-side (LHS) non-terminal
α ∈ (N ∪ V)+ right-hand-side
f semantic function for building derivations
Semantic functions are the key component!
6
Derivation
Root:Type.CityuPlaceOfBirthOf.AbeLincoln
what Set:Type.City
city
was Set:PlaceOfBirthOf.AbeLincoln
Entity:AbeLincoln
abraham lincoln
Binary:PlaceOfBirthOf
born in
A derivation tree dAi:j over a span x = (wi, . . . , wj−1):
Spans (wi, . . . , wj−1)
Has category d.c = A ∈ NHas logical form d.z
Has children that are derivations or terminals
7
Semantic functions
A function f : Dk → 2D
Example:
• r = A→ B C [f ]
• DAi:j = f(dBi:k, d
Ck:j)
Lexicon function:
Lex( lincoln ) =
{ Entity:AbeLincoln
lincoln
,
Entity:LincolnFilm
lincoln
, ...
}
8
Semantic functions
Join function:
Join
(Entity:AbeLincoln
abraham lincoln,Binary:PlaceOfBirthOf
born
)=
{ Set:PlaceOfBirthOf.AbeLincoln
Entity:AbeLincoln
abraham lincoln
Binary:PlaceOfBirthOf
born
}
Merge function:
Intersect
( Set:Type.City
city,Set:ReleaseDateOf.LincolnFilm
abraham lincoln born
)= {}
Return sets (unlike CFGs)
9
Semantic function
IdentityFn Copy logical form
SelectFn Select one child logical form
DateFn Convert date descriptions to date
FilterPosFn Filter words by POS
10
Semantic function
IdentityFn Copy logical form
SelectFn Select one child logical form
DateFn Convert date descriptions to date
FilterPosFn Filter words by POS
ContextFn Integrate arbitrary context
What city was abraham lincoln born?
How about his wife?
10
Semantic function
IdentityFn Copy logical form
SelectFn Select one child logical form
DateFn Convert date descriptions to date
FilterPosFn Filter words by POS
ContextFn Integrate arbitrary context
What city was abraham lincoln born?
How about his wife?
Flexible! arbitrary logic can be used
λx.Border(x, Italy)
S \Nbordering Italy
⇒λy.λx.Border(x, y) Italy
(S \N)/N N
bordering Italy
10
Outline
• Compositionality
– Grammars and derivations
– Example
– Lexicon
– Modeling
– CCG
– Exercise
11
Example
./run @mode=simple-lambdadcs \
-Grammar.inPaths esslli 2016/class2 demo.grammar \
-SimpleLexicon.inPaths esslli 2016/class2 demo.lexicon
12
Example
california
the golden state
cities in the golden state
towns located in california
rivers bordering california
13
Example
california
the golden state
cities in the golden state
towns located in california
rivers bordering california
Is the last utterance meaningful?
How can we avoid such logical forms?
13
Outline
• Compositionality
– Grammars and derivations
– Example
– Lexicon
– Modeling
– CCG
– Exercise
14
The lexicon problem
california California
the golden state California
cities Type.Citytown
towns Type.CityTown
in ContainedBy
How is the lexicon generated?
15
The lexicon problem
california California
the golden state California
cities Type.Citytown
towns Type.CityTown
in ContainedBy
How is the lexicon generated?
• Annotation
• Exhaustive search
• String matching
• Supervised alignment
• Unsupervised alginment
• Learning
15
Annotation
where Type.Location
most λx.λy.argmax(y, x)
how many λx.count(x)
Useful for function words
16
Annotation
where Type.Location
most λx.λy.argmax(y, x)
how many λx.count(x)
Useful for function words
city Type.CityTown
lake Type.Lake
area Area
Useful for small domains
16
Annotation
where Type.Location
most λx.λy.argmax(y, x)
how many λx.count(x)
Useful for function words
city Type.CityTown
lake Type.Lake
area Area
Useful for small domains
Large domains? Different languages?
16
Exhaustive search
city Type.Lake
state Population
people Area
area λx.count(x)
how many Type.CityTown
. . . . . .
17
Exhaustive search
city Type.Lake
state Population
people Area
area λx.count(x)
how many Type.CityTown
. . . . . .
Size of lexicon: |V| × |L|
Intractable for large domains
17
Exhaustive search
city Type.Lake
state Population
people Area
area λx.count(x)
how many Type.CityTown
. . . . . .
Size of lexicon: |V| × |L|
Intractable for large domains
Exhaustive?
actress Profession.Actor uGender.Female
relative λx.Parent.x t Sibling.x tChild.x
expat µx.BirthPlaceOf.x 6= argmax(x,PlacesLived)
17
String match
Knowledge-bases often have language descriptions
area Area
• Language specific
• Limited coverage and noisy
18
String match
Knowledge-bases often have language descriptions
area Area
• Language specific
• Limited coverage and noisy
• Useful as a feature at training time
18
Supervised alignment
Assume access to (x, z) language-logical form pairs
State with the largest area
argmax(Type.State,Area)
19
Supervised alignment
Assume access to (x, z) language-logical form pairs
State with the largest area
argmax(Type.State,Area)
Define patterns over (x, z) to generate candidate lexicon entries
State
with the largest
largest
area
State
Type.State
λx.Type.x
Area
λx.λy.Argmax(x, y)
19
Supervised alignment
Assume access to (x, z) language-logical form pairs
State with the largest area
argmax(Type.State,Area)
Define patterns over (x, z) to generate candidate lexicon entries
State
with the largest
largest
area
State
Type.State
λx.Type.x
Area
λx.λy.Argmax(x, y)
Keep counts for each lexical entry as a feature
19
Supervised alignment
Assume access to (x, z) language-logical form pairs
State with the largest area
argmax(Type.State,Area)
Define patterns over (x, z) to generate candidate lexicon entries
State
with the largest
largest
area
State
Type.State
λx.Type.x
Area
λx.λy.Argmax(x, y)
Keep counts for each lexical entry as a feature
Predefined patterns
Generalization? 19
Unsupervised alignment
(Barack Obama, was born in, Honolulu)
(Albert Einstein, was born in, Ulm)
(Barack Obama, lived in, Chicago)
... 15M triples ...
BarackObama
Person
Type
Politician
Profession
1961.08.04
DateOfBirth
HonoluluPlaceOfBirth
Hawaii
ContainedBy
City
Type
UnitedStates
ContainedBy
USState
Type
Event8
Marriage
MichelleObama
Spouse
Type
FemaleGender
1992.10.03
StartDate
Event3
PlacesLived
Chicago
Location
Event21
PlacesLived
Location
ContainedBy
(BarackObama, HasBirthplace, Honolulu)
(Albert Einstein, HasBirthplace, Ulm)
(BarackObama, PlacesLived.Location, Chicago)
... 600M triples ...
B et al., 2013
20
Unsupervised alignment
grew up in[Person,Location]
born in[Person,Date]
married in[Person,Date]
born in[Person,Location]
DateOfBirth
PlaceOfBirth
Marriage.StartDate
PlacesLived.Location
(BarackObama,Honolulu)
(MichelleObama,Chicago)
(RandomPerson,Seattle) (BarackObama,Chicago)
21
Unsupervised alignment
grew up in[Person,Location]
born in[Person,Date]
married in[Person,Date]
born in[Person,Location]
DateOfBirth
PlaceOfBirth
Marriage.StartDate
PlacesLived.Location
(BarackObama,Honolulu)
(MichelleObama,Chicago)
(RandomPerson,Seattle) (BarackObama,Chicago)
Alignment features
phrase-count:15,765
intersection-count: 6,048
21
Unsupervised alignment
grew up in[Person,Location]
born in[Person,Date]
married in[Person,Date]
born in[Person,Location]
DateOfBirth
PlaceOfBirth
Marriage.StartDate
PlacesLived.Location
(BarackObama,Honolulu)
(MichelleObama,Chicago)
(RandomPerson,Seattle) (BarackObama,Chicago)
Alignment features
phrase-count:15,765
intersection-count: 6,048
Generalizes to test set
Restricted domain21
Advanced
• Change lexicon at training time
• batch voting
• Generative models
[Kwiatkowski et al., 2010; Kwiatkowski et al. 2011; Artzi et al., 2014;Krishnamurthy, 2015]
22
Outline
• Compositionality
– Grammars and derivations
– Example
– Lexicon
– Modeling
– CCG
– Exercise
23
Bridging/trace predicates
Problem: Language defines semantics implicitly
Italy’s language Type.Language u LanguageOf.Italy
Where is Beijing Type.Location u Contains.Beijing
Boston flight Type.Flight u To.Boston
24
Bridging/trace predicates
Problem: Language defines semantics implicitly
Italy’s language Type.Language u LanguageOf.Italy
Where is Beijing Type.Location u Contains.Beijing
Boston flight Type.Flight u To.Boston
Lexicon?
’s LanguageOf
is Contains
??? To
24
Naive solution
language Type.Language
language LanguageOf
where Type.Location
where Contains
flight Type.Filght
flight To
flight From
More pressure on lexicon learning
25
Naive solution
language Type.Language
language LanguageOf
where Type.Location
where Contains
flight Type.Filght
flight To
flight From
More pressure on lexicon learning
Infer missing predicates from context
Can be implemented as a semantic function! (BridgeFn)
25
Bridging 1: two unaries
Boston
To
Type.Flight
boston flight
lex
lex
bridging
Type.Flight u To.Boston
Insert any type-matching binary
(bridge first) Set ⇒ Set Set
26
Bridging 1: two unaries
Boston
From
Type.Flight
boston flight
lex
lex
bridging
Type.Flight u To.Boston
Insert any type-matching binary
(bridge first) Set ⇒ Set Set
Learn to choose implicit predicate 26
Bridging 2: single unary
Contains
Beijing
Where is Beijing
lex
bridging
Insert any type-matching binary
Contains.Beijing
(bridge) Set ⇒ Set
More uncertainty
27
Bridging 3: n-ary relations
Marriage.Spouse.Madonna
Madonna Marriage.Spouse 2000
Who did Madonna marry in 2000
lex lex
joinjoin
28
Bridging 3: n-ary relations
Marriage.Spouse.Madonna Marriage.StartDate
Madonna Marriage.Spouse 2000
Who did Madonna marry in 2000
lex lex
joinjoin
bridging
Marriage.(Spouse.Madonna u StartDate.2000)
28
Bridging 3: n-ary relations
Marriage.Spouse.Madonna Marriage.StartDate
Madonna Marriage.Spouse 2000
Who did Madonna marry in 2000
lex lex
joinjoin
bridging
Marriage.(Spouse.Madonna u StartDate.2000)
Later: a more general solution called floating parser
• Wang et al., 2015; Pasupat and Liang, 2015
28
Type raising
Traverses Oregon
Traverse(Oregon)
Traverse
traverses
Oregon
Oregon
traverses Oregon or traverses Nevada
Traverse(Oregon) t Traverse(Nevada)
Traverse(Oregon)
Traverse
traverses
Oregon
Oregon
or Traverse(Nevada)
Traverse
traverses
Nevada
Nevada
29
Type raising
Traverse(Oregon) t Nevada
Traverse(Oregon)
Traverse
traverses
Oregon
Oregon
or Nevada
Nevada
How to apply the binary on multiple arguments?
30
Solution 1
(ConstFn λx.λy.λb.b(x) t b(y)) Disj ⇒ or
Traverses Oregon or Nevada or Colorado
Another lexical entry?
31
Type raising
Type raise the entity to a function that is applied on a binary
(ApplyFn λx.λf.f(x)) FuncSet⇒ Set
(ConstFn λa.λb.λg.a(g) t b(g)) Disj ⇒ or
Traverse(Oregon) t Traverse(Nevada)
Traverse
traverses
λg.g(Nevada) t g(Oregon)
λf.f(Oregon)
Oregon
Oregon
λb.λg.g(Nevada) t b(g)
λa.λb.λg.a(g) t b(g)
or
λf.f(Nevada)
Nevada
Nevada
32
Outline
• Compositionality
– Grammars and derivations
– Example
– Lexicon
– Modeling
– CCG
– Exercise
33
CCG
Standard formalism in semantics
Lexicon:
fun ` ADJ : λx.fun(x)
fun ` N/N : λf.λx.fun(x) ∧ f(x)
34
CCG
Standard formalism in semantics
Lexicon:
fun ` ADJ : λx.fun(x)
fun ` N/N : λf.λx.fun(x) ∧ f(x)
Handful of combinators (grammar)
A/B : f B : g ⇒ A : f(g) (>)
B : g A\B : f ⇒ A : f(g) (<)
34
CCG
Main difference:
• CCG pushed complexity from grammar to lexicon
• lambda-DCS tries to push it from lexicon to learning
35
CCG
Main difference:
• CCG pushed complexity from grammar to lexicon
• lambda-DCS tries to push it from lexicon to learning
Rationale:
• CCG originates in linguistics
• Lambda-DCS originates in NLP
35
CCG
Main difference:
• CCG pushed complexity from grammar to lexicon
• lambda-DCS tries to push it from lexicon to learning
Rationale:
• CCG originates in linguistics
• Lambda-DCS originates in NLP
• CCG-based semantic parsing addressed many issues with typeraising, factored lexicons, etc. [Zettlemoyer and Collins, 2007;Kwiatkowski et al., 2011]
35
Philosophy: simple grammar and lexicon
• Capturing correct derivations only requires complex rules
36
Philosophy: simple grammar and lexicon
• Capturing correct derivations only requires complex rules
• Simple rules generate overapproximation of good derivations
36
Philosophy: simple grammar and lexicon
• Capturing correct derivations only requires complex rules
• Simple rules generate overapproximation of good derivations
Disambiguate at learning time!
36
Outline
• Compositionality
– Grammars and derivations
– Example
– Lexicon
– Modeling
– CCG
– Exercise
37
Exercise
Write a grammar that parses utterances
You can use class2 demo.lexicon and class2 demo.grammar that are onthe website
They are also at /home/shared/esslli/semparse
You can also start with ConstantFn entries that parse the entire uttearnceand decompose
38
Exercise
State with the largest area
Top 5 cities by area
Major cities with at least 140,000 inhabitants
How many states have capitals with at least 200,000 inhabitants
State bordering Oregon and Nevada
Check if the grammar parses the sentence:
States bordering Oregon and Nevada and Arizona
39