Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSC NLP -Context-Free Grammars

Similar presentations


Presentation on theme: "CSC NLP -Context-Free Grammars"— Presentation transcript:

1 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: McCoy: (after Owen Rambow) 9/16/2018 CSC NLP -Context-Free Grammars

2 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 NLP -Context-Free Grammars

3 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 NLP -Context-Free Grammars

4 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 NLP -Context-Free Grammars

5 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 NLP -Context-Free Grammars

6 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 NLP -Context-Free Grammars

7 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 NLP -Context-Free Grammars

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

9 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 NLP -Context-Free Grammars

10 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 NLP -Context-Free Grammars

11 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 NLP -Context-Free Grammars

12 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 NLP -Context-Free Grammars

13 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 NLP -Context-Free Grammars

14 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 NLP -Context-Free Grammars

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

16 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 NLP -Context-Free Grammars

17 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 NLP -Context-Free Grammars

18 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 NLP -Context-Free Grammars

19 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 NLP -Context-Free Grammars

20 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 NLP -Context-Free Grammars

21 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 NLP -Context-Free Grammars

22 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 NLP -Context-Free Grammars

23 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 NLP -Context-Free Grammars

24 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 NLP -Context-Free Grammars

25 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 NLP -Context-Free Grammars

26 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 NLP -Context-Free Grammars

27 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 NLP -Context-Free Grammars

28 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 NLP -Context-Free Grammars

29 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 NLP -Context-Free Grammars

30 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 NLP -Context-Free Grammars

31 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 NLP -Context-Free Grammars

32 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 NLP -Context-Free Grammars

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

34 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 NLP -Context-Free Grammars

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

36 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 NLP -Context-Free Grammars

37 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 NLP -Context-Free Grammars

38 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 NLP -Context-Free Grammars

39 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 NLP -Context-Free Grammars

40 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 NLP -Context-Free Grammars

41 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 NLP -Context-Free Grammars

42 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 NLP -Context-Free Grammars

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

44 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 NLP -Context-Free Grammars

45 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 NLP -Context-Free Grammars

46 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 NLP -Context-Free Grammars

47 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 NLP -Context-Free Grammars

48 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 NLP -Context-Free Grammars

49 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 NLP -Context-Free Grammars


Download ppt "CSC NLP -Context-Free Grammars"

Similar presentations


Ads by Google