lecture cfg
TRANSCRIPT
-
7/30/2019 Lecture CFG
1/24
1
CONTEXT-FREE GRAMMARS
-
7/30/2019 Lecture CFG
2/24
NLE2
Syntactic analysis (Parsing)
S
NP VP
AT NNS VBD NP
AT NNthe children ate
the cake
-
7/30/2019 Lecture CFG
3/24
NLE4
Beyond regular languages:
Context-Free Grammars
S NP VPNP Det Nominal
Nominal Noun
VP V
Det theDet a
Noun flight
V left
-
7/30/2019 Lecture CFG
4/24
NLE5
Derivations
A DERIVATION of a string is a sequence of rule
applications
E.g., the string a flight can be derived from the grammar
above and symbol NP by the (leftmost first) derivation
NP => Det Nominal => a Nominal => a Noun => a flight
Derivations can be visualized as PARSE TREES
The LANGUAGE defined by a CFG is the set of stringsderivable from the start symbol S (for Sentence)
-
7/30/2019 Lecture CFG
5/24
NLE6
Derivations and parse trees
-
7/30/2019 Lecture CFG
6/24
NLE7
A more formal definition
A CFG is a 4-tuple
consisting of
-
7/30/2019 Lecture CFG
7/24
NLE8
What `context free means
-
7/30/2019 Lecture CFG
8/24
NLE9
Derivations and languages
The language LG GENERATED by a CFG
grammar G is the set of strings of TERMINALsymbols that can be derived from the start
symbol S using the production rules in G
LG = {w | w is in * and S derives w}
The strings in LG are called GRAMMATICAL The strings not in LG are called
UNGRAMMATICAL
-
7/30/2019 Lecture CFG
9/24
NLE10
Grammar development
One of the most basic skills in NLE is the ability
to write a CFG for some fragment of alanguage (e.g., the dates)
Well briefly cover some of the issues to be
addressed when writing small CFG grammars
-
7/30/2019 Lecture CFG
10/24
NLE11
An example lexicon
-
7/30/2019 Lecture CFG
11/24
NLE12
An example grammar
-
7/30/2019 Lecture CFG
12/24
NLE13
A simple parse tree
-
7/30/2019 Lecture CFG
13/24
NLE14
Basic types of phrases
Sentences
Noun Phrases Verb phrases
Prepositional phrases
-
7/30/2019 Lecture CFG
14/24
NLE15
Basic types of sentences
-
7/30/2019 Lecture CFG
15/24
NLE16
Noun phases: premodifiers
NP (Det) (Card) (Ord) (Quant) (AP) Nominal
Det: Determiners
a flight
Optional: Im looking forflights to Denver
Card: Cardinal numbers (one stop)
Ord: Ordinal numbers (the first flight)
Quantifiers: most flights to Denver leave in the morning
AP (Adjectives): three very expensive seats
-
7/30/2019 Lecture CFG
16/24
NLE17
Noun phases: postmodifiers
Nominal Noun
Nominal Nominal PP (PP) (PP) Nominal Nominal GerundVP
Nominal Nominal RelClause
-
7/30/2019 Lecture CFG
17/24
NLE18
Types of postnominal modifiers
-
7/30/2019 Lecture CFG
18/24
NLE19
Recursion
Nominal Nominal PP (PP) (PP)
Is an example of RECURSIVE rule Other examples:
NP NP PP
VP VP PP
Recursion a powerful device, but could havebad consequences (see lectures on parsing)
-
7/30/2019 Lecture CFG
19/24
NLE20
Recursion and VP attachment
-
7/30/2019 Lecture CFG
20/24
NLE21
Coordination
NP NP and NP
John and Mary left
VP VP and VP
John talks softly and carries a big stick
S S and / but / S
Kim is a lawyer but Sandy is reading medicine.
In fact, probably English has a
XP XP and XP
rule
-
7/30/2019 Lecture CFG
21/24
NLE22
Agreement
This dog
Those dogs *This dogs
*Those dogs
This dog is smart *This dog are smart
*Those dogs is smart
-
7/30/2019 Lecture CFG
22/24
NLE24
CFGs vs Regular languages
For many applications, finite state languages
(the languages defined by FA) are appropriate Limitation of FAs: cannot count
I.e., cannot check A n B n
Example of construction showing that English
is CF: long-distance dependencies Which film did Kim say the directorwho we just met
_recommended_?
-
7/30/2019 Lecture CFG
23/24
NLE25
The Chomsky Hierarchy
Finite-state languages (type 3)
A bC | Cb (a single NT on the right)
Context-free languages (type 2)
A BB
Context-sensitive languages (type 1)
CAC BB
Recursively enumerable languages
Every language that can be specified by a finite algorithm
-
7/30/2019 Lecture CFG
24/24
NLE26
Readings
Jurafsky and Martin, chapter 9
The chapters on context-free languages in The Free Dictionary:
http://encyclopedia.thefreedictionary.com/Context-
free%20language
Wikipedia:http://en.wikipedia.org/wiki/Context-free_grammar
http://encyclopedia.thefreedictionary.com/Context-free%20languagehttp://encyclopedia.thefreedictionary.com/Context-free%20languagehttp://en.wikipedia.org/wiki/Context-free_grammarhttp://en.wikipedia.org/wiki/Context-free_grammarhttp://en.wikipedia.org/wiki/Context-free_grammarhttp://en.wikipedia.org/wiki/Context-free_grammarhttp://encyclopedia.thefreedictionary.com/Context-free%20languagehttp://encyclopedia.thefreedictionary.com/Context-free%20languagehttp://encyclopedia.thefreedictionary.com/Context-free%20language