Parsing. What is Parsing? S  NP VP NP  Det N NP  NP PP VP  V NP VP  VP PP PP  P NP NP  Papa N  caviar N  spoon V  spoon V  ate P  with Det.

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
1 Language definition Syntax: the structure of a program. Usually given a formal (i.e., mathematical) definition using a context-free language. (Lexical.
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.
For Monday Read Chapter 23, sections 3-4 Homework –Chapter 23, exercises 1, 6, 14, 19 –Do them in order. Do NOT read ahead.
Artificial Intelligence 2004 Natural Language Processing - Syntax and Parsing - Language, Syntax, Parsing Problems in Parsing Ambiguity, Attachment.
 Christel Kemke /08 COMP 4060 Natural Language Processing PARSING.
PCFG Parsing, Evaluation, & Improvements Ling 571 Deep Processing Techniques for NLP January 24, 2011.
Parsing with CFG Ling 571 Fei Xia Week 2: 10/4-10/6/05.
Intro to NLP - J. Eisner1 Probabilistic CKY.
Amirkabir University of Technology Computer Engineering Faculty AILAB Efficient Parsing Ahmad Abdollahzadeh Barfouroush Aban 1381 Natural Language Processing.
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.
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.
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.
Probabilistic Parsing Reading: Chap 14, Jurafsky & Martin This slide set was adapted from J. Martin, U. Colorado Instructor: Paul Tarau, based on Rada.
Intro to NLP - J. Eisner1 Earley’s Algorithm (1970) Nice combo of our parsing ideas so far:  no restrictions on the form of the grammar:  A.
For Friday Finish chapter 23 Homework: –Chapter 22, exercise 9.
LINGUISTICA GENERALE E COMPUTAZIONALE ANALISI SINTATTICA (PARSING)
10. Parsing with Context-free Grammars -Speech and Language Processing- 발표자 : 정영임 발표일 :
Context-Free Parsing Read J & M Chapter 10.. Basic Parsing Facts Regular LanguagesContext-Free Languages Required Automaton FSMPDA Algorithm to get rid.
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. What is Parsing? S  NP VP NP  Det N NP  NP PP VP  V NP VP  VP PP PP  P NP NP  Papa N  caviar N  spoon V  spoon V  ate P  with Det.
October 2005csa3180: Parsing Algorithms 11 CSA350: NLP Algorithms Sentence Parsing I The Parsing Problem Parsing as Search Top Down/Bottom Up Parsing Strategies.
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.
Lecture 1, 7/21/2005Natural Language Processing1 CS60057 Speech &Natural Language Processing Autumn 2007 Lecture August 2007.
Probabilistic CKY Roger Levy [thanks to Jason Eisner]
Chart Parsing and Augmenting Grammars CSE-391: Artificial Intelligence University of Pennsylvania Matt Huenerfauth March 2005.
Sentence Parsing Parsing 3 Dynamic Programming. Jan 2009 Speech and Language Processing - Jurafsky and Martin 2 Acknowledgement  Lecture based on  Jurafsky.
Natural Language - General
Basic Parsing Algorithms: Earley Parser and Left Corner Parsing
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.
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.
Intro to NLP - J. Eisner1 Parsing Tricks.
CS 4705 Lecture 7 Parsing with Context-Free Grammars.
Natural Language Processing Lecture 15—10/15/2015 Jim Martin.
December 2011CSA3202: PCFGs1 CSA3202: Human Language Technology Probabilistic Phrase Structure Grammars (PCFGs)
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.
NLP. Introduction to NLP Time flies like an arrow –Many parses –Some (clearly) more likely than others –Need for a probabilistic ranking method.
Semantics cCS 224n / Lx 237 Tuesday, May With slides borrowed from Jason Eisner.
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.
1 Statistical methods in NLP Diana Trandabat
Parsing.
CSC 594 Topics in AI – Natural Language Processing
Parsing Recommended Reading: Ch th Jurafsky & Martin 2nd edition
Statistical NLP Winter 2009
Modeling Grammaticality
Basic Parsing with Context Free Grammars Chapter 13
CSCI 5832 Natural Language Processing
Natural Language - General
Parsing.
Earley’s Algorithm (1970) Nice combo of our parsing ideas so far:
Parsing and More Parsing
Modeling Grammaticality
Weighted Parsing, Probabilistic Parsing
David Kauchak CS159 – Spring 2019
Presentation transcript:

Parsing

What is Parsing? S  NP VP NP  Det N NP  NP PP VP  V NP VP  VP PP PP  P NP NP  Papa N  caviar N  spoon V  spoon V  ate P  with Det  the Det  a Papa the caviar a spoonatewith S NP VP V NP Det N NP Det N PP P

What is Parsing? S  NP VP NP  Det N NP  NP PP VP  V NP VP  VP PP PP  P NP NP  Papa N  caviar N  spoon V  spoon V  ate P  with Det  the Det  a S Papa NP VP V NP Det N the caviar NP Det N a spoon ate PP P with

Programming languages printf ("/charset [%s", (re_opcode_t) *(p - 1) == charset_not ? "^" : ""); assert (p + *p < pend); for (c = 0; c < 256; c++) if (c / 8 < *p && (p[1 + (c/8)] & (1 << (c % 8)))) { /* Are we starting a range? */ if (last + 1 == c && ! inrange) { putchar ('-'); inrange = 1; } /* Have we broken a range? */ else if (last + 1 != c && inrange) { putchar (last); inrange = 0; } if (! inrange) putchar (c); last = c; }  Easy to parse.  Designed that way!

Natural languages  No {} () [] to indicate scope & precedence  Lots of overloading (arity varies)  Grammar isn’t known in advance!  Context-free grammar not best formalism printf "/charset %s", re_opcode_t *p - 1 == charset_not ? "^" : ""; assert p + *p < pend; for c = 0; c < 256; c++ if c / 8 < *p && p1 + c/8 & 1 << c % 8 Are we starting a range? if last + 1 == c && ! inrange putchar '-'; inrange = 1; Have we broken a range? else if last + 1 != c && inrange putchar last; inrange = 0; if ! inrange putchar c; last = c;

Ambiguity S  NP VP NP  Det N NP  NP PP VP  V NP VP  VP PP PP  P NP NP  Papa N  caviar N  spoon V  spoon V  ate P  with Det  the Det  a S Papa NP VP V NP Det N the caviar NP Det N a spoon ate PP P with

Ambiguity S  NP VP NP  Det N NP  NP PP VP  V NP VP  VP PP PP  P NP NP  Papa N  caviar N  spoon V  spoon V  ate P  with Det  the Det  a S Papa NP VP NP V Det N the caviar NP Det N a spoon ate PP P with

The parsing problem PARSERPARSER Grammar scorerscorer correct test trees test sentences accuracy Recent parsers quite accurate … good enough to help a range of NLP tasks!

Applications of parsing (1/2)  Machine translation (Alshawi 1996, Wu 1997,...) EnglishChinese tree operations  Speech synthesis from parses (Prevost 1996) The government plans to raise income tax. The government plans to raise income tax the imagination.  Speech recognition using parsing (Chelba et al 1998) Put the file in the folder. Put the file and the folder. Warning: these slides are out of date

Applications of parsing (2/2)  Grammar checking (Microsoft)  Indexing for information retrieval (Woods 1997)... washing a car with a hose... vehicle maintenance  Information extraction (Hobbs 1996)  NY Times  archive  Database  query Warning: these slides are out of date

Parsing for Interpretation  Most linguistic properties are defined over trees.  One needs to parse to see subtle distinctions. E.g.: Sara dislikes criticism of her. (her  Sara) Sara dislikes criticism of her by anyone. (her  Sara) Sara dislikes anyone’s criticism of her. (her = Sara or her  Sara)

Intro to NLP - J. Eisner12 Parsing  Compositional Semantics  What is meaning of 3+5*6 ?  First parse it into 3+ ( 5*6 ) + 3 * 5 6 E E F E E E 3 F N 5 N 6 N * + Preview of the next topic!

Intro to NLP - J. Eisner13  What is meaning of 3+5*6 ?  First parse it into 3+ ( 5*6 )  Now give a meaning to each node in the tree (bottom-up) + 3 * 5 6 E E F E E E 3 F N 5 N 6 N* add mult Parsing  Compositional Semantics Preview of the next topic!

Intro to NLP - J. Eisner14 NP Laura V stem love VP stem VP inf T to S inf NP George VP stem V stem want VP fin T -s S fin NP N nation Det Every ROOT Punc. G a a y x e act(e,loving), lover(e,x), lovee(e,y) L y x e act(e,wanting), wanter(e,x), wantee(e,y) v x  e present(e),v(x)(e) everynation s assert(s) assert(every(nation, x  e present(e), act(e,wanting), wanter(e,x), wantee(e, e’ act(e’,loving), lover(e’,G), lovee(e’,L)))) Parsing  Compositional Semantics Preview of the next topic!

 Now let’s develop some parsing algorithms!  What substrings of this sentence are NPs?  Which substrings could be NPs in the right context?  Which substrings could be other types of phrases?  How would you defend a substring on your list? are unpopular The government plans to raise incometax

“Papa ate the caviar with a spoon”  S  NP VP  NP  Det N  NP  NP PP  VP  V NP  VP  VP PP  PP  P NP  NP  Papa  N  caviar  N  spoon  V  spoon  V  ate  P  with  Det  the  Det  a

First try … does it work?  for each constituent on the LIST (Y I Mid)  scan the LIST for an adjacent constituent (Z Mid J)  if grammar has a rule to combine them (X  Y Z)  then add the result to the LIST (X I J) “Papa ate the caviar with a spoon”

Second try …  initialize the list with parts-of-speech (T J-1 J) where T is a preterminal tag (like Noun) for the J th word  for each constituent on the LIST (Y I Mid)  scan the LIST for an adjacent constituent (Z Mid J)  if grammar has a rule to combine them (X  Y Z)  then add the result to the LIST (X I J)  if the above loop added anything, do it again! (so that X I J gets a chance to combine or be combined with) “Papa ate the caviar with a spoon”

Third try …  initialize the list with parts-of-speech (T J-1 J) where T is a preterminal tag (like Noun) for the J th word  for each constituent on the LIST (Y I Mid)  for each adjacent constituent on the list (Z Mid J)  for each rule to combine them (X  Y Z)  add the result to the LIST (X I J) if it’s not already there  if the above loop added anything, do it again! (so that X I J gets a chance to combine or be combined with) “Papa ate the caviar with a spoon”

Third try … Initialize  NP 0 1  V 1 2  Det 2 3  N 3 4  P 4 5  Det 5 6  N 6 7  V 6 7 “Papa ate the caviar with a spoon” st pass  NP 2 4  NP 5 7 2nd pass  VP 1 4  NP 2 4  PP 4 7  NP 5 7 3rd pass  …

Follow backpointers to get the parse “Papa ate the caviar with a spoon”

Turn sideways: See the trees?

Correct but still inefficient … We kept checking the same pairs that we’d checked before (both bad and good pairs) Can’t we manage the process in a way that avoids duplicate work? oldnew oldold pairnew pair newnew pair Left phrase Right phrase

Correct but still inefficient … We kept checking the same pairs that we’d checked before (both bad and good pairs) Can’t we manage the process in a way that avoids duplicate work? And even finding new pairs was expensive because we had to scan the whole list Can’t we have some kind of index that will help us find adjacent pairs?

Indexing: Store S 0 4 in chart[0,4]

Avoid duplicate work: Build width-1, then width-2, etc.

How do we build a width-6 phrase? (after building and indexing all shorter phrases) ? 1 7 =

Avoid duplicate work: Build width-1, then width-2, etc.

CKY algorithm, recognizer version  Input: string of n words  Output: yes/no (since it’s only a recognizer)  Data structure: n  n table  rows labeled 0 to n-1  columns labeled 1 to n  cell [i,j] lists constituents found between i and j  Basic idea: fill in width-1 cells, then width-2, …

CKY algorithm, recognizer version  for J := 1 to n  Add to [J-1,J] all categories for the J th word  for width := 2 to n  for start := 0 to n-width // this is I  Define end := start + width // this is J  for mid := start+1 to end-1 // find all I-to-J phrases  for every nonterminal Y in [start,mid]  for every nonterminal Z in [mid,end]  for all nonterminals X  if X  Y Z is in the grammar  then add X to [start,end]

Loose ends to tie up (no slides) What’s the space?  Duplicate entries?  How many parses could there be?  Can we fix this? What’s the runtime?

CKY algorithm, recognizer version  for J := 1 to n  Add to [J-1,J] all categories for the J th word  for width := 2 to n  for start := 0 to n-width // this is I  Define end := start + width // this is J  for mid := start+1 to end-1 // find all I-to-J phrases  for every nonterminal Y in [start,mid]  for every nonterminal Z in [mid,end]  for all nonterminals X  if X  Y Z is in the grammar  then add X to [start,end]

Alternative version of inner loops  for J := 1 to n  Add to [J-1,J] all categories for the J th word  for width := 2 to n  for start := 0 to n-width // this is I  Define end := start + width // this is J  for mid := start+1 to end-1 // find all I-to-J phrases  for every rule X  Y Z in the grammar if Y in [start,mid] and Z in [mid,end] then add X to [start,end]

Extensions to discuss (no slides) In Chinese, no spaces between the words!? Incremental (left-to-right) parsing? We assumed rules like X  Y Z or X  word.  Grammar in “Chomsky Normal Form.” What if it’s not? How do we choose among parses?

35 Chart Parsing in Dyna phrase(X,I,J):- rewrite(X,W), word(W,I,J). phrase(X,I,J):- rewrite(X,Y,Z), phrase(Y,I,Mid), phrase(Z,Mid,J). goal :- phrase(start_symbol, 0, sentence_length).

36 Understanding the Key Rule phrase(X,I,J):- rewrite(X,Y,Z), phrase(Y,I,Mid), phrase(Z,Mid,J). e.g., phrase(“VP”,1,7) Substring from I to J could be a phrase of category X if e.g., phrase(“V”,1,2), phrase(“NP”,2,7) it breaks up into adjacent substrings (from I to Mid and Mid to J) that could be phrases of categories Y and Z rewrite(“VP”,“V”,“NP”) the grammar has a rule X  Y Z (“an X can be made of a Y next to a Z”)

“A word is a phrase”(if grammar allows) start_symbol := “S”. sentence_length := 7. “Two adjacent phrases are a phrase”(if grammar allows) 37 Chart Parsing in Dyna phrase(X,I,J):- rewrite(X,W), word(W,I,J). phrase(X,I,J):- rewrite(X,Y,Z), phrase(Y,I,Mid), phrase(Z,Mid,J). goal :- phrase(start_symbol, 0, sentence_length). “A phrase that covers the whole sentence is a parse” (achieves our goal by showing that the sentence is grammatical) Alternatively: sentence_length max= J for word(_,_,J).

38 Chart Parsing in Dyna We also need a sentence: We also need a grammar: phrase(X,I,J):- rewrite(X,W), word(W,I,J). phrase(X,I,J):- rewrite(X,Y,Z), phrase(Y,I,Mid), phrase(Z,Mid,J). goal :- phrase(start_symbol, 0, sentence_length). word(“Papa”,0,1). word(“ate”,1,2). word(“the”,2,3). word(“caviar”,3,4). word(“with”,4,5). word(“a”,5,6). word(“spoon”,6,7). rewrite(“NP”,“Papa”). rewrite(“N”,“caviar”). … rewrite(“S”,“NP”,“VP”). rewrite(“NP”,“Det”,“N”). rewrite(“NP”,“NP”,“PP”). …

Procedural Algorithms  The Dyna program runs fine.  It nicely displays the abstract structure of the algorithm.  But Dyna is a declarative programming language that hides the details of the actual execution from you.  If you had to find the possible phrases by hand (or with a procedural programming language), what steps would you go through?

40 shared substructure (dynamic programming) ambiguity Discovered phrases & their relationships (“parse forest”) when parsing the ambiguous sentence “Time flies like an arrow” dead end desired theorem axioms This picture assumes a slightly different version of the Dyna program, sorry

41 shared substructure (dynamic programming) ambiguity dead end This picture assumes a slightly different version of the Dyna program, sorry Discovered phrases & their relationships (“parse forest”) when parsing the ambiguous sentence “Time flies like an arrow”

42 Procedural algorithms like CKY are just strategies for running this declarative program And we’ll look at further such strategies later, e.g.  magic sets / Earley’s algorithm / left-to-right parsing,  agenda-based forward chaining,  backward chaining with memoization,  coarse-to-fine search,  probability-guided search and pruning, … phrase(X,I,J):- rewrite(X,W), word(W,I,J). phrase(X,I,J):- rewrite(X,Y,Z), phrase(Y,I,Mid), phrase(Z,Mid,J). goal :- phrase(start_symbol, 0, sentence_length).