syntactic analysis using context free grammars

57
Syntactic analysis using Context Free Grammars

Upload: caroun

Post on 15-Jan-2016

73 views

Category:

Documents


0 download

DESCRIPTION

Syntactic analysis using Context Free Grammars. Analysis of language. Morphological analysis Chairs , Part Of Speech (POS) tagging The/DT man/NN left/VBD the/DT room/NN - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Syntactic analysis using  Context Free Grammars

Syntactic analysis using Context Free Grammars

Page 2: Syntactic analysis using  Context Free Grammars

Analysis of language

• Morphological analysis– Chairs <chair, n, plural>, <chair, v, 3rd person, present>

• Part Of Speech (POS) tagging– The/DT man/NN left/VBD the/DT room/NN– The/DT red/ADJ block/NN on/PREP the/DT blue/ADJ

cylinder/NN was/AUX moved/VBD onto/PREP the/DT brown/ADJ table/NN

• Any further analysis?

Page 3: Syntactic analysis using  Context Free Grammars

Analysis of language

• Part Of Speech (POS) tagging– The/DT man/NN left/VBD the/DT room/NN– The/DT red/ADJ block/NN on/PREP the/DT blue/ADJ

cylinder/NN was/AUX moved/VBD onto/PREP the/DT brown/ADJ table/NN

• Any further analysis?– chunks, clauses, syntax, semantics, word senses etc…

• Today’s lecture on analyzing syntax

Page 4: Syntactic analysis using  Context Free Grammars

What is Syntax?

• Study of structure of language– how words can connect to each other

• Specifically, goal is to relate surface form (i.e. the sentence) to semantics (the meaning)

• Representational device is tree structure

Page 5: Syntactic analysis using  Context Free Grammars

Structure in StringsProposal 1

• Some words: the a small nice big very boy girl sees likes

• Some good sentences:– (the) boy (likes a girl) – (the small) girl (likes the big girl)– (a very small nice) boy (sees a very nice boy)

• Some bad sentences:– *(the) boy (the girl)– *(small) boy (likes the nice girl)

Page 6: Syntactic analysis using  Context Free Grammars

Structure in StringsProposal 2

• Some words: the a small nice big very boy girl sees likes

• Some good sentences:– (the boy) likes (a girl) – (the small girl) likes (the big girl)– (a very small nice boy) sees (a very nice boy)

• Some bad sentences:– *(the boy) (the girl)– *(small boy) likes (the nice girl)

Page 7: Syntactic analysis using  Context Free Grammars

More Structure in StringsProposal 2 -- ctd

• Some words: the a small nice big very boy girl sees likes

• Some good sentences:– ((the) boy) likes ((a) girl) – ((the) (small) girl) likes ((the) (big) girl)– ((a) ((very) small) (nice) boy) sees ((a) ((very) nice) girl)

• Some bad sentences:– *((the) boy) ((the) girl)– *((small) boy) likes ((the) (nice) girl)

Page 8: Syntactic analysis using  Context Free Grammars

From Substrings to Trees

• (((the) boy) likes ((a) girl))

boythe

likesgirl

a

Page 9: Syntactic analysis using  Context Free Grammars
Page 10: Syntactic analysis using  Context Free Grammars
Page 11: Syntactic analysis using  Context Free Grammars
Page 12: Syntactic analysis using  Context Free Grammars
Page 13: Syntactic analysis using  Context Free Grammars
Page 14: Syntactic analysis using  Context Free Grammars
Page 15: Syntactic analysis using  Context Free Grammars
Page 16: Syntactic analysis using  Context Free Grammars
Page 17: Syntactic analysis using  Context Free Grammars
Page 18: Syntactic analysis using  Context Free Grammars
Page 19: Syntactic analysis using  Context Free Grammars
Page 20: Syntactic analysis using  Context Free Grammars
Page 21: Syntactic analysis using  Context Free Grammars
Page 22: Syntactic analysis using  Context Free Grammars
Page 23: Syntactic analysis using  Context Free Grammars
Page 24: Syntactic analysis using  Context Free Grammars
Page 25: Syntactic analysis using  Context Free Grammars
Page 26: Syntactic analysis using  Context Free Grammars
Page 27: Syntactic analysis using  Context Free Grammars

27

Context-Free Grammars

• Terminals– This would be the lexicon/vocabulary

• Non-Terminals– The constituents in a language

• Like noun phrase, verb phrase, prepositional phrase and sentence

• Rules– Rules consist of a single non-terminal on the left and any number of terminals

and non-terminals on the right.– Describe the allowed structure of the constituents– Express the ways in which symbols of the language can be grouped or ordered

together

Page 28: Syntactic analysis using  Context Free Grammars
Page 29: Syntactic analysis using  Context Free Grammars

Phrase Structure Tree

• (((the/Det) boy/N) likes/V ((a/Det) girl/N))

boy

the

likes

girl

a

DetP

NP NP

DetP

S

Phrase-structuretree

nonterminalsymbols= constituents

terminal symbols = words

Page 30: Syntactic analysis using  Context Free Grammars

Context?

• The notion of context in CFGs is not the same as 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– 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

Page 31: Syntactic analysis using  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

Page 32: Syntactic analysis using  Context Free Grammars

Derivations in a CFG

S NP VPVP V NPNP DetP N | AdjP NPAdjP Adj | Adv AdjPN boy | girlV sees | likesAdj big | smallAdv very DetP a | the

S

S

Page 33: Syntactic analysis using  Context Free Grammars

Derivations in a CFG

S NP VPVP V NPNP DetP N | AdjP NPAdjP Adj | Adv AdjPN boy | girlV sees | likesAdj big | smallAdv very DetP a | the

NP VP

NP

S

VP

Page 34: Syntactic analysis using  Context Free Grammars

Derivations in a CFG

S NP VPVP V NPNP DetP N | AdjP NPAdjP Adj | Adv AdjPN boy | girlV sees | likesAdj big | smallAdv very DetP a | the

DetP N VP

DetP

NP

S

VP

N

Page 35: Syntactic analysis using  Context Free Grammars

Derivations in a CFG

S NP VPVP V NPNP DetP N | AdjP NPAdjP Adj | Adv AdjPN boy | girlV sees | likesAdj big | smallAdv very DetP a | the

the boy VP

boythe

DetP

NP

S

VP

N

Page 36: Syntactic analysis using  Context Free Grammars

Derivations in a CFG

S NP VPVP V NPNP DetP N | AdjP NPAdjP Adj | Adv AdjPN boy | girlV sees | likesAdj big | smallAdv very DetP a | the

the boy likes NP

boythe likes

DetP

NP

NP

S

VP

N V

Page 37: Syntactic analysis using  Context Free Grammars

Derivations in a CFG

S NP VPVP V NPNP DetP N | AdjP NPAdjP Adj | Adv AdjPN boy | girlV sees | likesAdj big | smallAdv very DetP a | the

the boy likes a girl

boythe likes

DetP

NP

girla

NP

DetP

S

VP

N

N

V

Page 38: Syntactic analysis using  Context Free Grammars

38

Simple lexicon

Page 39: Syntactic analysis using  Context Free Grammars

39

Simple grammar

Page 40: Syntactic analysis using  Context Free Grammars

40

Generativity

• We 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

Page 41: Syntactic analysis using  Context Free Grammars

41

A CFG defines a formal language

• Sentences (strings of words) that can be derived by the grammar are in the formal language defined by the grammar

• Sentences that cannot be derived from the grammar are not in the language– Ungrammatical

Page 42: Syntactic analysis using  Context Free Grammars

42

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

Page 43: Syntactic analysis using  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]]

Page 44: Syntactic analysis using  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

Page 45: Syntactic analysis using  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

Page 46: Syntactic analysis using  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

Page 47: Syntactic analysis using  Context Free Grammars

Potential Problems in CFG

• Agreement• Subcategorization• Movement

Page 48: Syntactic analysis using  Context Free Grammars

48

Agreement• By agreement, we have in mind constraints that hold among various constituents

that take part in a rule or set of rules

• For example, in English, determiners and the head nouns in NPs have to agree in their number.

This flightThose flights

*This flights*Those flight

Page 49: Syntactic analysis using  Context Free Grammars

49

Problem

• Our earlier NP rules are clearly deficient since they don’t capture this constraint– NP Det Nominal

• Accepts, and assigns correct structures, to grammatical examples (this flight)• But its also happy with incorrect examples (*these flight)

– Such a rule is said to overgenerate.

Page 50: Syntactic analysis using  Context Free Grammars

50

Verb Phrases• English VPs consist of a head verb along with 0 or more following

constituents which we’ll call arguments.

Page 51: Syntactic analysis using  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

• …

• *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 type of the argument it wants to take

Page 52: Syntactic analysis using  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

• Subcategorization frames can fix this problem (“slow down” overgeneration)

• This is a modern take on the traditional notion of transitive/intransitive.• Modern grammars may have 100s or such classes.

Page 53: Syntactic analysis using  Context Free Grammars

53

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

• …

Page 54: Syntactic analysis using  Context Free Grammars

Movement

• Core example– [[My travel agent]NP [booked [the flight]NP]VP]S

• I.e. “book” is a straightforward transitive verb. It expects a single NP arg within the VP as an argument, and a single NP arg as the subject.

Page 55: Syntactic analysis using  Context Free Grammars

Movement

• What about?– Which flight do you want me to have the travel agent book?

• The direct object argument to “book” isn’t appearing in the right place. It is in fact a long way from where its supposed to appear.

• And note that its separated from its verb by 2 other verbs.

Page 56: Syntactic analysis using  Context Free Grammars

Grammar equivalence and normal form

• Strong equivalence:– two grammars are strongly equivalent if:

• they generate the same set of strings• they assign the same phrase structure to each sentence

– two grammars are weakly equivalent if:• they generate the same set of strings• they do not assign the same phrase structure to each sentence

• Normal form – Restrict the form of productions– Chomsky Normal Form (CNF)– Right hand side of the productions has either one or two terminals or non-

terminals– e.g. A -> BC A -> a– Any grammar can be translated into a weakly equivalent CNF– A -> B C D <=> A-> B X X -> C D

Page 57: Syntactic analysis using  Context Free Grammars

Building tree structures

• Draw tree structures for the following phrases

• Dallas• from Denver• arriving in Washington• I need to fly between Philadelphia and Atlanta• My flight from Philadelphia to Atlanta has been cancelled