CPSC 503 Computational Linguistics Lecture 7 Giuseppe Carenini

  • Slides: 47
Download presentation
CPSC 503 Computational Linguistics Lecture 7 Giuseppe Carenini 9/16/2020 CPSC 503 Winter 2007 1

CPSC 503 Computational Linguistics Lecture 7 Giuseppe Carenini 9/16/2020 CPSC 503 Winter 2007 1

Knowledge-Formalisms Map (next three lectures) Morphology State Machines (and prob. versions) (Finite State Automata,

Knowledge-Formalisms Map (next three lectures) Morphology State Machines (and prob. versions) (Finite State Automata, Finite State Transducers, Markov Models) Syntax Semantics Pragmatics Discourse and Dialogue Rule systems (and prob. versions) (e. g. , (Prob. ) Context-Free Grammars) Logical formalisms (First-Order Logics) AI planners 9/16/2020 CPSC 503 Winter 2007 2

Today 2/10 • English Syntax • Context-Free Grammar for English – – Rules Trees

Today 2/10 • English Syntax • Context-Free Grammar for English – – Rules Trees Recursion Problems • Start Parsing 9/16/2020 CPSC 503 Winter 2007 3

Syntactic Notions so far. . . • N-grams: prob. distr. for next word can

Syntactic Notions so far. . . • N-grams: prob. distr. for next word can be effectively approximated knowing previous n words • POS categories are based on: – distributional properties (what other words can occur nearby) – morphological properties (affixes they take) 9/16/2020 CPSC 503 Winter 2007 4

Syntax Def. The study of how sentences are formed by grouping and ordering words

Syntax Def. The study of how sentences are formed by grouping and ordering words Example: Ming and Sue prefer morning flights * Ming Sue flights morning and prefer Groups behave as single unit wrt Substitution, Movement, Coordination 9/16/2020 CPSC 503 Winter 2007 5

Syntax: Useful tasks • Why should you care? – Grammar checkers – Basis for

Syntax: Useful tasks • Why should you care? – Grammar checkers – Basis for semantic interpretation • Question answering • Information extraction • Summarization – Machine translation – …… 9/16/2020 CPSC 503 Winter 2007 6

Key Constituents - heads (English) (Specifier) • • • Noun phrases Verb phrases Prepositional

Key Constituents - heads (English) (Specifier) • • • Noun phrases Verb phrases Prepositional phrases Adjective phrases Sentences • • • (Det) (Qual) (Deg) (NP) X (Complement) N V P A (I) (PP) (NP) (PP) (VP) Some simple specifiers Category Typical function Examples Determiner specifier of N the, a, this, no. . Qualifier specifier of V never, often. . Degree word specifier of A or P very, almost. . 9/16/2020 CPSC 503 Winter 2007 Complements? 7

Key Constituents: Examples • (Det) N (PP) the cat on the table • (Qual)

Key Constituents: Examples • (Det) N (PP) the cat on the table • (Qual) V (NP) Verb phrases never eat a cat P (NP) Prepositional phrases • (Deg) almost in the net • (Deg) A (PP) Adjective phrases very happy about it • (NP) (I) (VP) Sentences a mouse -- ate it • Noun phrases • • 9/16/2020 CPSC 503 Winter 2007 8

Context Free Grammar (Example) Start-symbol • S -> NP VP • • • NP

Context Free Grammar (Example) Start-symbol • S -> NP VP • • • NP -> Det NOMINAL -> Noun VP -> Verb Det -> a Noun -> flight Verb -> left 9/16/2020 CPSC 503 Winter 2007 Non-terminal Terminal 9

CFG more complex Example Grammar with example phrases 9/16/2020 CPSC 503 Winter 2007 Lexicon

CFG more complex Example Grammar with example phrases 9/16/2020 CPSC 503 Winter 2007 Lexicon 10

CFGs • Define a Formal Language (un/grammatical sentences) • Generative Formalism – Generate strings

CFGs • Define a Formal Language (un/grammatical sentences) • Generative Formalism – Generate strings in the language – Reject strings not in the language – Impose structures (trees) on strings in the language 9/16/2020 CPSC 503 Winter 2007 11

CFG: Formal Definitions • 4 -tuple (non-term. , productions, start) • (N, , P,

CFG: Formal Definitions • 4 -tuple (non-term. , productions, start) • (N, , P, S) • P is a set of rules A ; A N, ( N)* • A derivation is the process of rewriting 1 into m (both strings in ( N)*) by applying a sequence of rules: 1 * m • L G = W|w * and S * w 9/16/2020 CPSC 503 Winter 2007 12

Derivations as Trees Nominal flight 9/16/2020 CPSC 503 Winter 2007 Context Free? 13

Derivations as Trees Nominal flight 9/16/2020 CPSC 503 Winter 2007 Context Free? 13

CFG Parsing I prefer a morning flight Nominal Parser Nominal flight • It is

CFG Parsing I prefer a morning flight Nominal Parser Nominal flight • It is completely analogous to running a finite-state transducer with a tape – It’s just more powerful • Chpt. 13 9/16/2020 CPSC 503 Winter 2007 14

Other Options • Regular languages (FSA) A x. B or A x – Too

Other Options • Regular languages (FSA) A x. B or A x – Too weak (e. g. , cannot deal with recursion in a general way – no center-embedding) • CFGs A (also produce more understandable and “useful” structure) • Context-sensitive A ; ≠ – Can be computationally intractable • Turing equiv. ; ≠ – Too powerful / Computationally intractable 9/16/2020 CPSC 503 Winter 2007 15

Common Sentence-Types • Declaratives: A plane left S -> NP VP • Imperatives: Leave!

Common Sentence-Types • Declaratives: A plane left S -> NP VP • Imperatives: Leave! S -> VP • Yes-No Questions: Did the plane leave? S -> Aux NP VP • WH Questions: Which flights serve breakfast? S -> WH NP VP When did the plane leave? S -> WH Aux NP VP 9/16/2020 CPSC 503 Winter 2007 16

NP: more details NP -> Specifiers N Complements • NP -> (Predet)(Det)(Card)(Ord)(Quant) (AP) Nom

NP: more details NP -> Specifiers N Complements • NP -> (Predet)(Det)(Card)(Ord)(Quant) (AP) Nom e. g. , all the other cheap cars • Nom -> Nom PP (PP) e. g. , reservation on BA 456 from NY to YVR Nom -> Nom Gerund. VP e. g. , flight arriving on Monday Nom -> Nom Rel. Clause ->(who | that) VP e. g. , flight that arrives in the evening 9/16/2020 CPSC 503 Winter 2007 17

Conjunctive Constructions • S -> S and S – John went to NY and

Conjunctive Constructions • S -> S and S – John went to NY and Mary followed him • NP -> NP and NP – John went to NY and Boston • VP -> VP and VP – John went to NY and visited MOMA • … • In fact the right rule for English is X -> X and X 9/16/2020 CPSC 503 Winter 2007 18

Problems with CFGs • Agreement • Subcategorization 9/16/2020 CPSC 503 Winter 2007 19

Problems with CFGs • Agreement • Subcategorization 9/16/2020 CPSC 503 Winter 2007 19

Agreement • In English, – Determiners and nouns have to agree in number –

Agreement • In English, – Determiners and nouns have to agree in number – Subjects and verbs have to agree in person and number • Many languages have agreement systems that are far more complex than this (e. g. , gender). 9/16/2020 CPSC 503 Winter 2007 20

Agreement • This dog • Those dogs • *This dogs • *Those dog •

Agreement • This dog • Those dogs • *This dogs • *Those dog • This dog eats • You have it • Those dogs eat • *This dog eat • *You has it • *Those dogs eats 9/16/2020 CPSC 503 Winter 2007 21

Possible CFG Solution OLD Grammar • S -> NP VP • • NP ->

Possible CFG Solution OLD Grammar • S -> NP VP • • NP -> Det Nominal • • VP -> V NP • • … • • 9/16/2020 NEW Grammar Sg. S -> Sg. NP Sg. VP Pl. S -> Pl. Np Pl. VP Sg. NP -> Sg. Det Sg. Nom Pl. NP -> Pl. Det Pl. Nom Pl. VP -> Pl. V NP Sg. VP ->Sg. V NP … Sg = singular Pl = plural CPSC 503 Winter 2007 22

CFG Solution for Agreement • It works and stays within the power of CFGs

CFG Solution for Agreement • It works and stays within the power of CFGs • But it doesn’t scale all that well (explosion in the number of rules) 9/16/2020 CPSC 503 Winter 2007 23

Subcategorization • Def. It expresses constraints that a predicate (verb here) places on the

Subcategorization • Def. It expresses constraints that a predicate (verb here) places on the number and type of its arguments (see first table) • *John sneezed the book • *I prefer United has a flight • *Give with a flight 9/16/2020 CPSC 503 Winter 2007 24

Subcategorization • • Sneeze: John sneezed Find: Please find [a flight to NY]NP Give:

Subcategorization • • Sneeze: John sneezed Find: Please find [a flight to NY]NP Give: Give [me]NP[a cheaper fare]NP Help: Can you help [me]NP[with a flight]PP Prefer: I prefer [to leave earlier]TO-VP Told: I was told [United has a flight]S … 9/16/2020 CPSC 503 Winter 2007 25

So? • So the various rules for VPs overgenerate. – They allow strings containing

So? • So the various rules for VPs overgenerate. – They allow strings containing verbs and arguments that don’t go together – For example: • VP -> V NP therefore Sneezed the book • VP -> V S therefore go she will go there 9/16/2020 CPSC 503 Winter 2007 26

Possible CFG Solution OLD Grammar • • • VP -> V NP PP •

Possible CFG Solution OLD Grammar • • • VP -> V NP PP • • … • NEW Grammar VP -> Intrans. V VP -> Trans. V NP VP -> Trans. PPto NP PPto … Trans. PPto -> hand, give, . . This solution has the same problem as the one for agreement 9/16/2020 CPSC 503 Winter 2007 27

CFG for NLP: summary • CFGs cover most syntactic structure in English. • But

CFG for NLP: summary • CFGs cover most syntactic structure in English. • But there are problems (overgeneration) – That can be dealt with adequately, although not elegantly, by staying within the CFG framework. • There are simpler, more elegant, solutions that take us out of the CFG framework Chpt 16 “Features and Unification” 9/16/2020 CPSC 503 Winter 2007 28

Dependency Grammars • Syntactic structure: binary relations between words • Links: grammatical function or

Dependency Grammars • Syntactic structure: binary relations between words • Links: grammatical function or very general semantic relation • Abstract away from word-order variations (simpler grammars) • Useful features in many NLP applications 9/16/2020 classification, CPSC 503 Winter 2007 29 (for summarization and NLG)

Today 2/10 • English Syntax • Context-Free Grammar for English – – Rules Trees

Today 2/10 • English Syntax • Context-Free Grammar for English – – Rules Trees Recursion Problems • Start Parsing 9/16/2020 CPSC 503 Winter 2007 30

Parsing with CFGs Valid parse trees Sequence of words I prefer a morning flight

Parsing with CFGs Valid parse trees Sequence of words I prefer a morning flight Parser Nominal CFG flight Assign valid trees: covers all and only the elements of the input and has an S at the top 9/16/2020 CPSC 503 Winter 2007 31

CFG • • Parsing as Search S -> NP VP S -> Aux NP

CFG • • Parsing as Search S -> NP VP S -> Aux NP VP NP -> Det Noun VP -> Verb Det -> a Noun -> flight Verb -> left, arrive Aux -> do, does Search space of possible parse trees defines Parsing: find all trees that cover all and only the words in the input 9/16/2020 CPSC 503 Winter 2007 32

Constraints on Search Sequence of words Valid parse trees I prefer a morning flight

Constraints on Search Sequence of words Valid parse trees I prefer a morning flight CFG (search space) Parser Nominal flight Search Strategies: • Top-down or goal-directed • Bottom-up or data-directed 9/16/2020 CPSC 503 Winter 2007 33

Top-Down Parsing • Since we’re trying to find trees rooted with an S (Sentences)

Top-Down Parsing • Since we’re trying to find trees rooted with an S (Sentences) start with the rules that give us an S. • Then work your way down from there to the words. Input: flight 9/16/2020 CPSC 503 Winter 2007 34

Next step: Top Down Space ……. . • When POS categories are reached, reject

Next step: Top Down Space ……. . • When POS categories are reached, reject trees whose leaves fail to match all words in the input 9/16/2020 CPSC 503 Winter 2007 35

Bottom-Up Parsing • Of course, we also want trees that cover the input words.

Bottom-Up Parsing • Of course, we also want trees that cover the input words. So start with trees that link up with the words in the right way. • Then work your way up from there. flight 9/16/2020 CPSC 503 Winter 2007 36

Two more steps: Bottom-Up Space ……. . flight 9/16/2020 ……. . CPSC 503 Winter

Two more steps: Bottom-Up Space ……. . flight 9/16/2020 ……. . CPSC 503 Winter 2007 flight 37

Top-Down vs. Bottom-Up • Top-down – Only searches for trees that can be answers

Top-Down vs. Bottom-Up • Top-down – Only searches for trees that can be answers – But suggests trees that are not consistent with the words • Bottom-up – Only forms trees consistent with the words – Suggest trees that make no sense globally 9/16/2020 CPSC 503 Winter 2007 38

So Combine Them • Top-down: control strategy to generate trees • Bottom-up: to filter

So Combine Them • Top-down: control strategy to generate trees • Bottom-up: to filter out inappropriate parses Top-down Control strategy: • Depth vs. Breadth first • Which node to try to expand next (left-most) • Which grammar rule to use to expand a node (textual order) 9/16/2020 CPSC 503 Winter 2007 39

Top-Down, Depth-First, Left-to. Right Search Sample sentence: “Does this flight include a meal? ”

Top-Down, Depth-First, Left-to. Right Search Sample sentence: “Does this flight include a meal? ” 9/16/2020 CPSC 503 Winter 2007 40

Example 9/16/2020 “Does this flight include a meal? ” CPSC 503 Winter 2007 41

Example 9/16/2020 “Does this flight include a meal? ” CPSC 503 Winter 2007 41

Example “Does this flight include a meal? ” flight 9/16/2020 CPSC 503 Winter 2007

Example “Does this flight include a meal? ” flight 9/16/2020 CPSC 503 Winter 2007 flight 42

Example “Does this flight include a meal? ” flight 9/16/2020 flight CPSC 503 Winter

Example “Does this flight include a meal? ” flight 9/16/2020 flight CPSC 503 Winter 2007 43

Adding Bottom-up Filtering The following sequence was a waste of time because an NP

Adding Bottom-up Filtering The following sequence was a waste of time because an NP cannot generate a parse tree starting with an AUX Aux 9/16/2020 Aux CPSC 503 Winter 2007 Aux 44

Bottom-Up Filtering Category Left Corners S Det, Proper-Noun, Aux, Verb NP Nominal Noun VP

Bottom-Up Filtering Category Left Corners S Det, Proper-Noun, Aux, Verb NP Nominal Noun VP Verb Aux 9/16/2020 Det, Proper-Noun Aux CPSC 503 Winter 2007 45

Problems with TD-BU-filtering • Left recursion • Ambiguity • Repeated Parsing • SOLUTION: Earley

Problems with TD-BU-filtering • Left recursion • Ambiguity • Repeated Parsing • SOLUTION: Earley Algorithm (once again dynamic programming!) 9/16/2020 CPSC 503 Winter 2007 46

For Next Time • Read Chapter 13 (Parsing) • Optional: Read Chapter 16 (Features

For Next Time • Read Chapter 13 (Parsing) • Optional: Read Chapter 16 (Features and Unification) – skip algorithms and implementation 9/16/2020 CPSC 503 Winter 2007 47