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

Slides:



Advertisements
Similar presentations
Natural Language Processing - Parsing 1 - Language, Syntax, Parsing Problems in Parsing Ambiguity, Attachment / Binding Bottom vs. Top Down Parsing.
Advertisements

May 2006CLINT-LN Parsing1 Computational Linguistics Introduction Approaches to Parsing.
PARSING WITH CONTEXT-FREE GRAMMARS
Parsing with Context Free Grammars Reading: Chap 13, Jurafsky & Martin
March 1, 2009 Dr. Muhammed Al-Mulhem 1 ICS 482 Natural Language Processing Probabilistic Context Free Grammars (Chapter 14) Muhammed Al-Mulhem March 1,
CKY Parsing Ling 571 Deep Processing Techniques for NLP January 12, 2011.
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.
Parsing with CFG Ling 571 Fei Xia Week 2: 10/4-10/6/05.
Parsing with PCFG Ling 571 Fei Xia Week 3: 10/11-10/13/05.
Earley’s algorithm Earley’s algorithm employs the dynamic programming technique to address the weaknesses of general top-down parsing. Dynamic programming.
Basic Parsing with Context- Free Grammars 1 Some slides adapted from Julia Hirschberg and Dan Jurafsky.
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.
Parsing SLP Chapter 13. 7/2/2015 Speech and Language Processing - Jurafsky and Martin 2 Outline  Parsing with CFGs  Bottom-up, top-down  CKY parsing.
Syllabus Text Books Classes Reading Material Assignments Grades Links Forum Text Books עיבוד שפות טבעיות - שיעור תשע Bottom Up Parsing עידו דגן.
Basic Parsing with Context- Free Grammars 1 Some slides adapted from Julia Hirschberg and Dan Jurafsky.
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.
PARSING David Kauchak CS457 – Fall 2011 some slides adapted from Ray Mooney.
1 Basic Parsing with Context- Free Grammars Slides adapted from Dan Jurafsky and Julia Hirschberg.
CS 4705 Parsing More Efficiently and Accurately. Review Top-Down vs. Bottom-Up Parsers Left-corner table provides more efficient look- ahead Left recursion.
中文信息处理 Chinese NLP Lecture 9.
1 CKY and Earley Algorithms Chapter 13 October 2012 Lecture #8.
GRAMMARS David Kauchak CS159 – Fall 2014 some slides adapted from Ray Mooney.
LINGUISTICA GENERALE E COMPUTAZIONALE ANALISI SINTATTICA (PARSING)
10. Parsing with Context-free Grammars -Speech and Language Processing- 발표자 : 정영임 발표일 :
11 Syntactic Parsing. Produce the correct syntactic parse tree for a sentence.
May 2006CLINT-LN Parsing1 Computational Linguistics Introduction Parsing with Context Free Grammars.
Parsing with Context Free Grammars CSC 9010 Natural Language Processing Paula Matuszek and Mary-Angela Papalaskari This slide set was adapted from: Jim.
Parsing I: Earley Parser CMSC Natural Language Processing May 1, 2003.
PARSING David Kauchak CS159 – Spring 2011 some slides adapted from Ray Mooney.
11 Chapter 14 Part 1 Statistical Parsing Based on slides by Ray Mooney.
6/2/2016CPSC503 Winter CPSC 503 Computational Linguistics Lecture 9 Giuseppe Carenini.
Lecture 1, 7/21/2005Natural Language Processing1 CS60057 Speech &Natural Language Processing Autumn 2007 Lecture August 2007.
1 Basic Parsing with Context- Free Grammars Slides adapted from Julia Hirschberg and Dan Jurafsky.
1 Chart Parsing Allen ’ s Chapter 3 J & M ’ s Chapter 10.
Sentence Parsing Parsing 3 Dynamic Programming. Jan 2009 Speech and Language Processing - Jurafsky and Martin 2 Acknowledgement  Lecture based on  Jurafsky.
Natural Language - General
PARSING 2 David Kauchak CS159 – Spring 2011 some slides adapted from Ray Mooney.
NLP. Introduction to NLP Motivation –A lot of the work is repeated –Caching intermediate results improves the complexity Dynamic programming –Building.
Quick Speech Synthesis CMSC Natural Language Processing April 29, 2003.
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.
Instructor: Nick Cercone CSEB - 1 Parsing and Context Free Grammars Parsers, Top Down, Bottom Up, Left Corner, Earley.
October 2005CSA3180: Parsing Algorithms 21 CSA3050: NLP Algorithms Parsing Algorithms 2 Problems with DFTD Parser Earley Parsing Algorithm.
PARSING David Kauchak CS159 – Fall Admin Assignment 3 Quiz #1  High: 36  Average: 33 (92%)  Median: 33.5 (93%)
Speech and Language Processing SLP Chapter 13 Parsing.
CSC 594 Topics in AI – Natural Language Processing
Parsing Recommended Reading: Ch th Jurafsky & Martin 2nd edition
Basic Parsing with Context Free Grammars Chapter 13
Parsing Recommended Reading: Ch th Jurafsky & Martin 2nd edition
CPSC 503 Computational Linguistics
CSCI 5832 Natural Language Processing
CS 388: Natural Language Processing: Syntactic Parsing
Lecture 14: Grammar and Parsing (II) November 11, 2004 Dan Jurafsky
Natural Language - General
Parsing and More Parsing
CPSC 503 Computational Linguistics
CSA2050 Introduction to Computational Linguistics
David Kauchak CS159 – Spring 2019
Parsing I: CFGs & the Earley Parser
David Kauchak CS159 – Spring 2019
NLP.
Presentation transcript:

Basic Parsing with Context-Free Grammars CS 4705 Julia Hirschberg 1 Some slides adapted from Kathy McKeown and Dan Jurafsky

Syntactic Parsing Declarative formalisms like CFGs, FSAs define the legal strings of a language -- but only tell you whether a given string is legal in a particular language Parsing algorithms specify how to recognize the strings of a language and assign one (or more) syntactic analyses to each string 2

S  NP VPVP  V S  Aux NP VPVP -> V PP S -> VPPP -> Prep NP NP  Det NomN  old | dog | footsteps | young NP  PropNV  dog | eat | sleep | bark | meow Nom -> Adj NAux  does | can Nom  NPrep  from | to | on | of Nom  N NomPropN  Fido | Felix Nom  Nom PPDet  that | this | a | the VP  V NPAdj -> old | happy| young “The old dog the footsteps of the young.”

S NPVP NPV DET NOM N PP DETNOM N Theolddogthe footsteps of the young How do we create this parse tree?

Parsing is a form of Search We search FSAs by –Finding the correct path through the automaton –Search space defined by structure of FSA We search CFGs by –Finding the correct parse tree among all possible parse trees –Search space defined by the grammar Constraints provided by the input sentence and the automaton or grammar 5

Top Down Parsing Builds from the root S node to the leaves Expectation-based Common top-down search strategy –Top-down, left-to-right, with backtracking –Try first rule s.t. LHS is S –Next expand all constituents on RHS –Iterate until all leaves are POS –Backtrack when candidate POS does not match POS of current word in input string 6

S  NP VPVP  V S  Aux NP VPVP -> V PP S -> VPPP -> Prep NP NP  Det NomN  old | dog | footsteps | young NP  PropNV  dog | eat | sleep | bark | meow Nom -> Adj NAux  does | can Nom  NPrep  from | to | on | of Nom  N NomPropN  Fido | Felix Nom  Nom PPDet  that | this | a | the VP  V NPAdj -> old | happy| young “The old dog the footsteps of the young.”

Expanding the Rules The old dog the footsteps of the young. Where does backtracking happen? What are the computational disadvantages? What are the advantages? What could we do to improve the process? 8

Bottom Up Parsing Parser begins with words of input and builds up trees, applying grammar rules whose RHS matches Det N V Det N Prep Det N The old dog the footsteps of the young. Det Adj N Det N Prep Det N The old dog the footsteps of the young. Parse continues until an S root node reached or no further node expansion possible 9

S  NP VPVP  V S  Aux NP VPVP -> V PP S -> VPPP -> Prep NP NP  Det NomN  old | dog | footsteps | young NP  PropNV  dog | eat | sleep | bark | meow Nom -> Adj NAux  does | can Nom  NPrep  from | to | on | of Nom  N NomPropN  Fido | Felix Nom  Nom PPDet  that | this | a | the VP  V NPAdj -> old | happy| young “The old dog the footsteps of the young.”

Bottom Up Parsing When does disambiguation occur? What are the computational advantages and disadvantages? What could we do to make this process more efficient? 11

Issues to Address Ambiguity: –POS –Attachment PP:… Coordination: old dogs and cats –Overgenerating useless hypotheses –Regenerating good hypotheses

Dynamic Programming Fill in tables with solutions to subproblems For parsing: –Store possible subtrees for each substring as they are discovered in the input –Ambiguous strings are given multiple entries –Table look-up to come up with final parse(s) Many parsers take advantage of this approach

Review: Minimal Edit Distance Simple example of DP: find the minimal ‘distance’ between 2 strings –Minimal number of operations (insert, delete, substitute) needed to transform one string into another –Levenstein distances (subst=1 or 2) –Key idea: minimal path between substrings is on the minimal path between the beginning and end of the 2 strings

Example of MED Calculation

DP for Parsing Table cells represented state of parse of input up to this point Can be calculated from neighboring state(s) Only need to parse each substring once for each possible analysis into constituents

Parsers Using DP CKY Parsing Algorithm –Bottom-up –Grammar must be in Chomsky Normal Form –The parse tree might not be consistent with linguistic theory Earley Parsing Algorithm –Top-down –Expectations about constituents are confirmed by input –A POS tag for a word that is not predicted is never added Chart Parser 17

Cocke-Kasami-Younger Algorithm Convert grammar to Chomsky Normal Form –Every CFG has a weakly equivalent CNF grammar –A  B C (non-terminals) –A  w (terminal) –Basic ideas: Keep rules conforming to CNF Introduce dummy non-terminals for rules that mix terminal and non- terminals (e.g. A  Bw becomes A  BB’; B’  w) Rewrite RHS of unit productions with RHS of all non-unit productions they lead to (e.g. A  B; B  w becomes A  w) For RHS longer than 2 non-terminals, replace leftmost pairs of non- terminals with a new non-terminal and add a new production rule (e.g. A  BCD becomes A  ZD; Z  BC) For ε-productions, find all occurences of LHS in 2-variable RHSs and create new rule without the LHS (e.g. C  AB;A  ε becomes C  B)

A CFG

Figure 13.8

CYK in Action Each non-terminal above POS level has 2 daughters –Encode entire parse tree in N+1 x N+1 table –Each cell [i,j] contains all non-terminals that span positions [i-j] betw input words –Cell [0,N] represents all input –For each [i,j] s.t. i<k<j, [i,k] is to left and [k,j] is below in table –Diagonal contains POS of each input word –Fill in table from diagonal on up

–For any cell [i,j], cells (constituents) contributing to [i.j] are to left and below, already filled in

Figure 13.8

CYK Parse Table X2

CYK Algorithm

Filling in [0,N]: Adding X2 [0,n]

Filling the Final Column (1)

Filling the Final Column (2) X2

Earley Algorithm Top-down parsing algorithm using DP Allows arbitrary CFGs: closer to linguistics Fills a chart of length N+1 in a single sweep over input of N words –Chart entries represent state of parse at each word position Completed constituents and their locations In-progress constituents Predicted constituents 29

Parser States The table-entries are called states and are represented with dotted-rules S -> · VPA VP is predicted NP -> Det · NominalAn NP is in progress VP -> V NP · A VP has been found 30

CFG for Fragment of English S  NP VPVP  V S  Aux NP VP PP -> Prep NP S  VPN  book | flight | meal | money NP  Det NomV  book | include | prefer NP  PropNAux  does Nom  N NomPrep  from | to | on Nom  NPropN  Houston | TWA Nom  Nom PPDet  that | this | a | the VP  V NP

S8 S9 S10 S11 S13 S12 S8 S9 S8 Some Parse States for Book that flight

Filling in the Chart March through chart left-to-right. At each step, apply 1 of 3 operators –Predictor Create new states representing top-down expectations –Scanner Match word predictions (rule with POS following dot) to words in input –Completer When a state is complete, see what rules were looking for that complete constituent 33

Top Level Earley

Predictor Given a state –With a non-terminal to right of dot (not a part-of-speech category) –Create a new state for each expansion of the non-terminal –Put predicted states in same chart cell as generating state, beginning and ending where generating state ends –So predictor looking at S ->. VP [0,0] – results in VP ->. Verb [0,0] VP ->. Verb NP [0,0] 35

Scanner Given a state –With a non-terminal to right of dot that is a POS category –If next word in input matches this POS –Create a new state with dot moved past the non-terminal E.g., scanner looking at VP ->. Verb NP [0,0] –If next word can be a verb, add new state: VP -> Verb. NP [0,1] –Add this state to chart entry following current one –NB: Earley uses top-down input to disambiguate POS -- only POS predicted by some state can be added to chart 36

Completer Given a state –Whose dot has reached right end of rule –Parser has discovered a constituent over some span of input –Find and advance all previous states that are ‘looking for’ this category –Copy state, move dot, insert in current chart entry E.g., if processing: –NP -> Det Nominal. [1,3] and if state expecting an NP like VP -> Verb. NP [0,1] in chart Add –VP -> Verb NP. [0,3] to same cell of chart 37

Reaching a Final State Find an S state in chart that spans input from 0 to N+1 and is complete Declare victory: –S –> α · [0,N+1] 38

Converting from Recognizer to Parser Augment the “Completer” to include pointer to each previous (now completed) state Read off all the backpointers from every complete S 39

Gist of Earley Parsing 1.Predict all the states you can as soon as you can 2.Read a word 1.Extend states based on matches 2.Add new predictions 3.Go to 2 3.Look at N+1 to see if you have a winner 40

Example Book that flight Goal: Find a completed S from 0 to 3 Chart[0] shows Predictor operations Chart[1] S12 shows Scanner Chart[3] shows Completer stage 41

Figure 13.14

Figure continued

Final Parse States

Chart Parsing CKY and Earley are deterministic, given an input: all actions are taken is predetermined order Chart Parsing allows for flexibility of events via separate policy that determines order of an agenda of states –Policy determines order in which states are created and predictions made –Fundamental rule: if chart includes 2 contiguous states s.t. one provides a constituent the other needs, a new state spanning the two states is created with the new information

Summing Up Parsing as search: what search strategies to use? –Top down –Bottom up –How to combine? How to parse as little as possible –Dynamic Programming –Different policies for ordering states to be processed –Next: Shallow Parsing and Review 46