Basic Parsing with Context Free Grammars Chapter 13

Slides:



Advertisements
Similar presentations
Computational language: week 10 Lexical Knowledge Representation concluded Syntax-based computational language Sentence structure: syntax Context free.
Advertisements

Basic Parsing with Context-Free Grammars CS 4705 Julia Hirschberg 1 Some slides adapted from Kathy McKeown and Dan Jurafsky.
Natural Language Processing - Parsing 1 - Language, Syntax, Parsing Problems in Parsing Ambiguity, Attachment / Binding Bottom vs. Top Down Parsing.
May 2006CLINT-LN Parsing1 Computational Linguistics Introduction Approaches to Parsing.
PARSING WITH CONTEXT-FREE GRAMMARS
GRAMMAR & PARSING (Syntactic Analysis) NLP- WEEK 4.
Artificial Intelligence 2004 Natural Language Processing - Syntax and Parsing - Language, Syntax, Parsing Problems in Parsing Ambiguity, Attachment.
1 Earley Algorithm Chapter 13.4 October 2009 Lecture #9.
 Christel Kemke /08 COMP 4060 Natural Language Processing PARSING.
CS Basic Parsing with Context-Free Grammars.
Parsing context-free grammars Context-free grammars specify structure, not process. There are many different ways to parse input in accordance with a given.
Albert Gatt LIN3022 Natural Language Processing Lecture 8.
CMSC 723 / LING 645: Intro to Computational Linguistics November 10, 2004 Lecture 10 (Dorr): CFG’s (Finish Chapter 9) Parsing (Chapter 10) Prof. Bonnie.
CS 4705 Lecture 7 Parsing with Context-Free Grammars.
Syntactic Parsing with CFGs CMSC 723: Computational Linguistics I ― Session #7 Jimmy Lin The iSchool University of Maryland Wednesday, October 14, 2009.
CS 4705 Basic Parsing with Context-Free Grammars.
Artificial Intelligence 2004 Natural Language Processing - Syntax and Parsing - Language Syntax Parsing.
Basic Parsing with Context- Free Grammars 1 Some slides adapted from Julia Hirschberg and Dan Jurafsky.
Context-Free Grammar CSCI-GA.2590 – Lecture 3 Ralph Grishman NYU.
1 Basic Parsing with Context Free Grammars Chapter 13 September/October 2012 Lecture 6.
11 CS 388: Natural Language Processing: Syntactic Parsing Raymond J. Mooney University of Texas at Austin.
October 2008csa3180: Setence Parsing Algorithms 1 1 CSA350: NLP Algorithms Sentence Parsing I The Parsing Problem Parsing as Search Top Down/Bottom Up.
1 CPE 480 Natural Language Processing Lecture 5: Parser Asst. Prof. Nuttanart Facundes, Ph.D.
CS 4705 Parsing More Efficiently and Accurately. Review Top-Down vs. Bottom-Up Parsers Left-corner table provides more efficient look- ahead Left recursion.
GRAMMARS David Kauchak CS159 – Fall 2014 some slides adapted from Ray Mooney.
Chapter 10. Parsing with CFGs From: Chapter 10 of An Introduction to Natural Language Processing, Computational Linguistics, and Speech Recognition, by.
LINGUISTICA GENERALE E COMPUTAZIONALE ANALISI SINTATTICA (PARSING)
May 2006CLINT-LN Parsing1 Computational Linguistics Introduction Parsing with Context Free Grammars.
October 2005csa3180: Parsing Algorithms 11 CSA350: NLP Algorithms Sentence Parsing I The Parsing Problem Parsing as Search Top Down/Bottom Up Parsing Strategies.
11 Chapter 14 Part 1 Statistical Parsing Based on slides by Ray Mooney.
Natural Language - General
PARSING 2 David Kauchak CS159 – Spring 2011 some slides adapted from Ray Mooney.
November 2004csa3050: Sentence Parsing II1 CSA350: NLP Algorithms Sentence Parsing 2 Top Down Bottom-Up Left Corner BUP Implementation in Prolog.
CS 4705 Lecture 10 The Earley Algorithm. Review Top-Down vs. Bottom-Up Parsers –Both generate too many useless trees –Combine the two to avoid over-generation:
csa3050: Parsing Algorithms 11 CSA350: NLP Algorithms Parsing Algorithms 1 Top Down Bottom-Up Left Corner.
CS 4705 Lecture 7 Parsing with Context-Free Grammars.
Natural Language Processing Lecture 15—10/15/2015 Jim Martin.
Instructor: Nick Cercone CSEB - 1 Parsing and Context Free Grammars Parsers, Top Down, Bottom Up, Left Corner, Earley.
NATURAL LANGUAGE PROCESSING
November 2004csa3050: Parsing Algorithms 11 CSA350: NLP Algorithms Parsing Algorithms 1 Top Down Bottom-Up Left Corner.
PARSING David Kauchak CS159 – Fall Admin Assignment 3 Quiz #1  High: 36  Average: 33 (92%)  Median: 33.5 (93%)
Parsing with Context Free Grammars. Slide 1 Outline Why should you care? Parsing Top-Down Parsing Bottom-Up Parsing Bottom-Up Space (an example) Top -
Chapter 3 – Describing Syntax
CSC 594 Topics in AI – Natural Language Processing
Parsing Recommended Reading: Ch th Jurafsky & Martin 2nd edition
Programming Languages Translator
Bottom-up parsing Goal of parser : build a derivation
Unit-3 Bottom-Up-Parsing.
Parsing IV Bottom-up Parsing
Table-driven parsing Parsing performed by a finite state machine.
Parsing — Part II (Top-down parsing, left-recursion removal)
4 (c) parsing.
Natural Language Processing (NLP)
CPSC 503 Computational Linguistics
Parsing Techniques.
CSCI 5832 Natural Language Processing
CPSC 503 Computational Linguistics
Top-Down Parsing CS 671 January 29, 2008.
CS 388: Natural Language Processing: Syntactic Parsing
Natural Language - General
Parsing and More Parsing
Lecture 7: Introduction to Parsing (Syntax Analysis)
CSCI 5832 Natural Language Processing
CPSC 503 Computational Linguistics
CSA2050 Introduction to Computational Linguistics
David Kauchak CS159 – Spring 2019
csa3180: Setence Parsing Algorithms 1
Parsing I: CFGs & the Earley Parser
David Kauchak CS159 – Spring 2019
Artificial Intelligence 2004 Speech & Natural Language Processing
Presentation transcript:

Basic Parsing with Context Free Grammars Chapter 13 Lecture #8 October 2009

Analyzing Linguistic Units Morphological parsing: analyze words into morphemes and affixes rule-based, FSAs, FSTs Phonological parsing: analyze sounds into words and phrases POS Tagging Syntactic parsing: identify component parts and how related to see if a sentence is grammatical to assign an abstract representation of meaning

Syntactic Parsing Declarative formalisms like CFGs define the legal strings of a language but don’t specify how to recognize or assign structure to them Parsing algorithms specify how to recognize the strings of a language and assign each string one or more syntactic structures Parse trees useful for grammar checking, semantic analysis, MT, QA, information extraction, speech recognition…and almost every task in NLP

Parsing is a Form of Search Searching FSAs Finding the right path through the automaton Search space defined by structure of FSA Searching CFGs Finding the right parse tree among all possible parse trees Search space defined by the grammar Constraints provided by the input sentence and the automaton or grammar

CFG for Fragment of English S  NP VP VP  V S  Aux NP VP Det  that | this | a S  VP N  book | flight | meal | money NP  Det Nom V  book | include | prefer NP PropN Aux  does Nom  N Nom Prep from | to | on Nom  N PropN  Houston | TWA Nom  Nom PP VP  V NP Remember non-terminals, terminals. Here the lexicon is mixed in with the grammar (making no distinction) LC’s TopD BotUp E.g.

Parse Tree for “Book that flight” for Prior CFG VP NP Nom Verb Det Noun Book that Flight

Top-Down Parser Builds from the root S node to the leaves Find a rule to apply by matching the left hand side of a rule Build a tree by replacing LHS with the right hand side Assuming we build all trees in parallel: Find all trees with root S (or all rules w/lhs S) Next expand all constituents in these trees/rules Continue until leaves are pos Candidate trees failing to match pos of input string are rejected (e.g. Book that flight can only match subtree 5)

Top Down Space

CFG for Fragment of English VP  V NP (2) Nom  Nom PP PropN  Houston | TWA Nom  N (6) Prep from | to | on Nom  N Nom Aux  does NP PropN V  book (3) | include | prefer NP  Det Nom (4) N  book | flight (7) | meal | money S  VP (1) Det  that (5) | this | a S  Aux NP VP VP  V S  NP VP LC’s TopD BotUp E.g.

Parse Tree for “Book that flight” for Prior CFG VP NP Nom Verb Det Noun Book that Flight

Bottom-Up Parsing Parser begins with words of input and builds up trees, applying grammar rules whose right hand side match Book that flight N Det N V Det N Book that flight Book that flight ‘Book’ ambiguous Parse continues until an S root node reached or no further node expansion possible

Bottom-Up Space flight flight flight flight flight flight flight

CFG for Fragment of English VP  V NP (6) Nom  Nom PP PropN  Houston | TWA Nom  N (4) Prep from | to | on Nom  N Nom Aux  does NP PropN V  book (1) | include | prefer NP  Det Nom (5) N  book | flight (3) | meal | money S  VP (7) Det  that (2) | this | a S  Aux NP VP VP  V S  NP VP LC’s TopD BotUp E.g.

Parse Tree for “Book that flight” for Prior CFG VP NP Nom Verb Det Noun Book that Flight

Control Of course, we left out how to keep track of the spaces and how to make choices Which node to try to expand next Which grammar rule to use to expand a node

A Top-Down Parsing Strategy Depth-first search: Agenda of search states: expand search space incrementally, exploring most recently generated state (tree) each time When you reach a state (tree) inconsistent with input, backtrack to most recent unexplored state (tree) Which node to expand? Leftmost or rightmost Which grammar rule to use? Order in the grammar??

Top-Down, Depth-First, Left-Right Strategy Initialize agenda with ‘S’ tree and ptr to first word and make this current search state (cur) Loop until successful parse or empty agenda Apply all applicable grammar rules to leftmost unexpanded node of cur If this node is a POS category and matches that of the current input, push this onto agenda O.w. push new trees onto agenda Pop new cur from agenda Does this flight include a meal?

Top-Down, Depth-First, Left-to-Right Search Grammar: S  NP VP S  Aux NP VP S  VP NP  Det Nom NP PropN Nom  N Nom Nom  N Nom  Nom PP VP  V NP VP  V Curr:

Top-Down, Depth-First, Left-to-Right Search Grammar: S  NP VP S  Aux NP VP S  VP NP  Det Nom NP PropN Nom  N Nom Nom  N Nom  Nom PP VP  V NP VP  V Curr:

Top-Down, Depth-First, Left-to-Right Search Curr: Agenda:

Top-Down, Depth-First, Left-to-Right Search Curr: Agenda:

Top-Down, Depth-First, Left-to-Right Search Grammar: S  NP VP S  Aux NP VP S  VP NP  Det Nom NP PropN Nom  N Nom Nom  N Nom  Nom PP VP  V NP VP  V Curr:

Top-Down, Depth-First, Left-to-Right Search Grammar: S  NP VP S  Aux NP VP S  VP NP  Det Nom NP PropN Nom  N Nom Nom  N Nom  Nom PP VP  V NP VP  V Curr:

Top-Down, Depth-First, Left-to-Right Search Curr: Agenda:

Top-Down, Depth-First, Left-to-Right Search Curr: Agenda:

Top-Down, Depth-First, Left-to-Right Search Curr: Agenda:

Top-Down, Depth-First, Left-to-Right Search Curr: Agenda:

Top-Down, Depth-First, Left-to-Right Search Curr: Agenda: Continue putting NP “rules” on agenda

“Does this flight include a meal?” Parsing Overview

“Does this flight include a meal?” Parsing Overview (cont.)

“Does this flight include a meal?” Parsing Overview (cont.)

“Does this flight include a meal?” Parsing Overview (cont.)

A Bottom-Up Parsing Strategy Depth-first search: State of parse is going to be initialized to the input words At each step, look for Right Hand Side of a rule in the state, replace the matched right hand side with the Left Hand Side of the rule and continue Agenda of search states: expand search space incrementally, exploring most recently generated state each time When you reach a state that contains only the start symbol, you have successfully parsed

Bottom Up: “Book that flight” Grammar: Curr: N det N Agenda: V det N Curr: Nom det N Agenda: N det Nom, V det N Curr: Nom det Nom Curr: Nom NP Curr: N det Nom S  NP VP S  Aux NP VP S  VP NP  Det Nom NP PropN Nom  N Nom Nom  N Nom  Nom PP VP  V NP VP  V

Bottom Up: “Book that flight” Grammar: Curr: V det N Agenda: Curr: VP det N Agenda: V det Nom Curr: VP NP Curr: S NP S  NP VP S  Aux NP VP S  VP NP  Det Nom NP PropN Nom  N Nom Nom  N Nom  Nom PP VP  V NP VP  V

Bottom Up: “Book that flight” Grammar: Curr: V det Nom Agenda: Curr: V NP Curr: VP Curr: S SUCCESS!!!! S  NP VP S  Aux NP VP S  VP NP  Det Nom NP PropN Nom  N Nom Nom  N Nom  Nom PP VP  V NP VP  V

What’s wrong with…. Top-Down parsers never explore illegal parses (e.g. can’t form an S) -- but waste time on trees that can never match the input Bottom-Up parsers never explore trees inconsistent with input -- but waste time exploring illegal parses (no S root) For both: control strategy -- how explore search space? Pursuing all parses in parallel or backtrack or …? Which rule to apply next? Which node to expand next?

Left Corners: Top-Down Parsing with Bottom-Up Filtering We saw: Top-Down, depth-first, L2R parsing Expands non-terminals along the tree’s left edge down to leftmost leaf of tree Moves on to expand down to next leftmost leaf… Note: In successful parse, current input word will be first word in derivation of node the parser currently processing So….look ahead to left-corner of the tree B is a left-corner of A if A =*=> Bα Build table with left-corners of all non-terminals in grammar and consult before applying rule Procedure: before applying a grammar rule, check the rhs of the rule if its first term is a p.o.s of the current input, apply if its first term has a left corner which is a p.o.s. of the current input, apply o.w. don’t apply the rule

Left Corners

Calculating Left Corners Grammar: For each constituent on the LHS of a rule, follow through LHS until you find a preterminal (lexical category). That’s the left corner. Consider S – one rule at a time Det PropN Aux V Same procedure for other constituents S  NP VP S  Aux NP VP S  VP NP  Det Nom NP PropN Nom  N Nom Nom  N Nom  Nom PP VP  V NP VP  V

Left-Corner Table for CFG

Summing Up Parsing is a search problem which may be implemented with many control strategies Top-Down or Bottom-Up approaches each have problems Combining the two solves some but not all issues… Look at some more solutions next week (Thursday) Next time: Read Ch 10:3-6