Context-Free Grammar CSCI-GA.2590 – Lecture 3 Ralph Grishman NYU.

Slides:



Advertisements
Similar presentations
C O N T E X T - F R E E LANGUAGES ( use a grammar to describe a language) 1.
Advertisements

1 Parsing The scanner recognizes words The parser recognizes syntactic units Parser operations: Check and verify syntax based on specified syntax rules.
CFGs and PDAs Sipser 2 (pages ). Long long ago…
Grammars, constituency and order A grammar describes the legal strings of a language in terms of constituency and order. For example, a grammar for a fragment.
PARSING WITH CONTEXT-FREE GRAMMARS
GRAMMAR & PARSING (Syntactic Analysis) NLP- WEEK 4.
CS Basic Parsing with Context-Free Grammars.
Parsing with CFG Ling 571 Fei Xia Week 2: 10/4-10/6/05.
Context-Free Parsing. 2/37 Basic issues Top-down vs. bottom-up Handling ambiguity –Lexical ambiguity –Structural ambiguity Breadth first vs. depth first.
Amirkabir University of Technology Computer Engineering Faculty AILAB Efficient Parsing Ahmad Abdollahzadeh Barfouroush Aban 1381 Natural Language Processing.
Amirkabir University of Technology Computer Engineering Faculty AILAB Parsing Ahmad Abdollahzadeh Barfouroush Aban 1381 Natural Language Processing Course,
Context-Free Grammars Lecture 7
January 14, 2015CS21 Lecture 51 CS21 Decidability and Tractability Lecture 5 January 14, 2015.
1 Foundations of Software Design Lecture 23: Finite Automata and Context-Free Grammars Marti Hearst Fall 2002.
Parsing — Part II (Ambiguity, Top-down parsing, Left-recursion Removal)
Syntactic Parsing with CFGs CMSC 723: Computational Linguistics I ― Session #7 Jimmy Lin The iSchool University of Maryland Wednesday, October 14, 2009.
Prof. Fateman CS 164 Lecture 91 Bottom-Up Parsing Lecture 9.
1 The Parser Its job: –Check and verify syntax based on specified syntax rules –Report errors –Build IR Good news –the process can be automated.
CS 4705 Basic Parsing with Context-Free Grammars.
1 CONTEXT-FREE GRAMMARS. NLE 2 Syntactic analysis (Parsing) S NPVP ATNNSVBD NP AT NNthechildrenate thecake.
Artificial Intelligence 2004 Natural Language Processing - Syntax and Parsing - Language Syntax Parsing.
Chapter 3: Formal Translation Models
Table-driven parsing Parsing performed by a finite state machine. Parsing algorithm is language-independent. FSM driven by table (s) generated automatically.
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.
Lecture 9UofH - COSC Dr. Verma 1 COSC 3340: Introduction to Theory of Computation University of Houston Dr. Verma Lecture 9.
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.
1 Introduction to Parsing Lecture 5. 2 Outline Regular languages revisited Parser overview Context-free grammars (CFG’s) Derivations.
Syntax and Semantics Structure of programming languages.
LINGUISTICA GENERALE E COMPUTAZIONALE ANALISI SINTATTICA (PARSING)
-Mandakinee Singh (11CS10026).  What is parsing? ◦ Discovering the derivation of a string: If one exists. ◦ Harder than generating strings.  Two major.
10. Parsing with Context-free Grammars -Speech and Language Processing- 발표자 : 정영임 발표일 :
A sentence (S) is composed of a noun phrase (NP) and a verb phrase (VP). A noun phrase may be composed of a determiner (D/DET) and a noun (N). A noun phrase.
PART I: overview material
May 2006CLINT-LN Parsing1 Computational Linguistics Introduction Parsing with Context Free Grammars.
Parsing Prepared by Manuel E. Bermúdez, Ph.D. Associate Professor University of Florida Programming Language Principles Lecture 3.
October 2005csa3180: Parsing Algorithms 11 CSA350: NLP Algorithms Sentence Parsing I The Parsing Problem Parsing as Search Top Down/Bottom Up Parsing Strategies.
Parsing I: Earley Parser CMSC Natural Language Processing May 1, 2003.
1 Syntax In Text: Chapter 3. 2 Chapter 3: Syntax and Semantics Outline Syntax: Recognizer vs. generator BNF EBNF.
Syntax and Semantics Structure of programming languages.
11 Chapter 4 Grammars and Parsing Grammar Grammars, or more precisely, context-free grammars, are the formalism for describing the structure of.
Parsing Introduction Syntactic Analysis I. Parsing Introduction 2 The Role of the Parser The Syntactic Analyzer, or Parser, is the heart of the front.
For Wednesday Read chapter 23 Homework: –Chapter 22, exercises 1,4, 7, and 14.
November 2011CLINT-LN CFG1 Computational Linguistics Introduction Context Free Grammars.
Introduction to Parsing
Parsing with Context-Free Grammars References: 1.Natural Language Understanding, chapter 3 (3.1~3.4, 3.6) 2.Speech and Language Processing, chapters 9,
Natural Language - General
PARSING 2 David Kauchak CS159 – Spring 2011 some slides adapted from Ray Mooney.
Syntax The Structure of a Language. Lexical Structure The structure of the tokens of a programming language The scanner takes a sequence of characters.
CS412/413 Introduction to Compilers and Translators Spring ’99 Lecture 3: Introduction to Syntactic Analysis.
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.
1Computer Sciences Department. Book: INTRODUCTION TO THE THEORY OF COMPUTATION, SECOND EDITION, by: MICHAEL SIPSER Reference 3Computer Sciences Department.
CS 4705 Lecture 7 Parsing with Context-Free Grammars.
CSE 5317/4305 L3: Parsing #11 Parsing #1 Leonidas Fegaras.
Parsing and Code Generation Set 24. Parser Construction Most of the work involved in constructing a parser is carried out automatically by a program,
GRAMMARS David Kauchak CS457 – Spring 2011 some slides adapted from Ray Mooney.
CSC312 Automata Theory Lecture # 26 Chapter # 12 by Cohen Context Free Grammars.
1 Introduction to Parsing. 2 Outline l Regular languages revisited l Parser overview Context-free grammars (CFG ’ s) l Derivations.
GRAMMARS & PARSING. Parser Construction Most of the work involved in constructing a parser is carried out automatically by a program, referred to as a.
NLP. Introduction to NLP #include int main() { int n, reverse = 0; printf("Enter a number to reverse\n"); scanf("%d",&n); while (n != 0) { reverse =
Formal grammars A formal grammar is a system for defining the syntax of a language by specifying sequences of symbols or sentences that are considered.
CMSC 330: Organization of Programming Languages Pushdown Automata Parsing.
Syntax Analysis By Noor Dhia Syntax analysis:- Syntax analysis or parsing is the most important phase of a compiler. The syntax analyzer considers.
Syntax and Semantics Structure of programming languages.
WELCOME TO A JOURNEY TO CS419 Dr. Hussien Sharaf Dr. Mohammad Nassef Department of Computer Science, Faculty of Computers and Information, Cairo University.
Programming Languages Translator
Basic Parsing with Context Free Grammars Chapter 13
Parsing and More Parsing
Presentation transcript:

Context-Free Grammar CSCI-GA.2590 – Lecture 3 Ralph Grishman NYU

A Grammar Formalism We have informally described the basic constructs of English grammar Now we want to introduce a formalism for representing these constructs – a formalism that we can use as input to a parsing procedure 1/16/14NYU2

Context-Free Grammar A context-free grammar consists of – a set of non-terminal symbols A, B, C, … ε N – a set of terminal symbols a, b, c, … ε T – a start symbol S ε N – a set of productions P of the form N  (N U T)* 1/16/14NYU3

A Simple Context-Free Grammar A simple CFG: S  NP VP NP  cats NP  the cats NP  the old cats NP  mice VP  sleep VP  chase NP 1/16/14NYU4

Derivation and Language If A  β is a production of the grammar, we can rewrite α A γ  α β γ A derivation is a sequence of rewrite operations  …  …  NP VP  cats VP  cats chase NP The language generated by a CFG is the set of strings (sequences of terminals) which can be derived from the start symbol S  …  …  T* S  NP VP  cats VP  cats chase NP  cats chase mice 1/16/14NYU5

Preterminals It is convenient to include a set of symbols called preterminals (corresponding to the parts of speech) which can be directly rewritten as terminals (words) This allows us to separate the productions into a set which generates sequences of preterminals (the “grammar”) and those which rewrite the preterminals as terminals (the “dictionary”) 1/16/14NYU6

A Grammar with Preterminals grammar: S  NP VP NP  N NP  ART N NP  ART ADJ N VP  V VP  V NP dictionary: N  cats N  mice ADJ  old DET  the V  sleep V  chase 1/16/14NYU7

Grouping Alternates To make the grammar more compact, we group productions with the same left-hand side: S  NP VP NP  N | ART N | ART ADJ N VP  V | V NP 1/16/14NYU8

A grammar can be used to – generate – recognize – parse Why parse? – parsing assigns the sentence a structure that may be helpful in determining its meaning 1/16/14NYU9

vs Finite State Language CFGs are more powerful than finite-state grammars (regular expressions) – FSG cannot generate center embeddings S  ( S ) | x – even if FSG can capture the language, it may be unable to assign the nested structures we want

A slightly bigger CFG sentence  np vp np  ngroup | ngroup pp ngroup  n | art n | art adj n vp  v | v np | v vp | v np pp (auxilliary) pp  p np (pp = prepositional phrase) 1/16/1411NYU

Ambiguity Most sentences will have more than one parse Generally different parses will reflect different meanings … “I saw the man with a telescope.” Can attach pp (“with a telescope”) under np or vp 1/16/14NYU12

A CFG with just 2 nonterminals S  NP V | NP V NP NP  N | ART NOUN | ART ADJ N use this for tracing our parsers 1/16/1413NYU

Top-down parser repeat expand leftmost non-terminal using first production (save any alternative productions on backtrack stack) if we have matched entire sentence, quit (success) if we have generated a terminal which doesn't match sentence, pop choice point from stack (if stack is empty, quit (failure)) 1/16/14NYU14

Top-down parser 1/16/14NYU15 0: S the cat chases mice

Top-down parser 1/16/14NYU16 0: S 1: NP the cat chases mice 2: V backtrack table 0: S  NP V NP

Top-down parser 1/16/14NYU17 0: S 1: NP 3: N the cat chases mice 2: V backtrack table 0: S  NP V NP 1:NP  ART ADJ N 1: NP  ART N

Top-down parser 1/16/14NYU18 0: S 1: NP 3: ART the cat chases mice 4: N 2: V backtrack table 0: S  NP V NP 1:NP  ART ADJ N

Top-down parser 1/16/14NYU19 0: S 1: NP 3: ART the cat chases mice 4: ADJ 2: V 5: N backtrack table 0: S  NP V NP

Top-down parser 1/16/14NYU20 0: S 1: NP the cat chases mice 2: V3: NP backtrack table

Top-down parser 1/16/14NYU21 0: S 1: NP 3: N the cat chases mice 2: V3: NP backtrack table 1:NP  ART ADJ N 1: NP  ART N

Top-down parser 1/16/14NYU22 0: S 1: NP 4: ART the cat chases mice 2: V3: NP 5: N backtrack table 1:NP  ART ADJ N

Top-down parser 1/16/14NYU23 0: S 1: NP 4: ART the cat chases mice 2: V3: NP 5: N 6: N parse! backtrack table 1:NP  ART ADJ N 3: NP  ART ADJ N 3: NP  ART N

Bottom-up parser Builds a table where each row represents a parse tree node spanning the words from start up to end 1/16/14NYU24 symbolstartendconstituents N01-

Bottom-up parser We initialize the table with the parts-of – speech of each word … 1/16/14NYU25 symbolstartendconstituents ART01- N12- V23- N34-

Bottom-up parser We initialize the table with the parts-of – speech of each word … remembering that many English words have several parts of speech 1/16/14NYU26 symbolstartendconstituents ART01- N12- V23- N23- N34-

Bottom-up parser Then if these is a production A  B C and we have entries for B and C with end B = start C, we add an entry for A with start = start B and end = end C [see lecture notes for handling general productions] 1/16/14NYU27 node #symbolstartendconstituents 0ART01- 1N12- 2V23- 3N23- 4N34- 5NP02[0, 1]

Bottom-up parser 1/16/14NYU28 node #symbolstartendconstituents 0ART01- 1N12- 2V23- 3N23- 4N34- 5NP02[0, 1] 6NP12[1] 7NP23[3] 8NP34[4] 9S04[5, 2, 8]  10S14[6, 2, 8] several more S’s parse!