Phrase Structure and Parsing as Search

Similar documents
Syntax Parsing 1. Grammars and parsing 2. Top-down and bottom-up parsing 3. Chart parsers 4. Bottom-up chart parsing 5. The Earley Algorithm

Basic Parsing with Context-Free Grammars. Some slides adapted from Julia Hirschberg and Dan Jurafsky 1

Grammars & Parsing, Part 1:

CS 598 Natural Language Processing

Parsing of part-of-speech tagged Assamese Texts

Context Free Grammars. Many slides from Michael Collins

Basic Syntax. Doug Arnold We review some basic grammatical ideas and terminology, and look at some common constructions in English.

Informatics 2A: Language Complexity and the. Inf2A: Chomsky Hierarchy

Introduction to HPSG. Introduction. Historical Overview. The HPSG architecture. Signature. Linguistic Objects. Descriptions.

11/29/2010. Statistical Parsing. Statistical Parsing. Simple PCFG for ATIS English. Syntactic Disambiguation

Developing a TT-MCTAG for German with an RCG-based Parser

Chapter 4: Valence & Agreement CSLI Publications

Natural Language Processing. George Konidaris

Approaches to control phenomena handout Obligatory control and morphological case: Icelandic and Basque

ENGBG1 ENGBL1 Campus Linguistics. Meeting 2. Chapter 7 (Morphology) and chapter 9 (Syntax) Pia Sundqvist

Proof Theory for Syntacticians

Argument structure and theta roles

Derivational: Inflectional: In a fit of rage the soldiers attacked them both that week, but lost the fight.

Developing Grammar in Context

Compositional Semantics

Control and Boundedness

Some Principles of Automated Natural Language Information Extraction

Constraining X-Bar: Theta Theory

1/20 idea. We ll spend an extra hour on 1/21. based on assigned readings. so you ll be ready to discuss them in class

Language Acquisition Fall 2010/Winter Lexical Categories. Afra Alishahi, Heiner Drenhaus

Inleiding Taalkunde. Docent: Paola Monachesi. Blok 4, 2001/ Syntax 2. 2 Phrases and constituent structure 2. 3 A minigrammar of Italian 3

Parsing natural language

A Minimalist Approach to Code-Switching. In the field of linguistics, the topic of bilingualism is a broad one. There are many

Ch VI- SENTENCE PATTERNS.

Enhancing Unlexicalized Parsing Performance using a Wide Coverage Lexicon, Fuzzy Tag-set Mapping, and EM-HMM-based Lexical Probabilities

Towards a MWE-driven A* parsing with LTAGs [WG2,WG3]

An Introduction to the Minimalist Program

RANKING AND UNRANKING LEFT SZILARD LANGUAGES. Erkki Mäkinen DEPARTMENT OF COMPUTER SCIENCE UNIVERSITY OF TAMPERE REPORT A ER E P S I M S

Writing a composition

2/15/13. POS Tagging Problem. Part-of-Speech Tagging. Example English Part-of-Speech Tagsets. More Details of the Problem. Typical Problem Cases

The Interface between Phrasal and Functional Constraints

An Interactive Intelligent Language Tutor Over The Internet

Using dialogue context to improve parsing performance in dialogue systems

The presence of interpretable but ungrammatical sentences corresponds to mismatches between interpretive and productive parsing.

COMPUTATIONAL COMPLEXITY OF LEFT-ASSOCIATIVE GRAMMAR

Words come in categories

Part I. Figuring out how English works

LNGT0101 Introduction to Linguistics

Case government vs Case agreement: modelling Modern Greek case attraction phenomena in LFG

LTAG-spinal and the Treebank

Language properties and Grammar of Parallel and Series Parallel Languages

a) analyse sentences, so you know what s going on and how to use that information to help you find the answer.

Ensemble Technique Utilization for Indonesian Dependency Parser

Advanced Grammar in Use

"f TOPIC =T COMP COMP... OBJ

BULATS A2 WORDLIST 2

Chunk Parsing for Base Noun Phrases using Regular Expressions. Let s first let the variable s0 be the sentence tree of the first sentence.

The College Board Redesigned SAT Grade 12

Construction Grammar. University of Jena.

A Computational Evaluation of Case-Assignment Algorithms

SAMPLE. Chapter 1: Background. A. Basic Introduction. B. Why It s Important to Teach/Learn Grammar in the First Place

Mercer County Schools

Dear Teacher: Welcome to Reading Rods! Reading Rods offer many outstanding features! Read on to discover how to put Reading Rods to work today!

Machine Learning from Garden Path Sentences: The Application of Computational Linguistics

BANGLA TO ENGLISH TEXT CONVERSION USING OPENNLP TOOLS

Today we examine the distribution of infinitival clauses, which can be

Hindi Aspectual Verb Complexes

Intra-talker Variation: Audience Design Factors Affecting Lexical Selections

Hindi-Urdu Phrase Structure Annotation

Prediction of Maximal Projection for Semantic Role Labeling

Analysis of Probabilistic Parsing in NLP

Accurate Unlexicalized Parsing for Modern Hebrew

A Usage-Based Approach to Recursion in Sentence Processing

Aspectual Classes of Verb Phrases

Pre-Processing MRSes

BASIC ENGLISH. Book GRAMMAR

Chinese Language Parsing with Maximum-Entropy-Inspired Parser

How to analyze visual narratives: A tutorial in Visual Narrative Grammar

Cognitive Modeling. Tower of Hanoi: Description. Tower of Hanoi: The Task. Lecture 5: Models of Problem Solving. Frank Keller.

Chapter 9 Banked gap-filling

Type Theory and Universal Grammar

The Discourse Anaphoric Properties of Connectives

UNIVERSITY OF OSLO Department of Informatics. Dialog Act Recognition using Dependency Features. Master s thesis. Sindre Wetjen

SINGLE DOCUMENT AUTOMATIC TEXT SUMMARIZATION USING TERM FREQUENCY-INVERSE DOCUMENT FREQUENCY (TF-IDF)

SAMPLE PAPER SYLLABUS

Multiple case assignment and the English pseudo-passive *

A R "! I,,, !~ii ii! A ow ' r.-ii ' i ' JA' V5, 9. MiN, ;

Specifying Logic Programs in Controlled Natural Language

AQUA: An Ontology-Driven Question Answering System

ELD CELDT 5 EDGE Level C Curriculum Guide LANGUAGE DEVELOPMENT VOCABULARY COMMON WRITING PROJECT. ToolKit

The stages of event extraction

NAME OF ASSESSMENT: Reading Informational Texts and Argument Writing Performance Assessment

Universal Grammar 2. Universal Grammar 1. Forms and functions 1. Universal Grammar 3. Conceptual and surface structure of complex clauses

Adjectives tell you more about a noun (for example: the red dress ).

Module 12. Machine Learning. Version 2 CSE IIT, Kharagpur

Chapter 3: Semi-lexical categories. nor truly functional. As Corver and van Riemsdijk rightly point out, There is more

Dependency, licensing and the nature of grammatical relations *

Underlying and Surface Grammatical Relations in Greek consider

Campus Academic Resource Program An Object of a Preposition: A Prepositional Phrase: noun adjective

Refining the Design of a Contracting Finite-State Dependency Parser

Sample Goals and Benchmarks

Language and Computers. Writers Aids. Introduction. Non-word error detection. Dictionaries. N-gram analysis. Isolated-word error correction

1 st Quarter (September, October, November) August/September Strand Topic Standard Notes Reading for Literature

CAS LX 522 Syntax I. Long-distance wh-movement. Long distance wh-movement. Islands. Islands. Locality. NP Sea. NP Sea

Procedia - Social and Behavioral Sciences 154 ( 2014 )

Transcription:

Phrase Structure and Parsing as Search Informatics 2A: Lecture 19 Shay Cohen School of Informatics University of Edinburgh 30 October 2017 1 / 66

Last class Part-of-speech tagging and its applications The use of hidden Markov models for POS tagging The Viterbi algorithm Weighted finite-state automata and their use in applications like speech recognition, machine translation (similarly: optical character recognition, predictive text, poetry generation...) 2 / 66

1 Phrase Structure Heads and Phrases Desirable Properties of a Grammar A Fragment of English 2 Grammars and Parsing Recursion Structural Ambiguity Recursive Descent Parsing Shift-Reduce Parsing 3 / 66

Computing meaning A well-studied, difficult, and unsolved problem. Fortunately, we know enough to have made partial progress (Watson won). Over the next few weeks, we will work up to the study of systems that can assign logical forms that mathematically state the meaning of a sentence, so that they can be processed by machines. Our first stop will be natural language syntax. 4 / 66

atural language syntax Syntax provides the scaffolding for semantic composition. The brown dog on the mat saw the striped cat through the window. 5 / 66

atural language syntax Syntax provides the scaffolding for semantic composition. The brown dog on the mat saw the striped cat through the window. The brown cat saw the striped dog through the window on the mat. 5 / 66

atural language syntax Syntax provides the scaffolding for semantic composition. The brown dog on the mat saw the striped cat through the window. The brown cat saw the striped dog through the window on the mat. Do the two sentences above mean the same thing? What is the process by which you computed their meanings? 5 / 66

Constituents Words in a sentence often form groupings that can combine with other units to produce meaning. These groupings, called consituents can often be identified by substitution tests (much like parts of speech!) Kim [read a book], [gave it to Sandy], and [left] You said I should read the book and [read it] I did. Kim read [a very interesting book about grammar]. 6 / 66

Heads and Phrases oun (): oun Phrase () Adjective (A): Adjective Phrase (AP) Verb (V): Verb Phrase (VP) Preposition (P): Prepositional Phrase (PP) So far we have looked at terminals (words or POS tags). Today, we ll look at non-terminals, which correspond to phrases. The part of speech that a word belongs to is closely linked to the type of constituent that it is associated with. In a X-phrase (eg ), the key occurrence of X (eg ) is called the head, and controls how the phrase interacts (both syntactically and semantically) with the rest of the sentence. In English, the head tends to appear in the middle of a phrase. 7 / 66

Constituents have structure English s are commonly of the form: () Adj* oun (PP RelClause)* : the angry duck that tried to bite me, VPs are commonly of the form: (Aux) Adv* Verb Arg* Adjunct* Arg PP Adjunct PP AdvP... VP: usually eats artichokes for dinner,. In Japanese, Korean, Hindi, Urdu, and other head-final languages, the head is at the end of its associated phrase. In Irish, Welsh, Scots Gaelic and other head-initial languages, the head is at the beginning of its associated phrase. 8 / 66

Constituents have structure English s are commonly of the form: () Adj* oun (PP RelClause)* : the angry duck that tried to bite me, head: duck. VPs are commonly of the form: (Aux) Adv* Verb Arg* Adjunct* Arg PP Adjunct PP AdvP... VP: usually eats artichokes for dinner,. In Japanese, Korean, Hindi, Urdu, and other head-final languages, the head is at the end of its associated phrase. In Irish, Welsh, Scots Gaelic and other head-initial languages, the head is at the beginning of its associated phrase. 8 / 66

Constituents have structure English s are commonly of the form: () Adj* oun (PP RelClause)* : the angry duck that tried to bite me, head: duck. VPs are commonly of the form: (Aux) Adv* Verb Arg* Adjunct* Arg PP Adjunct PP AdvP... VP: usually eats artichokes for dinner, head: eat. In Japanese, Korean, Hindi, Urdu, and other head-final languages, the head is at the end of its associated phrase. In Irish, Welsh, Scots Gaelic and other head-initial languages, the head is at the beginning of its associated phrase. 8 / 66

Desirable Properties of a Grammar Chomsky specified two properties that make a grammar interesting and satisfying : It should be a finite specification of the strings of the language, rather than a list of its sentences. It should be revealing, in allowing strings to be associated with meaning (semantics) in a systematic way. We can add another desirable property: It should capture structural and distributional properties of the language. (E.g. where heads of phrases are located; how a sentence transforms into a question; which phrases can float around the sentence.) 9 / 66

Desirable Properties of a Grammar Context-free grammars (CFGs) provide a pretty good approximation. Some features of Ls are more easily captured using mildly context-sensitive grammars, as well see later in the course. There are also more modern grammar formalisms that better capture structural and distributional properties of human languages. (E.g. combinatory categorial grammar.) But LL(1) grammars and the like definitely aren t enough for Ls. Even if we could make a L grammar LL(1), we wouldn t want to: this would artificially suppress ambiguities, and would often mutilate the natural structure of sentences. 10 / 66

A Tiny Fragment of English Let s say we want to capture in a grammar the structural and distributional properties that give rise to sentences like: A duck walked in the park. The man walked with a duck. You made a duck. You made her duck. A man with a telescope saw you. A man saw you with a telescope. You saw a man with a telescope.,v,pp,v,pp Pro,V,? Pro,V,,PP,V,Pro,V,Pro,PP Pro,V,,PP We want to write grammatical rules that generate these phrase structures, and lexical rules that generate the words appearing in them. 11 / 66

A Tiny Fragment of English Let s say we want to capture in a grammar the structural and distributional properties that give rise to sentences like: A duck walked in the park. The man walked with a duck. You made a duck. You made her duck. A man with a telescope saw you. A man saw you with a telescope. You saw a man with a telescope.,v,pp,v,pp Pro,V,? Pro,V,,PP,V,Pro,V,Pro,PP Pro,V,,PP We want to write grammatical rules that generate these phrase structures, and lexical rules that generate the words appearing in them. 11 / 66

A Tiny Fragment of English Let s say we want to capture in a grammar the structural and distributional properties that give rise to sentences like: A duck walked in the park. The man walked with a duck. You made a duck. You made her duck. A man with a telescope saw you. A man saw you with a telescope. You saw a man with a telescope.,v,pp,v,pp Pro,V,? Pro,V,,PP,V,Pro,V,Pro,PP Pro,V,,PP We want to write grammatical rules that generate these phrase structures, and lexical rules that generate the words appearing in them. 11 / 66

A Tiny Fragment of English Let s say we want to capture in a grammar the structural and distributional properties that give rise to sentences like: A duck walked in the park. The man walked with a duck. You made a duck. You made her duck. A man with a telescope saw you. A man saw you with a telescope. You saw a man with a telescope.,v,pp,v,pp Pro,V,? Pro,V,,PP,V,Pro,V,Pro,PP Pro,V,,PP We want to write grammatical rules that generate these phrase structures, and lexical rules that generate the words appearing in them. 11 / 66

A Tiny Fragment of English Let s say we want to capture in a grammar the structural and distributional properties that give rise to sentences like: A duck walked in the park. The man walked with a duck. You made a duck. You made her duck. A man with a telescope saw you. A man saw you with a telescope. You saw a man with a telescope.,v,pp,v,pp Pro,V,? Pro,V,,PP,V,Pro,V,Pro,PP Pro,V,,PP We want to write grammatical rules that generate these phrase structures, and lexical rules that generate the words appearing in them. 11 / 66

Grammar for the Tiny Fragment of English Grammar G1 generates the sentences on the previous slide: Grammatical rules S VP PP Pro VP V PP VP V VP V PP Prep Lexical rules a the her (determiners) man park duck telescope (nouns) Pro you (pronoun) V saw walked made (verbs) Prep in with for (prepositions) Does G1 produce a finite or an infinite number of sentences? 12 / 66

Recursion Recursion in a grammar makes it possible to generate an infinite number of sentences. In direct recursion, a non-terminal on the LHS of a rule also appears on its RHS. The following rules add direct recursion to G1: VP VP Conj VP Conj and or In indirect recursion, some non-terminal can be expanded (via several steps) to a sequence of symbols containing that non-terminal: PP PP Prep 13 / 66

Structural Ambiguity You saw a man with a telescope. S VP Pro You V PP saw Prep a man with a telescope 14 / 66

Structural Ambiguity You saw a man with a telescope. S VP Pro You V saw PP a man Prep with a telescope 15 / 66

Structural Ambiguity You saw a man with a telescope. S S VP Pro You V VP PP Pro You V saw PP saw a man Prep with a man Prep with a telescope This illustrates attachment ambiguity: the PP can be a part of the VP or of the. ote that there s no POS ambiguity here. a telescope 16 / 66

Structural Ambiguity You saw a man with a telescope. S S VP Pro You V VP PP Pro You V saw PP saw a man Prep with a man Prep with a telescope This illustrates attachment ambiguity: the PP can be a part of the VP or of the. ote that there s no POS ambiguity here. a telescope 16 / 66

Structural Ambiguity You saw a man with a telescope. S S VP Pro You V VP PP Pro You V saw PP saw a man Prep with a man Prep with a telescope This illustrates attachment ambiguity: the PP can be a part of the VP or of the. ote that there s no POS ambiguity here. a telescope 16 / 66

Structural Ambiguity Grammar G1 only gives us one analysis of you made her duck. S VP Pro V You made her duck There is another, ditransitive (i.e., two-object) analysis of this sentence one that underlies the pair: What did you make for her? You made her duck. 17 / 66

Structural Ambiguity For this alternative, G1 also needs rules like: VP V Pro her S S VP VP Pro You V made Pro You V made Pro her duck her duck In this case, the structural ambiguity is rooted in POS ambiguity. 18 / 66

Structural Ambiguity There is a third analysis as well, one that underlies the pair: What did you make her do? You made her duck. Here, the small clause (her duck) is the direct object of a verb. Similar small clauses are possible with verbs like see, hear and notice, but not ask, want, persuade, etc. G1 needs a rule that requires accusative case-marking on the subject of a small clause and no tense on its verb.: VP V S1 S1 (acc) VP(untensed) (acc) her him them 19 / 66

Structural Ambiguity There is a third analysis as well, one that underlies the pair: What did you make her do? You made her duck. (move head or body quickly downwards) Here, the small clause (her duck) is the direct object of a verb. Similar small clauses are possible with verbs like see, hear and notice, but not ask, want, persuade, etc. G1 needs a rule that requires accusative case-marking on the subject of a small clause and no tense on its verb.: VP V S1 S1 (acc) VP(untensed) (acc) her him them 19 / 66

Structural Ambiguity ow we have three analyses for you made her duck: S S S VP VP VP Pro V Pro V Pro V S Pro (acc) VP V You made her duck You made her duck You made her duck How can we compute these analyses automatically? 20 / 66

A Fun Exercise - Which is the VP? (a) (b) (c) A new one? (d) (e) (f) watched the train from the window with my binoculars 21 / 66

A Fun Exercise - Which is the VP? (a) (b) (c) A new one? (d) (e) (f) watched the train from the window with my binoculars E 21 / 66

A Fun Exercise - Which is the VP? (a) (b) (c) A new one? (d) (e) (f) watched the train from the window on the wall 22 / 66

A Fun Exercise - Which is the VP? (a) (b) (c) A new one? (d) (e) (f) watched the train from the window on the wall A 22 / 66

A Fun Exercise - Which is the VP? (a) (b) (c) A new one? (d) (e) (f) watched a show by etflix about the starship 23 / 66

A Fun Exercise - Which is the VP? (a) (b) (c) A new one? (d) (e) (f) watched a show by etflix about the starship D 23 / 66

A Fun Exercise - Which is the VP? (a) (b) (c) A new one? (d) (e) (f) watched a show about the expedition to space 24 / 66

A Fun Exercise - Which is the VP? (a) (b) (c) A new one? (d) (e) (f) watched a show about the expedition to space C 24 / 66

A Fun Exercise - Which is the VP? (a) (b) (c) A new one? (d) (e) (f) watched a video about the commet on my mobile 25 / 66

A Fun Exercise - Which is the VP? (a) (b) (c) A new one? (d) (e) (f) watched a video about the commet on my mobile B 25 / 66

Parsing Algorithms A parser is an algorithm that computes a structure for an input string given a grammar. All parsers have two fundamental properties: Directionality: the sequence in which the structures are constructed (e.g., top-down or bottom-up). Search strategy: the order in which the search space of possible analyses is explored (e.g., depth-first, breadth-first). For instance, LL(1) parsing is top-down and depth-first. 26 / 66

Coming up: A zoo of parsing algorithms As we ve noted, LL(1) isn t good enough for L. We ll be looking at other parsing algorithms that work for more general CFGs. Recursive descent parsers (top-down). Simple and very general, but inefficient. Other problems Shift-reduce parsers (bottom-up). The Cocke-Younger-Kasami algorithm (bottom up). Works for any CFG with reasonable efficiency. The Earley algorithm (top down). Chart parsing enhanced with prediction. 27 / 66

Recursive Descent Parsing A recursive descent parser treats a grammar as a specification of how to break down a top-level goal into subgoals. Therefore: Parser searches through the trees licensed by the grammar to find the one that has the required sentence along its yield. Directionality = top-down: It starts from the start symbol of the grammar, and works its way down to the terminals. Search strategy = depth-first: It expands a given terminal as far as possible before proceeding to the next one. 28 / 66

Algorithm Sketch: Recursive Descent Parsing 1 The top-level goal is to derive the start symbol (S). 2 Choose a grammatical rule with S as its LHS (e.g, S VP), and replace S with the RHS of the rule (the subgoals; e.g., and VP). 3 Choose a rule with the leftmost subgoal as its LHS (e.g., ). Replace the subgoal with the RHS of the rule. 4 Whenever you reach a lexical rule (e.g., the), match its RHS against the current position in the input string. If it matches, move on to next position in the input. If it doesn t, try next lexical rule with the same LHS. If no rules with same LHS, backtrack to most recent choice of grammatical rule and choose another rule with the same LHS. If no more grammatical rules, back up to the previous subgoal. 5 Iterate until the whole input string is consumed, or you fail to match one of the positions in the input. Backtrack on failure. 29 / 66

Recursive Descent Parsing S the dog saw a man in the park 30 / 66

Recursive Descent Parsing S VP the dog saw a man in the park 31 / 66

Recursive Descent Parsing S VP PP the dog saw a man in the park 32 / 66

Recursive Descent Parsing S VP PP the the dog saw a man in the park 33 / 66

Recursive Descent Parsing S VP PP the the dog saw a man in the park 34 / 66

Recursive Descent Parsing S VP PP man the the dog saw a man in the park 35 / 66

Recursive Descent Parsing S VP park PP the the dog saw a man in the park 36 / 66

Recursive Descent Parsing S VP PP the dog the dog saw a man in the park 37 / 66

Recursive Descent Parsing S VP PP P the dog the dog saw a man in the park 38 / 66

Recursive Descent Parsing S VP PP P in the dog the dog saw a man in the park 39 / 66

Recursive Descent Parsing S VP the the dog saw a man in the park 40 / 66

Recursive Descent Parsing S VP the dog the dog saw a man in the park 41 / 66

Recursive Descent Parsing S VP V PP the dog saw the dog saw a man in the park 42 / 66

Recursive Descent Parsing S VP V PP PP the dog saw a the dog saw a man in the park 43 / 66

Recursive Descent Parsing S VP V PP PP the dog saw a man the dog saw a man in the park 44 / 66

Recursive Descent Parsing S VP V PP PP P the dog saw a man in the dog saw a man in the park 45 / 66

Recursive Descent Parsing S VP V PP PP P PP the dog saw a man in the dog saw a man in the park 46 / 66

Recursive Descent Parsing S VP V PP PP P PP P the dog saw a man in the park the dog saw a man in the park 47 / 66

Recursive Descent Parsing S VP V PP the dog saw the dog saw a man in the park 48 / 66

Recursive Descent Parsing S VP V PP the dog saw a man the dog saw a man in the park 49 / 66

Recursive Descent Parsing S VP V PP P the dog saw a man in the park the dog saw a man in the park 50 / 66

Shift-Reduce Parsing A Shift-Reduce parser tries to find sequences of words and phrases that correspond to the righthand side of a grammar production and replace them with the lefthand side: Directionality = bottom-up: starts with the words of the input and tries to build trees from the words up. Search strategy = breadth-first: starts with the words, then applies rules with matching right hand sides, and so on until the whole sentence is reduced to an S. 51 / 66

Algorithm Sketch: Shift-Reduce Parsing Until the words in the sentences are substituted with S: Scan through the input until we recognise something that corresponds to the RHS of one of the production rules (shift) Apply a production rule in reverse; i.e., replace the RHS of the rule which appears in the sentential form with the LHS of the rule (reduce) A shift-reduce parser implemented using a stack: 1 start with an empty stack 2 a shift action pushes the current input symbol onto the stack 3 a reduce action replaces n items with a single item 52 / 66

Shift-Reduce Parsing Stack Remaining T my dog saw a man in the park with a s 53 / 66

Shift-Reduce Parsing Stack Remaining T dog saw a man in the park with a s my 54 / 66

Shift-Reduce Parsing Stack Remaining T saw a man in the park with a s my dog 55 / 66

Shift-Reduce Parsing Stack Remaining T saw a man in the park with a s my dog 56 / 66

Shift-Reduce Parsing Stack Remaining T V in the park with a s saw my dog a man 57 / 66

Shift-Reduce Parsing Stack Remaining T V PP with a s saw P my dog a man in the park 58 / 66

Shift-Reduce Parsing Stack V saw PP my dog P a man in the park 59 / 66

Shift-Reduce Parsing Stack VP V my dog saw PP P a man in the park 60 / 66

Shift-Reduce Parsing Stack S VP V my dog saw PP P a man in the park 61 / 66

Shift-reduce parsers and pushdown automata Shift-reduce parsing is equivalent to a pushdown automaton constructed from the CFG (with one state q 0 ): start with empty stack shift: a transition in the PDA from q 0 (to q 0 ) putting a terminal symbol on the stack reduce: whenever the righthand side of a rule appears on top of the stack, pop the RHS and push the lefthand side (still staying in q 0 ). Don t consume anything from the input. accept the string if the start symbol is in the stack and the end of string has been reached If there is some derivation for a given sentence under the CFG, there will be a sequence of actions for which this DA accepts the string 62 / 66

Generalised LR parsing If there is some derivation for a given sentence under the CFG, there will be a sequence of actions for which this DA accepts the string But how do we find this derivation? One way to do this is using so-called generalised LR parsing, which explores all possible paths of the above DA Modern parsers do it differently, because GLR can be expontential in the worst-case 63 / 66

Modern shift-reduce parsers Shift-reduce parsers are highly efficient, they are linear in the length of the string they parse, if they explore only one path How to do that? Learn from data what actions to take at each point, and try to make the optimal decisions so that the correct parse tree will be found This keeps the parser linear in the length of the string, but one small error can propagate through the whole parse, and lead to the wrong parse tree 64 / 66

Try it out Yourselves! Recursive Descent Parser >>> from nltk.app import rdparser >>> rdparser() Shift-Reduce Parser >>> from nltk.app import srparser >>> srparser() 65 / 66

Summary We use CFGs to represent L grammars Grammars need recursion to produce infinite sentences Most L grammars have structural ambiguity A parser computes structure for an input automatically Recursive descent and shift-reduce parsing We ll examine more parsers in Lectures 17 22 Reading: J&M (2nd edition) Chapter 12 (intro section 12.3), Chapter 13 (intro section 13.3) ext lecture: The CYK algorithm 66 / 66