CSC NLP -Context-Free Grammars

Slides:



Advertisements
Similar presentations
Introduction to Syntax and Context-Free Grammars Owen Rambow
Advertisements

Mrach 1, 2009Dr. Muhammed Al-Mulhem1 ICS482 Formal Grammars Chapter 12 Muhammed Al-Mulhem March 1, 2009.
Introduction to Syntax, with Part-of-Speech Tagging Owen Rambow September 17 & 19.
1 Context Free Grammars Chapter 12 (Much influenced by Owen Rambow) September 2012 Lecture #5.
Syntax and Context-Free Grammars Julia Hirschberg CS 4705 Slides with contributions from Owen Rambow, Kathy McKeown, Dan Jurafsky and James Martin.
Syntactic analysis using Context Free Grammars. Analysis of language Morphological analysis – Chairs, Part Of Speech (POS) tagging – The/DT man/NN left/VBD.
Context-Free Grammars Julia Hirschberg CS 4705 Slides with contributions from Owen Rambow, Kathy McKeown, Dan Jurafsky and James Martin.
Introduction to Syntax Owen Rambow September 30.
Introduction to Syntax Owen Rambow September
Introduction to Syntax Owen Rambow October
Introduction to Syntax, with Part-of-Speech Tagging Owen Rambow September 17 & 19.
Introduction to Syntax and Context-Free Grammars Owen Rambow September
Syntax and Context-Free Grammars CMSC 723: Computational Linguistics I ― Session #6 Jimmy Lin The iSchool University of Maryland Wednesday, October 7,
1 CONTEXT-FREE GRAMMARS. NLE 2 Syntactic analysis (Parsing) S NPVP ATNNSVBD NP AT NNthechildrenate thecake.
CPSC 503 Computational Linguistics
Models of Generative Grammar Smriti Singh. Generative Grammar  A Generative Grammar is a set of formal rules that can generate an infinite set of sentences.
11 CS 388: Natural Language Processing: Syntactic Parsing Raymond J. Mooney University of Texas at Austin.
Context Free Grammars Reading: Chap 12-13, Jurafsky & Martin This slide set was adapted from J. Martin, U. Colorado Instructor: Paul Tarau, based on Rada.
School of something FACULTY OF OTHER School of Computing FACULTY OF ENGINEERING COMP3310 Natural Language Processing Eric Atwell, Language Research Group.
1 Features and Unification Chapter 15 October 2012 Lecture #10.
Context Free Grammars Reading: Chap 12-13, Jurafsky & Martin This slide set was adapted from J. Martin and Rada Mihalcea.
1 Syntax Sudeshna Sarkar 25 Aug Sentence-Types Declaratives: A plane left S -> NP VP Imperatives: Leave! S -> VP Yes-No Questions: Did the plane.
1 CPE 480 Natural Language Processing Lecture 5: Parser Asst. Prof. Nuttanart Facundes, Ph.D.
GRAMMARS David Kauchak CS159 – Fall 2014 some slides adapted from Ray Mooney.
PARSING David Kauchak CS159 – Spring 2011 some slides adapted from Ray Mooney.
Context Free Grammars Reading: Chap 9, Jurafsky & Martin This slide set was adapted from J. Martin, U. Colorado Instructor: Rada Mihalcea.
11 Chapter 14 Part 1 Statistical Parsing Based on slides by Ray Mooney.
1 LIN6932 Spring 2007 LIN6932 Topics in Computational Linguistics Lecture 6: Grammar and Parsing (I) February 15, 2007 Hana Filip.
Parsing with Context-Free Grammars for ASR Julia Hirschberg CS 4706 Slides with contributions from Owen Rambow, Kathy McKeown, Dan Jurafsky and James Martin.
CPE 480 Natural Language Processing Lecture 4: Syntax Adapted from Owen Rambow’s slides for CSc Fall 2006.
Rules, Movement, Ambiguity
1 Context Free Grammars October Syntactic Grammaticality Doesn’t depend on Having heard the sentence before The sentence being true –I saw a unicorn.
1 Context Free Grammars Chapter 9 (Much influenced by Owen Rambow) October 2009 Lecture #7.
CPSC 422, Lecture 27Slide 1 Intelligent Systems (AI-2) Computer Science cpsc422, Lecture 27 Nov, 16, 2015.
Natural Language Processing Lecture 14—10/13/2015 Jim Martin.
GRAMMARS David Kauchak CS457 – Spring 2011 some slides adapted from Ray Mooney.
CSA3050: NLP Algorithms Sentence Grammar NLP Algorithms.
Speech and Language Processing Formal Grammars Chapter 12.
SYNTAX.
King Faisal University جامعة الملك فيصل Deanship of E-Learning and Distance Education عمادة التعلم الإلكتروني والتعليم عن بعد [ ] 1 King Faisal University.
Context Free Grammars. Slide 1 Syntax Syntax = rules describing how words can connect to each other * that and after year last I saw you yesterday colorless.
Natural Language Processing Vasile Rus
Natural Language Processing Vasile Rus
Introduction to Syntax and Context-Free Grammars
Heng Ji September 13, 2016 SYNATCTIC PARSING Heng Ji September 13, 2016.
Speech and Language Processing
Basic Parsing with Context Free Grammars Chapter 13
Parsing Recommended Reading: Ch th Jurafsky & Martin 2nd edition
SYNTAX.
Chapter Eight Syntax.
Intelligent Systems (AI-2) Computer Science cpsc422, Lecture 27
CPSC 503 Computational Linguistics
Introduction to Syntax and Context-Free Grammars cs
Lecture 13: Grammar and Parsing (I) November 9, 2004 Dan Jurafsky
CSC 594 Topics in AI – Natural Language Processing
CSCI 5832 Natural Language Processing
CSCI 5832 Natural Language Processing
CS 388: Natural Language Processing: Syntactic Parsing
CSCI 5832 Natural Language Processing
Probabilistic and Lexicalized Parsing
Chapter Eight Syntax.
Introduction to Linguistics
Intelligent Systems (AI-2) Computer Science cpsc422, Lecture 27
CSC NLP - Regex, Finite State Automata
Intelligent Systems (AI-2) Computer Science cpsc422, Lecture 26
CSCI 5832 Natural Language Processing
Heng Ji January 17, 2019 SYNATCTIC PARSING Heng Ji January 17, 2019.
Introduction to Syntax
CPSC 503 Computational Linguistics
David Kauchak CS159 – Spring 2019
Presentation transcript:

CSC 9010- NLP -Context-Free Grammars CSC 9010 Natural Language Processing Lecture 6: Context-Free Grammars Paula Matuszek Mary-Angela Papalaskari Presentation slides adapted from: Martin: http://www.cs.colorado.edu/~martin/csci5832.html McCoy: http://www.cis.udel.edu/~mccoy/courses/cisc882.03f (after Owen Rambow) 9/16/2018 CSC 9010- NLP -Context-Free Grammars

CSC 9010- NLP -Context-Free Grammars Grammaticality Does NOT depend on Having heard the sentence before The sentence being true Julia Roberts wears green pyjamas The sentence being meaningful Colorless green ideas sleep furiously *Furiously sleep ideas green colorless My groklar is sklivier than your bosser Grammatically is a formal property that we can investigate and describe 9/16/2018 CSC 9010- NLP -Context-Free Grammars

CSC 9010- NLP -Context-Free Grammars Syntax Words are strung together to form components of sentences which are in turn strung together to form other components or sentences New Concept: Constituency Constituent: group of words that behave as a single unit E.g., noun phrase (NP) 9/16/2018 CSC 9010- NLP -Context-Free Grammars

CSC 9010- NLP -Context-Free Grammars Evidence Whole group appears in similar syntactic environment (eg before a verb) Preposed/postposed constructions Note: notions of meaning play no role in syntax (sort-of) 9/16/2018 CSC 9010- NLP -Context-Free Grammars

CSC 9010- NLP -Context-Free Grammars What is Syntax? Study of structure of language Goal: relate surface form to semantics Morphology, phonology, semantics farmed out (mainly), issue is word order and structure Representational device is tree structure 9/16/2018 CSC 9010- NLP -Context-Free Grammars

CSC 9010- NLP -Context-Free Grammars What About Chomsky? At birth of formal language theory (comp sci) and formal linguistics Major contribution: syntax is cognitive reality Humans able to learn languages quickly, but not all languages  universal grammar is biological Goal of syntactic study: find universal principles and language-specific parameters Specific Chomskyan theories change regularly These ideas adopted by almost all contemporary syntactic theories (“principles-and-parameters-type theories”) 9/16/2018 CSC 9010- NLP -Context-Free Grammars

CSC 9010- NLP -Context-Free Grammars Types of Linguistics Descriptive: account of syntax of a language; often good enough for NLP engineering work Explanatory: principles-and-parameters style account of syntax of (preferably) several languages Prescriptive: “prescriptive linguistics” not very useful in any way “We don’t need no education…” 9/16/2018 CSC 9010- NLP -Context-Free Grammars

CSC 9010- NLP -Context-Free Grammars Syntax Why should you care? Grammar checkers Question answering Information extraction Machine translation 9/16/2018 CSC 9010- NLP -Context-Free Grammars

CSC 9010- NLP -Context-Free Grammars Example: S -> NP VP NP -> Det NOMINAL NOMINAL -> Noun VP -> Verb Det -> a Noun -> flight Verb -> left Productions 9/16/2018 CSC 9010- NLP -Context-Free Grammars

CSC 9010- NLP -Context-Free Grammars Earlier examples S → b a a A A → a A A → ! S → NP VP NP → PrNoun NP → Det Noun Det → a | the Noun → cat | dog| book PrNoun → samantha |elmer | fido VP → IVerb | TVerb NP IVerb → ran |slept | ate TVerb → hit | kissed | ate Regular language Regular? 9/16/2018 CSC 9010- NLP -Context-Free Grammars

CSC 9010- NLP -Context-Free Grammars CFGs S -> NP VP This says that there are units called S, NP, and VP in this language That an S consists of an NP followed immediately by a VP Doesn’t say that that’s the only kind of S Nor does it say that this is the only place that NPs and VPs occur 9/16/2018 CSC 9010- NLP -Context-Free Grammars

CSC 9010- NLP -Context-Free Grammars Generativity As with FSAs and FSTs you can view these rules as either analysis or synthesis machines Generate strings in the language Reject strings not in the language Impose structures (trees) on strings in the language 9/16/2018 CSC 9010- NLP -Context-Free Grammars

CSC 9010- NLP -Context-Free Grammars Derivations A derivation is a sequence of rules applied to a string that accounts for that string Covers all the elements in the string Covers only the elements in the string 9/16/2018 CSC 9010- NLP -Context-Free Grammars

Context-Free Grammars Defined in formal language theory (comp sci) Terminals, nonterminals, start symbol, rules String-rewriting system Start with start symbol, rewrite using rules, done when only terminals left NOT A LINGUISTIC THEORY, just a formal device 9/16/2018 CSC 9010- NLP -Context-Free Grammars

CSC 9010- NLP -Context-Free Grammars Derivations as Trees Phrase structure tree 9/16/2018 CSC 9010- NLP -Context-Free Grammars

Another example - Types of Nodes (((the/Det) boy/N) likes/V ((a/Det) girl/N)) boy the likes girl a DetP NP S nonterminal symbols (constituents) terminal symbols = words 9/16/2018 CSC 9010- NLP -Context-Free Grammars

CFG: Example Many possible CFGs for English, here is an example (fragment): S  NP VP VP  V NP NP  DetP N | AdjP NP AdjP  Adj | Adv AdjP N  boy | girl V  sees | likes Adj  big | small Adv  very DetP  a | the the very small boy likes a girl 9/16/2018 CSC 9010- NLP -Context-Free Grammars

CSC 9010- NLP -Context-Free Grammars Derivations in a CFG S S  NP VP VP  V NP NP  DetP N | AdjP NP AdjP  Adj | Adv AdjP N  boy | girl V  sees | likes Adj  big | small Adv  very DetP  a | the S 9/16/2018 CSC 9010- NLP -Context-Free Grammars

CSC 9010- NLP -Context-Free Grammars Derivations in a CFG NP VP S  NP VP VP  V NP NP  DetP N | AdjP NP AdjP  Adj | Adv AdjP N  boy | girl V  sees | likes Adj  big | small Adv  very DetP  a | the S NP VP 9/16/2018 CSC 9010- NLP -Context-Free Grammars

CSC 9010- NLP -Context-Free Grammars Derivations in a CFG DetP N VP S  NP VP VP  V NP NP  DetP N | AdjP NP AdjP  Adj | Adv AdjP N  boy | girl V  sees | likes Adj  big | small Adv  very DetP  a | the S NP VP DetP N 9/16/2018 CSC 9010- NLP -Context-Free Grammars

CSC 9010- NLP -Context-Free Grammars Derivations in a CFG the boy VP S  NP VP VP  V NP NP  DetP N | AdjP NP AdjP  Adj | Adv AdjP N  boy | girl V  sees | likes Adj  big | small Adv  very DetP  a | the S NP VP DetP N the boy 9/16/2018 CSC 9010- NLP -Context-Free Grammars

CSC 9010- NLP -Context-Free Grammars Derivations in a CFG the boy likes NP S  NP VP VP  V NP NP  DetP N | AdjP NP AdjP  Adj | Adv AdjP N  boy | girl V  sees | likes Adj  big | small Adv  very DetP  a | the S NP VP DetP N V NP the boy likes 9/16/2018 CSC 9010- NLP -Context-Free Grammars

CSC 9010- NLP -Context-Free Grammars Derivations in a CFG the boy likes a girl S  NP VP VP  V NP NP  DetP N | AdjP NP AdjP  Adj | Adv AdjP N  boy | girl V  sees | likes Adj  big | small Adv  very DetP  a | the S NP VP DetP N V NP the boy likes DetP N a girl 9/16/2018 CSC 9010- NLP -Context-Free Grammars

Derivations in a CFG; Order of Derivation Irrelevant NP likes DetP girl S  NP VP VP  V NP NP  DetP N | AdjP NP AdjP  Adj | Adv AdjP N  boy | girl V  sees | likes Adj  big | small Adv  very DetP  a | the S NP VP V NP likes DetP N girl 9/16/2018 CSC 9010- NLP -Context-Free Grammars

CSC 9010- NLP -Context-Free Grammars Derivations of CFGs String rewriting system: we derive a string (=derived structure) But derivation history represented by phrase-structure tree (=derivation structure)! 9/16/2018 CSC 9010- NLP -Context-Free Grammars

CSC 9010- NLP -Context-Free Grammars Grammar Equivalence Can have different grammars that generate same set of strings (weak equivalence) Grammar 1: NP  DetP N and DetP  a | the Grammar 2: NP  a N | NP  the N Can have different grammars that have same set of derivation trees (strong equivalence) With CFGs, possible only with useless rules Grammar 2’: DetP  many Strong equivalence implies weak equivalence 9/16/2018 CSC 9010- NLP -Context-Free Grammars

CSC 9010- NLP -Context-Free Grammars Normal Forms &c There are weakly equivalent normal forms (Chomsky Normal Form, Greibach Normal Form) There are ways to eliminate useless productions and so on 9/16/2018 CSC 9010- NLP -Context-Free Grammars

Nobody Uses CFGs Only (Except Intro NLP Courses) All major syntactic theories (Chomsky, LFG, HPSG) represent both phrase structure and dependency, in one way or another All successful parsers currently use statistics about phrase structure and about dependency Derive dependency through “head percolation”: for each rule, say which daughter is head 9/16/2018 CSC 9010- NLP -Context-Free Grammars

What about Computational Complexity – Options to CFG Regular Grammars – generally claimed to be too weak to capture linguistic generalizations Context Sentsitive Grammars – generally regarded as too strong Recursively Enumerable (Type 0) Grammars – generally regarded as way too strong Approaches that are TOO STRONG have the power to predict/describe/capture syntactic structures that don’t exist in human languages. (But CFG probably not enough) Computational processes associated with stronger formalisms are not as efficient as those associated with weaker methods 9/16/2018 CSC 9010- NLP -Context-Free Grammars

Massive Ambiguity of Syntax For a standard sentence, and a grammar with wide coverage, there are 1000s of derivations! Example: The large head painter told the delegation that he gave money orders and shares in a letter on Wednesday 9/16/2018 CSC 9010- NLP -Context-Free Grammars

CSC 9010- NLP -Context-Free Grammars Penn Treebank, Again Syntactically annotated corpus (phrase structure) PTB is not naturally occurring data! Represents a particular linguistic theory (but a fairly “vanilla” one) Particularities Very indirect representation of grammatical relations (need for head percolation tables) Completely flat structure in NP (brown bag lunch, pink-and-yellow child seat ) Has flat Ss, flat VPs 9/16/2018 CSC 9010- NLP -Context-Free Grammars

CSC 9010- NLP -Context-Free Grammars Parsing Parsing is the process of taking a string and a grammar and returning a (many?) parse tree(s) for that string It is completely analogous to running a finite-state transducer with a tape It’s just more powerful Remember this means that there are languages we can capture with CFGs that we can’t capture with finite-state methods 9/16/2018 CSC 9010- NLP -Context-Free Grammars

CSC 9010- NLP -Context-Free Grammars Other Options Regular languages (expressions) Too weak Context-sensitive or Turing equivalent Too powerful 9/16/2018 CSC 9010- NLP -Context-Free Grammars

CSC 9010- NLP -Context-Free Grammars The notion of context in CFGs has nothing to do with the ordinary meaning of the word context in language. All it really means is that the non-terminal on the left-hand side of a rule is out there all by itself (free of context) A -> B C Means that I can rewrite an A as a B followed by a C regardless of the context in which A is found 9/16/2018 CSC 9010- NLP -Context-Free Grammars

Key Constituents (English) Sentences Noun phrases Verb phrases Prepositional phrases 9/16/2018 CSC 9010- NLP -Context-Free Grammars

CSC 9010- NLP -Context-Free Grammars Sentence-Types Declaratives: The cat ate my homework S -> NP VP Imperatives: Fetch! S -> VP Yes-No Questions: Do you love me? S -> Aux NP VP WH Questions: Where did that book go? S -> WH Aux NP VP 9/16/2018 CSC 9010- NLP -Context-Free Grammars

CSC 9010- NLP -Context-Free Grammars Recursion We’ll have to deal with rules such as the following where the non-terminal on the left also appears somewhere on the right (directly). NP -> NP PP [[The flight] [to Boston]] VP -> VP PP [[departed Miami] [at noon]] 9/16/2018 CSC 9010- NLP -Context-Free Grammars

CSC 9010- NLP -Context-Free Grammars Recursion Of course, this is what makes syntax interesting flights from Denver Flights from Denver to Miami Flights from Denver to Miami in February Flights from Denver to Miami in February on a Friday Flights from Denver to Miami in February on a Friday under $300 Flights from Denver to Miami in February on a Friday under $300 with lunch 9/16/2018 CSC 9010- NLP -Context-Free Grammars

CSC 9010- NLP -Context-Free Grammars Recursion Of course, this is what makes syntax interesting [[flights] [from Denver]] [[[Flights] [from Denver]] [to Miami]] [[[[Flights] [from Denver]] [to Miami]] [in February]] [[[[[Flights] [from Denver]] [to Miami]] [in February]] [on a Friday]] Etc. 9/16/2018 CSC 9010- NLP -Context-Free Grammars

CSC 9010- NLP -Context-Free Grammars The Point If you have a rule like VP -> V NP It only cares that the thing after the verb is an NP. It doesn’t have to know about the internal affairs of that NP 9/16/2018 CSC 9010- NLP -Context-Free Grammars

CSC 9010- NLP -Context-Free Grammars The Point VP -> V NP I hate flights from Denver Flights from Denver to Miami Flights from Denver to Miami in February Flights from Denver to Miami in February on a Friday Flights from Denver to Miami in February on a Friday under $300 Flights from Denver to Miami in February on a Friday under $300 with lunch 9/16/2018 CSC 9010- NLP -Context-Free Grammars

Conjunctive Constructions S -> S and S John went to NY and Mary followed him NP -> NP and NP VP -> VP and VP … In fact the right rule for English is X -> X and X 9/16/2018 CSC 9010- NLP -Context-Free Grammars

CSC 9010- NLP -Context-Free Grammars Problems Agreement Subcategorization Movement (for want of a better term) 9/16/2018 CSC 9010- NLP -Context-Free Grammars

CSC 9010- NLP -Context-Free Grammars Agreement This dog Those dogs This dog eats Those dogs eat *This dogs *Those dog *This dog eat *Those dogs eats 9/16/2018 CSC 9010- NLP -Context-Free Grammars

Handing Number Agreement in CFGs To handle, would need to expand the grammar with multiple sets of rules – but it gets rather messy quickly. NP_sg  Det_sg N_sg NP_pl  Det_pl N_pl ….. VP_sg  V_sg NP_sg VP_sg  V_sg NP_pl VP_pl  V_pl NP_sg VP_pl  V_pl NP_pl 9/16/2018 CSC 9010- NLP -Context-Free Grammars

CSC 9010- NLP -Context-Free Grammars Subcategorization Sneeze: John sneezed Find: Please find [a flight to NY]NP Give: Give [me]NP[a cheaper fare]NP Help: Can you help [me]NP[with a flight]PP Prefer: I prefer [to leave earlier]TO-VP Told: I was told [United has a flight]S … 9/16/2018 CSC 9010- NLP -Context-Free Grammars

CSC 9010- NLP -Context-Free Grammars Subcategorization *John sneezed the book *I prefer United has a flight *Give with a flight Subcat expresses the constraints that a predicate (verb for now) places on the number and syntactic types of arguments it wants to take (occur with). 9/16/2018 CSC 9010- NLP -Context-Free Grammars

CSC 9010- NLP -Context-Free Grammars So? So the various rules for VPs overgenerate. They permit the presence of strings containing verbs and arguments that don’t go together For example VP -> V NP therefore Sneezed the book is a VP since “sneeze” is a verb and “the book” is a valid NP 9/16/2018 CSC 9010- NLP -Context-Free Grammars

CSC 9010- NLP -Context-Free Grammars The Point CFGs appear to be just about what we need to account for a lot of basic syntactic structure in English. But there are problems That can be dealt with adequately, although not elegantly, by staying within the CFG framework. There are simpler, more elegant, solutions that take us out of the CFG framework (beyond its formal power) 9/16/2018 CSC 9010- NLP -Context-Free Grammars