nlp8-semantics2-reduced - compatibility...

19
Semantics 2/3 (Semantic Analysis) Ing. Roberto Tedesco, PhD [email protected] NLP – AA 20-21 Slides based on Jurafsky and Martin “Speech and Language Processing”

Upload: others

Post on 08-Oct-2020

0 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: NLP8-semantics2-reduced - Compatibility Modecorsi.dei.polimi.it/nlp/download/NLP8-semantics2-reduced.pdf · 1. Key semantic elements are often widely distributed across parse trees

Semantics 2/3(Semantic Analysis)

Ing. Roberto Tedesco, [email protected]

NLP – AA 20-21

Slides based on Jurafsky and Martin “Speech and Language Processing”

Page 2: NLP8-semantics2-reduced - Compatibility Modecorsi.dei.polimi.it/nlp/download/NLP8-semantics2-reduced.pdf · 1. Key semantic elements are often widely distributed across parse trees

Semantic analysis: approaches

l Syntax-driven semantic analysis– Based on lexicon and grammar– Domain independent

l Semantic grammar– The elements of the grammar are semantic entities– Domain dependent

l Information Extraction– Extracts small amount of information– Simple approach

2

Page 3: NLP8-semantics2-reduced - Compatibility Modecorsi.dei.polimi.it/nlp/download/NLP8-semantics2-reduced.pdf · 1. Key semantic elements are often widely distributed across parse trees

l Based on the principle of compositionality– The meaning of a sentence can be constructed from the

meanings of its parts– The meaning of a sentence is not based solely on the

words that make it up, but also on the ordering and grouping of words, and on the relations among the words in the sentence

l The composition of meaning representations is guided by a grammar:– syntactic components – relations

Syntax-based semantic analysis

3

Page 4: NLP8-semantics2-reduced - Compatibility Modecorsi.dei.polimi.it/nlp/download/NLP8-semantics2-reduced.pdf · 1. Key semantic elements are often widely distributed across parse trees

l Input: parse tree, or feature structures, or lexical dependency diagrams

l Lexical-level ambiguities are not resolved– Semantic analysis produces several interpretations– Later, lexical semantics analysis will perform WSD– In general, a last analysis phase will choose the “right”

interpretation

Syntax-based semantic analysis

4

Page 5: NLP8-semantics2-reduced - Compatibility Modecorsi.dei.polimi.it/nlp/download/NLP8-semantics2-reduced.pdf · 1. Key semantic elements are often widely distributed across parse trees

Syntax-based analysis pipeline

5

Page 6: NLP8-semantics2-reduced - Compatibility Modecorsi.dei.polimi.it/nlp/download/NLP8-semantics2-reduced.pdf · 1. Key semantic elements are often widely distributed across parse trees

Example

l Starting from a parse treel If I know that “serves” has roles Server and Served 6

Page 7: NLP8-semantics2-reduced - Compatibility Modecorsi.dei.polimi.it/nlp/download/NLP8-semantics2-reduced.pdf · 1. Key semantic elements are often widely distributed across parse trees

l Augmented CFG rule:

l The meaning representation assigned to A (called A.sem) is computed by function f on A’s costituents

CFG: semantic augmentation

ProperNoun→ AyCaramba AyCaramba{ }MassNoun→ meat Meat{ }NP→ ProperNoun ProperNoun.sem{ }NP→MassNoun MassNoun.sem{ }Verb→ serves λxλ y ∃e Isa(e,Serving)∧ Server(e, y)∧ Served(e,x){ }VP→Verb NP Verb.sem(NP.sem){ }S→ NP VP VP.sem(NP.sem){ }

7

A.sem = f(α1.sem, …, αn.sem)

E.g.: ProperNoun.sem = AyCaramba.sem = AyCaramba

AyCaramba

Page 8: NLP8-semantics2-reduced - Compatibility Modecorsi.dei.polimi.it/nlp/download/NLP8-semantics2-reduced.pdf · 1. Key semantic elements are often widely distributed across parse trees

CFG: semantic augmentation

λx P(x)(A) = P(A)λxλy P(x, y)(A) = P(A, y)

Lambda reduction

8

Example: semantics

Page 9: NLP8-semantics2-reduced - Compatibility Modecorsi.dei.polimi.it/nlp/download/NLP8-semantics2-reduced.pdf · 1. Key semantic elements are often widely distributed across parse trees

Idioms

l The principle of compositionability runs into truble with real language

l Often a sentence is more then the sum of its parts!l “Coupons are just the tip of the iceberg”

– The sentence is not speaking of icebergs!– Idiom “the tip of the iceberg” à “the beginning”

l Handling idioms: specialized semantic augmentations:NP→ the tip of the iceberg {Beginning}

9

Page 10: NLP8-semantics2-reduced - Compatibility Modecorsi.dei.polimi.it/nlp/download/NLP8-semantics2-reduced.pdf · 1. Key semantic elements are often widely distributed across parse trees

Semantic grammars

l Syntactic grammars are not well-suited for the task of semantic analysis

l Mismatch between structures provided by syntactic grammars, and those needed1. Key semantic elements are often widely distributed across

parse trees [because of issue 2] (this complicates composition)2. Parse trees contain syntactically-motivated constituents that

play no role in semantics processing (e.g., articles…)3. The general nature of syntactic constituents result in semantic

attachment that are often too general (“when does it arrives…”)l Semantic grammars permit to overcome these problems

– Grammars that describe the semantics of sentences10

Page 11: NLP8-semantics2-reduced - Compatibility Modecorsi.dei.polimi.it/nlp/download/NLP8-semantics2-reduced.pdf · 1. Key semantic elements are often widely distributed across parse trees

Semantic grammars“I want to go to eat some Italian food”l A semantic grammar:

InfoRequestà User want to go to eat FoodTypeFoodTypeà Nationality FoodType

“When does it arrive in Dallas?”l A semantic grammar:

InfoRequestà when does Flight arrive in City

– Notice that the “it” has a well-defined semantic meaning– Semantic grammars can help with ellipsis and anaphora,

because permits to know the expected parts of the sentencel Main drawback:

– Semantic grammars are domain-specific, reuse is difficult!11

Page 12: NLP8-semantics2-reduced - Compatibility Modecorsi.dei.polimi.it/nlp/download/NLP8-semantics2-reduced.pdf · 1. Key semantic elements are often widely distributed across parse trees

Information Extraction

l Simple approach:l Search for specific info to extractl Templates to fill

– Simple and predefined– Can be organized as a hierarchy

l Just a small subset of the text is used, the rest can be discarded

l Common tasks:– NER, relation detection, event detection, temporal analysis,

template filling12

Page 13: NLP8-semantics2-reduced - Compatibility Modecorsi.dei.polimi.it/nlp/download/NLP8-semantics2-reduced.pdf · 1. Key semantic elements are often widely distributed across parse trees

Named entity recognition (NER)

l Anything that can be referred to with a proper name– People, organization, location, geo-political entity, facility,

vehicle, temporal expression, numerical expression, …Citing high fuel prices, [ORG United Airlines] said

[TIME Friday] it has increased fares by [MONEY $6]l Approaches & tools:

– Regular expressions; e.g.: matching e-mail:([a-z0-9_\.-]+)@([\da-z\.-]+)\.([a-z\.]{2,6})

– Gazetteers (e.g., list of proper names)– Machine learning

l We present a machine learning methodology13

Page 14: NLP8-semantics2-reduced - Compatibility Modecorsi.dei.polimi.it/nlp/download/NLP8-semantics2-reduced.pdf · 1. Key semantic elements are often widely distributed across parse trees

NER & machine learning

l Word-by-word sequence labelingl Features: lexical items, POS, chunk

gazetteers, etc.

14

Page 15: NLP8-semantics2-reduced - Compatibility Modecorsi.dei.polimi.it/nlp/download/NLP8-semantics2-reduced.pdf · 1. Key semantic elements are often widely distributed across parse trees

Relation detectionl Find relations among the entities detected in a textl Machine learning approach

– Corpus: texts annotated with relations– Important feature: key words, NER, the sentence parse tree

15

Page 16: NLP8-semantics2-reduced - Compatibility Modecorsi.dei.polimi.it/nlp/download/NLP8-semantics2-reduced.pdf · 1. Key semantic elements are often widely distributed across parse trees

Temporal analysisl Recognizes:

– absolute points in time– relative times– durations

l Approaches:– Rule-based systems based on partial parsing or chunking

(i.e., searching for patterns)– Statistical sequence classifiers based on standard token-

by-token IBO encodingl Normalization: mapping a temporal expression to

either a specific point in time, or to a duration– “tomorrow at noon” à 2016-1-30T12:00.000+01:0016

Page 17: NLP8-semantics2-reduced - Compatibility Modecorsi.dei.polimi.it/nlp/download/NLP8-semantics2-reduced.pdf · 1. Key semantic elements are often widely distributed across parse trees

Event detectionl To identify mentions of events in texts and then

assign those events to predefined classes[EVENT Citing] high fuel prices, United Airlines [EVENT said] Friday it has [EVENT increased]fares by $6 per round trip

l Most event mentions correspond to verbsl Approaches:

– Rule-based and statistical machine learning – Both approaches make use of: POS, presence of

particular lexical items, and verb tense information17

Page 18: NLP8-semantics2-reduced - Compatibility Modecorsi.dei.polimi.it/nlp/download/NLP8-semantics2-reduced.pdf · 1. Key semantic elements are often widely distributed across parse trees

Template fillingl Many texts contain reports of events, and

possibly sequences of events, that often correspond to fairly common situations

l These abstract situations can be characterized as scripts

l Such scripts can be represented as templates– Fixed sets of slots which take as values slot-fillers

18

Page 19: NLP8-semantics2-reduced - Compatibility Modecorsi.dei.polimi.it/nlp/download/NLP8-semantics2-reduced.pdf · 1. Key semantic elements are often widely distributed across parse trees

Template filling: Machine Learning

l Train separate sequence classifiers for each slotto be filled

l Each classifier recognizes sequences of tokens as potential fillers for its particular slots

l Features: tokens, POS tags, syntactic chunk tags, and named entity tags

19