1 natural language processing lecture notes 11 chapter 15 (part 1)

61
1 Natural Language Processing Lecture Notes 11 Chapter 15 (part 1)

Upload: marshall-edwards

Post on 25-Dec-2015

227 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: 1 Natural Language Processing Lecture Notes 11 Chapter 15 (part 1)

1

Natural Language Processing

Lecture Notes 11Chapter 15 (part 1)

Page 2: 1 Natural Language Processing Lecture Notes 11 Chapter 15 (part 1)

2

Semantic Analysis

– These notes: syntax driven compositional semantic analysis

– Assign meanings based only on the grammar and lexicon (no inference, ignore context)

Page 3: 1 Natural Language Processing Lecture Notes 11 Chapter 15 (part 1)

3

Compositional Analysis

• Principle of Compositionality– The meaning of a whole is derived from

the meanings of the parts

• What parts?– The constituents of the syntactic parse

of the input

Page 4: 1 Natural Language Processing Lecture Notes 11 Chapter 15 (part 1)

4

Example

• AyCaramba serves meat

),()^,()^( MeateServedAyCarambaeServereServinge

Page 5: 1 Natural Language Processing Lecture Notes 11 Chapter 15 (part 1)

5

Compositional Analysis

Page 6: 1 Natural Language Processing Lecture Notes 11 Chapter 15 (part 1)

6

Augmented Rules

• We’ll accomplish this by attaching semantic formation rules to our syntactic CFG rules

• Abstractly

• This should be read as the semantics we attach to A can be computed from some function applied to the semantics of A’s parts.

)}.,....({... 11 semsemfA nn

Page 7: 1 Natural Language Processing Lecture Notes 11 Chapter 15 (part 1)

7

Example

• Easy parts…– NP -> PropNoun– NP -> MassNoun– PropNoun -> AyCaramba– MassNoun -> meat

• Attachments{PropNoun.se

m}{MassNoun.se

m}{AyCaramba}{MEAT}

Page 8: 1 Natural Language Processing Lecture Notes 11 Chapter 15 (part 1)

8

Example

• S -> NP VP• VP -> Verb NP• Verb -> serves

• {VP.sem(NP.sem)}• {Verb.sem(NP.sem)}• ???

),()^,()^( xeServedyeServereServingeyx

Page 9: 1 Natural Language Processing Lecture Notes 11 Chapter 15 (part 1)

9

Example

Page 10: 1 Natural Language Processing Lecture Notes 11 Chapter 15 (part 1)

10

Example

Page 11: 1 Natural Language Processing Lecture Notes 11 Chapter 15 (part 1)

11

Example

Page 12: 1 Natural Language Processing Lecture Notes 11 Chapter 15 (part 1)

12

Example

Page 13: 1 Natural Language Processing Lecture Notes 11 Chapter 15 (part 1)

13

Key Points

• Each node in a tree corresponds to a rule in the grammar

• Each grammar rule has a semantic rule associated with it that specifies how the semantics of the RHS of that rule can be computed from the semantics of its daughters.

Page 14: 1 Natural Language Processing Lecture Notes 11 Chapter 15 (part 1)

14

Quantified Phrases

• Consider A restaurant serves meat.

• Assume that A restaurant looks like

• If we do the normal lambda thing we get

)RestaurantxIsax ,(

)),(,()( MeatServed(e,))RestaurantxxIsaeServereeServing

Page 15: 1 Natural Language Processing Lecture Notes 11 Chapter 15 (part 1)

15

Complex Terms

• Allow the compositional system to pass around representations like the following as objects with parts:

Complex-Term → <Quantifier var body>

)Restaurant,(xIsax

Page 16: 1 Natural Language Processing Lecture Notes 11 Chapter 15 (part 1)

16

Example

• Our restaurant example winds up looking like

Meat)Served(e,))RestaurantxxIsaeServereeServing ,(,()(

Page 17: 1 Natural Language Processing Lecture Notes 11 Chapter 15 (part 1)

17

Conversion

• So… complex terms wind up being embedded inside predicates. So pull them out and redistribute the parts in the right way…

P(<quantifier, var, body>)turns into

Quantifier var body connective P(var)

Page 18: 1 Natural Language Processing Lecture Notes 11 Chapter 15 (part 1)

18

Example

),()Restaurant(

))Restaurant,(,(

xeServerx, Isax

xIsaxeServer

Page 19: 1 Natural Language Processing Lecture Notes 11 Chapter 15 (part 1)

19

Quantifiers and Connectives

• If the quantifier is an existential, then the connective is an ^ (and)

• If the quantifier is a universal, then the connective is an -> (implies)

Page 20: 1 Natural Language Processing Lecture Notes 11 Chapter 15 (part 1)

20

Multiple Complex Terms

• Note that the conversion technique pulls the quantifiers out to the front of the logical form…

• That leads to ambiguity if there’s more than one complex term in a sentence.

Page 21: 1 Natural Language Processing Lecture Notes 11 Chapter 15 (part 1)

21

Quantifier Ambiguity

• Consider– Every restaurant has a menu

– That could mean that every restaurant has a menu

– Or thatThere’s some uber-menu out there and all

restaurants have that menu

Page 22: 1 Natural Language Processing Lecture Notes 11 Chapter 15 (part 1)

22

Quantifier Scope Ambiguity

),(),(),()(,

),(

MenuyIsayeHadxeHavereyHavinge

restaurantxxIsa

),(),()(

),(),(

yeHadxeHavereeHaving

RestaurantxxIsaMenuyyIsa

Page 23: 1 Natural Language Processing Lecture Notes 11 Chapter 15 (part 1)

23

Ambiguity

• Much like the prepositional phrase attachment problem

• The number of possible interpretations goes up exponentially with the number of complex terms in the sentence

• The best we can do: weak methods to prefer one interpretation over another

Page 24: 1 Natural Language Processing Lecture Notes 11 Chapter 15 (part 1)

24

Integration with a Parser

• Assume you’re using a dynamic-programming style parser (Earley or CYK).

• As with feature structures for agreement and subcategorization, we add semantic attachments to states.

• As constituents are completed and entered into the table, we compute their semantics.

Page 25: 1 Natural Language Processing Lecture Notes 11 Chapter 15 (part 1)

25

Harder Example

• What makes this hard?

• What role does Harry play in all this?

Page 26: 1 Natural Language Processing Lecture Notes 11 Chapter 15 (part 1)

26

Harder Example• The VP for told is VP -> V NP VPto

– So you do what (what should its semantic attachment be?)Apply the semantic function attached to VPto

the semantics of the NP; this binds Harry as the goer of the going.

Then apply the semantics of the V to the semantics of the NP; this binds Harry as the Tellee of the TellingAnd to the result of the first application to get the right value of the told thing.

V.Sem(NP.Sem, VPto.Sem(NP.Sem))

Page 27: 1 Natural Language Processing Lecture Notes 11 Chapter 15 (part 1)

27

Two Philosophies

1. Let the syntax do what syntax does well and don’t expect it to know much about meaning– In this approach, the lexical entry’s

semantic attachments do the work

2. Assume the syntax does know something about meaning• Here the grammar gets complicated

and the lexicon simpler

Page 28: 1 Natural Language Processing Lecture Notes 11 Chapter 15 (part 1)

28

Example

• Mary freebled John the nim.– Who has the nim?– Who had it before the freebling?– How do you know?

Page 29: 1 Natural Language Processing Lecture Notes 11 Chapter 15 (part 1)

29

Example

• Consider the attachments for the VPsVP -> Verb NP NP rule(gave Mary a book)VP -> Verb NP PP (gave a book to Mary)

Assume the meaning representations should be the same for both. Under the lexicon-heavy scheme, the VP attachments are:VP.Sem(NP.Sem, NP.Sem)VP.Sem(NP.Sem, PP.Sem)

Page 30: 1 Natural Language Processing Lecture Notes 11 Chapter 15 (part 1)

30

Example

• Under a syntax-heavy scheme we might want to do something like

• VP -> V NP NP V.sem ^ Recip(NP1.sem) ^ Object(NP2.sem)

• VP -> V NP PP V.Sem ^ Recip(PP.Sem) ^ Object(NP1.sem)

• I.e the verb only contributes the predicate, the grammar “knows” the roles.

Page 31: 1 Natural Language Processing Lecture Notes 11 Chapter 15 (part 1)

31

Integration

• Two basic approaches– Integrate semantic analysis into the

parser (assign meaning representations as constituents are completed)

– Pipeline… assign meaning representations to complete trees only after they’re completed

Page 32: 1 Natural Language Processing Lecture Notes 11 Chapter 15 (part 1)

32

Example

• From BERP– I want to eat someplace near campus

• Two parse trees, two meanings

Page 33: 1 Natural Language Processing Lecture Notes 11 Chapter 15 (part 1)

33

Pros and Cons

• If you integrate semantic analysis into the parser as its running…– You can use semantic constraints to

cut off parses that make no sense– You assign meaning representations to

constituents that don’t take part in the correct (most probable) parse

Page 34: 1 Natural Language Processing Lecture Notes 11 Chapter 15 (part 1)

34

Mismatches

• There are unfortunately some annoying mismatches between the syntax of FOPC and the syntax provided by our grammars…

• So we’ll accept that we can’t always directly create valid logical forms in a strictly compositional way– We’ll get as close as we can and patch

things up after the fact.

Page 35: 1 Natural Language Processing Lecture Notes 11 Chapter 15 (part 1)

35

Non-Compositionality

• Unfortunately, there are lots of examples where the meaning (loosely defined) can’t be derived from the meanings of the parts

– Idioms, jokes, irony, sarcasm, metaphor, metonymy, indirect requests, etc

Page 36: 1 Natural Language Processing Lecture Notes 11 Chapter 15 (part 1)

36

English Idioms

• Kick the bucket, buy the farm, bite the bullet, run the show, bury the hatchet, etc…

• Lots of these… constructions where the meaning of the whole is either – Totally unrelated to the meanings of

the parts (kick the bucket)– Related in some opaque way (run the

show)

Page 37: 1 Natural Language Processing Lecture Notes 11 Chapter 15 (part 1)

37

The Tip of the Iceberg

• Describe this construction1. A fixed phrase with a particular

meaning2. A syntactically and lexically flexible

phrase with a particular meaning3. A syntactically and lexically flexible

phrase with a partially compositional meaning

4. …

Page 38: 1 Natural Language Processing Lecture Notes 11 Chapter 15 (part 1)

38

Example

• Enron is the tip of the iceberg.NP -> “the tip of the iceberg”

• Not so good… attested examples…– the tip of Mrs. Ford’s iceberg– the tip of a 1000-page iceberg– the merest tip of the iceberg

• How about– That’s just the iceberg’s tip.

Page 39: 1 Natural Language Processing Lecture Notes 11 Chapter 15 (part 1)

39

Example

• What we seem to need is something like

• NP -> An initial NP with tip as its head followed

bya subsequent PP with of as its head and that has iceberg as the head of its NP

And that allows modifiers like merest, Mrs. Ford, and 1000-page to modify the relevant semantic forms

Page 40: 1 Natural Language Processing Lecture Notes 11 Chapter 15 (part 1)

40

Non-Compositionality

• Unfortunately, there are lots of examples where the meaning (loosely defined) can’t be derived from the meanings of the parts

– Idioms, jokes, irony, sarcasm, metaphor, metonymy, indirect requests, etc

Page 41: 1 Natural Language Processing Lecture Notes 11 Chapter 15 (part 1)

41

English Idioms

• Kick the bucket, buy the farm, bite the bullet, run the show, bury the hatchet, etc…

• Lots of these… constructions where the meaning of the whole is either – Totally unrelated to the meanings of

the parts (kick the bucket)– Related in some opaque way (run the

show)

Page 42: 1 Natural Language Processing Lecture Notes 11 Chapter 15 (part 1)

42

Constructional Approach

• Syntax and semantics aren’t separable in the way that we’ve been assuming

• Grammars contain form-meaning pairings that vary in the degree to which the meaning of a constituent (and what constitutes a constituent) can be computed from the meanings of the parts.

Page 43: 1 Natural Language Processing Lecture Notes 11 Chapter 15 (part 1)

43

Constructional Approach

• So we’ll allow both

VP → V NP {V.sem(NP.sem)}

and

VP → Kick-Verb the bucket {λ x Die(x)}

Page 44: 1 Natural Language Processing Lecture Notes 11 Chapter 15 (part 1)

44

Computational Realizations

• Semantic grammars– Simple idea, dumb name

• Cascaded finite-state transducers– Just like Chapter 3

Page 45: 1 Natural Language Processing Lecture Notes 11 Chapter 15 (part 1)

45

Semantic Grammars

• One problem with traditional grammars is that they don’t necessarily reflect the semantics in a straightforward way

• You can deal with this by…– Fighting with the grammar

• Complex lambdas and complex terms, etc

– Rewriting the grammar to reflect the semantics

• And in the process give up on some syntactic niceties

Page 46: 1 Natural Language Processing Lecture Notes 11 Chapter 15 (part 1)

46

BERP Example

Page 47: 1 Natural Language Processing Lecture Notes 11 Chapter 15 (part 1)

47

BERP Example

• How about a rule like the following instead…

Request → I want to go to eat FoodType Time{ some attachment }

Page 48: 1 Natural Language Processing Lecture Notes 11 Chapter 15 (part 1)

48

Semantic Grammar

• The term semantic grammar refers to the motivation for the grammar rules

• The technology (plain CFG rules with a set of terminals) is the same as we’ve been using

• The good thing about them is that you get exactly the semantic rules you need

• The bad thing is that you need to develop a new grammar for each new domain

Page 49: 1 Natural Language Processing Lecture Notes 11 Chapter 15 (part 1)

49

Semantic Grammars

• Typically used in conversational agents in constrained domains– Limited vocabulary– Limited grammatical complexity– Chart parsing (Earley) can often

produce all that’s needed for semantic interpretation even in the face of ungrammatical input.

Page 50: 1 Natural Language Processing Lecture Notes 11 Chapter 15 (part 1)

50

Information Extraction

• A different kind of approach is required for information extraction applications

• Such systems must deal with– Arbitrarily complex (long) sentences– Shallow semantics

• flat attribute-value lists• XML/SGML style markup

Page 51: 1 Natural Language Processing Lecture Notes 11 Chapter 15 (part 1)

51

Examples

• Scanning newspapers, newswires for a fixed set of events of interests

• Scanning websites for products, prices, reviews, etc

• These may involve– Long sentences, complex syntax,

extended discourse, multiple writers

Page 52: 1 Natural Language Processing Lecture Notes 11 Chapter 15 (part 1)

52

Back to Finite State Methods

• Apply a series of cascaded transducers to an input text

• At each stage an isolated element of syntax/semantics is extracted for use in the next level

• The end result is a set of relations suitable for entry into a database

Page 53: 1 Natural Language Processing Lecture Notes 11 Chapter 15 (part 1)

53

Example

Bridgestone Sports Co. said Friday it has set up a joint venture in Taiwan with a local concern and a Japanese trading house to produce golf clubs to be shipped to Japan.

The joint venture, Bridgestone Sports Taiwan Co., capitalized at 20 million new Taiwan dollars, will start production in January 1990 with production of 20,000 iron and “metal wood” clubs a month.

Page 54: 1 Natural Language Processing Lecture Notes 11 Chapter 15 (part 1)

54

Example

Bridgestone Sports Co. said Friday it has set up a joint venture in Taiwan with a local concern and a Japanese trading house to produce golf clubs to be shipped to Japan.

The joint venture, Bridgestone Sports Taiwan Co., capitalized at 20 million new Taiwan dollars, will start production in January 1990 with production of 20,000 iron and “metal wood” clubs a month.

Page 55: 1 Natural Language Processing Lecture Notes 11 Chapter 15 (part 1)

55

Example

Bridgestone Sports Co. said Friday it has set up a joint venture in Taiwan with a local concern and a Japanese trading house to produce golf clubs to be shipped to Japan.

The joint venture, Bridgestone Sports Taiwan Co., capitalized at 20 million new Taiwan dollars, will start production in January 1990 with production of 20,000 iron and “metal wood” clubs a month.

Page 56: 1 Natural Language Processing Lecture Notes 11 Chapter 15 (part 1)

56

Example

Bridgestone Sports Co. said Friday it has set up a joint venture in Taiwan with a local concern and a Japanese trading house to produce golf clubs to be shipped to Japan.

The joint venture, Bridgestone Sports Taiwan Co., capitalized at 20 million new Taiwan dollars, will start production in January 1990 with production of 20,000 iron and “metal wood” clubs a month.

Page 57: 1 Natural Language Processing Lecture Notes 11 Chapter 15 (part 1)

57

FASTUS Output

Page 58: 1 Natural Language Processing Lecture Notes 11 Chapter 15 (part 1)

58

Cascades

Page 59: 1 Natural Language Processing Lecture Notes 11 Chapter 15 (part 1)

59

Named Entities

• Cascade 2 in the last example involves named entity recognition…– Labeling all the occurrences of named

entities in a text…• People, organizations, lakes, bridges,

hospitals, mountains, etc…

• This can be done quite robustly and looks like one of the most useful tasks across a variety of applications

Page 60: 1 Natural Language Processing Lecture Notes 11 Chapter 15 (part 1)

60

Key Point

• What about the stuff we don’t care about?– Ignore it. I.e. It’s not written to the

next tape, so it just disappears from further processing

Page 61: 1 Natural Language Processing Lecture Notes 11 Chapter 15 (part 1)

61

Key Point

• It works because of the constrained nature of the problem…– Only looking for a small set of items

that can appear in a small set of roles