Natural Language Processing Lecture Notes 11 Chapter 15

  • Slides: 61
Download presentation
Natural Language Processing Lecture Notes 11 Chapter 15 (part 1) 1

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

Semantic Analysis – These notes: syntax driven compositional semantic analysis – Assign meanings based

Semantic Analysis – These notes: syntax driven compositional semantic analysis – Assign meanings based only on the grammar and lexicon (no inference, ignore context) 2

Compositional Analysis • Principle of Compositionality – The meaning of a whole is derived

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 3

Example • Ay. Caramba serves meat 4

Example • Ay. Caramba serves meat 4

Compositional Analysis 5

Compositional Analysis 5

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

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. 6

Example • Attachments • Easy parts… {Prop. Noun. sem} – NP -> Prop. Noun

Example • Attachments • Easy parts… {Prop. Noun. sem} – NP -> Prop. Noun {Mass. Noun. sem} – NP -> Mass. Noun {Ay. Caramba} – Prop. Noun -> Ay. Caramba {MEAT} – Mass. Noun -> meat 7

Example • S -> NP VP • VP -> Verb NP • Verb ->

Example • S -> NP VP • VP -> Verb NP • Verb -> serves • {VP. sem(NP. sem)} • {Verb. sem(NP. sem)} • ? ? ? 8

Example 9

Example 9

Example 10

Example 10

Example 11

Example 11

Example 12

Example 12

Key Points • Each node in a tree corresponds to a rule in the

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. 13

Quantified Phrases • Consider A restaurant serves meat. • Assume that A restaurant looks

Quantified Phrases • Consider A restaurant serves meat. • Assume that A restaurant looks like • If we do the normal lambda thing we get 14

Complex Terms • Allow the compositional system to pass around representations like the following

Complex Terms • Allow the compositional system to pass around representations like the following as objects with parts: Complex-Term → <Quantifier var body> 15

Example • Our restaurant example winds up looking like 16

Example • Our restaurant example winds up looking like 16

Conversion • So… complex terms wind up being embedded inside predicates. So pull them

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) 17

Example 18

Example 18

Quantifiers and Connectives • If the quantifier is an existential, then the connective is

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) 19

Multiple Complex Terms • Note that the conversion technique pulls the quantifiers out to

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. 20

Quantifier Ambiguity • Consider – Every restaurant has a menu – That could mean

Quantifier Ambiguity • Consider – Every restaurant has a menu – That could mean that every restaurant has a menu – Or that There’s some uber-menu out there and all restaurants have that menu 21

Quantifier Scope Ambiguity 22

Quantifier Scope Ambiguity 22

Ambiguity • Much like the prepositional phrase attachment problem • The number of possible

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 23

Integration with a Parser • Assume you’re using a dynamic-programming style parser (Earley or

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. 24

Harder Example • What makes this hard? • What role does Harry play in

Harder Example • What makes this hard? • What role does Harry play in all this? 25

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

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 Telling And to the result of the first application to get the right value of the told thing. V. Sem(NP. Sem, VPto. Sem(NP. Sem)) 26

Two Philosophies 1. Let the syntax do what syntax does well and don’t expect

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 27

Example • Mary freebled John the nim. – Who has the nim? – Who

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

Example • Consider the attachments for the VPs VP -> Verb NP NP rule

Example • Consider the attachments for the VPs VP -> Verb NP NP rule VP -> Verb NP PP (gave Mary a book) (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) 29

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

Example • Under a syntax-heavy scheme we might want to do something like • VP -> V NP NP V. sem ^ Recip(NP 1. sem) ^ Object(NP 2. sem) • VP -> V NP PP V. Sem ^ Recip(PP. Sem) ^ Object(NP 1. sem) • I. e the verb only contributes the predicate, the grammar “knows” the roles. 30

Integration • Two basic approaches – Integrate semantic analysis into the parser (assign meaning

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 31

Example • From BERP – I want to eat someplace near campus • Two

Example • From BERP – I want to eat someplace near campus • Two parse trees, two meanings 32

Pros and Cons • If you integrate semantic analysis into the parser as its

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 33

Mismatches • There are unfortunately some annoying mismatches between the syntax of FOPC and

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. 34

Non-Compositionality • Unfortunately, there are lots of examples where the meaning (loosely defined) can’t

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 35

English Idioms • Kick the bucket, buy the farm, bite the bullet, run the

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) 36

The Tip of the Iceberg • Describe this construction 1. A fixed phrase with

The Tip of the Iceberg • Describe this construction 1. A fixed phrase with a particular meaning 2. A syntactically and lexically flexible phrase with a particular meaning 3. A syntactically and lexically flexible phrase with a partially compositional meaning 4. … 37

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

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. 38

Example • What we seem to need is something like • NP -> An

Example • What we seem to need is something like • NP -> An initial NP with tip as its head followed by a 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 39

Non-Compositionality • Unfortunately, there are lots of examples where the meaning (loosely defined) can’t

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 40

English Idioms • Kick the bucket, buy the farm, bite the bullet, run the

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) 41

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

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. 42

Constructional Approach • So we’ll allow both VP → V NP → Kick-Verb the

Constructional Approach • So we’ll allow both VP → V NP → Kick-Verb the bucket {V. sem(NP. sem)} and VP {λ x Die(x)} 43

Computational Realizations • Semantic grammars – Simple idea, dumb name • Cascaded finite-state transducers

Computational Realizations • Semantic grammars – Simple idea, dumb name • Cascaded finite-state transducers – Just like Chapter 3 44

Semantic Grammars • One problem with traditional grammars is that they don’t necessarily reflect

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 45

BERP Example 46

BERP Example 46

BERP Example • How about a rule like the following instead… Request → I

BERP Example • How about a rule like the following instead… Request → I want to go to eat Food. Type Time { some attachment } 47

Semantic Grammar • The term semantic grammar refers to the motivation for the grammar

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 48

Semantic Grammars • Typically used in conversational agents in constrained domains – Limited vocabulary

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. 49

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

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 50

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

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 51

Back to Finite State Methods • Apply a series of cascaded transducers to an

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 52

Example Bridgestone Sports Co. said Friday it has set up a joint venture in

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. 53

Example Bridgestone Sports Co. said Friday it has set up a joint venture in

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. 54

Example Bridgestone Sports Co. said Friday it has set up a joint venture in

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. 55

Example Bridgestone Sports Co. said Friday it has set up a joint venture in

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. 56

FASTUS Output 57

FASTUS Output 57

Cascades 58

Cascades 58

Named Entities • Cascade 2 in the last example involves named entity recognition… –

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 59

Key Point • What about the stuff we don’t care about? – Ignore it.

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 60

Key Point • It works because of the constrained nature of the problem… –

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 61