+ All Categories
Home > Documents > Syntax and Parsing

Syntax and Parsing

Date post: 29-Jan-2017
Category:
Upload: hoangque
View: 231 times
Download: 1 times
Share this document with a friend
45
CS 544 NLP Spring 2011 Syntax and Parsing Dirk Hovy 1-13-2011 (some slides from Liang Huang) S NP VP 1 Freitag, 14. Januar 2011
Transcript
Page 1: Syntax and Parsing

CS 544 NLPSpring 2011

Syntax and Parsing

Dirk Hovy1-13-2011

(some slides from Liang Huang)

S → NP VP

1Freitag, 14. Januar 2011

Page 2: Syntax and Parsing

CS 544 NLPSpring 2011

Syntax and Parsing

Dirk Hovy1-13-2011

(some slides from Liang Huang)

S → NP VP

1Freitag, 14. Januar 2011

Page 3: Syntax and Parsing

CS 544 NLPSpring 2011

Syntax and Parsing

Dirk Hovy1-13-2011

(some slides from Liang Huang)

S → NP VP

1Freitag, 14. Januar 2011

Page 4: Syntax and Parsing

What’s wrong here?

hovercraft full my is eels of

2Freitag, 14. Januar 2011

Page 5: Syntax and Parsing

What’s wrong here?

my hovercraft is full of eels

3Freitag, 14. Januar 2011

Page 6: Syntax and Parsing

Order, please!

• some orders are grammatical, others not

*hovercraft full my is eels ofvs.

my hovercraft is full of eels

4Freitag, 14. Januar 2011

Page 7: Syntax and Parsing

Order, please!

• some orders are grammatical, others not

*hovercraft full my is eels ofvs.

my hovercraft is full of eels

ungrammatical sentences are marked with a *

4Freitag, 14. Januar 2011

Page 8: Syntax and Parsing

Syntax

• study of word order

• one of fundamental levels of language (phonetics/phonology, morphology, syntax, semantics, pragmatics)

• has to do with trees…

• Chomsky says: independent of meaning!Colorless green ideas sleep furiously

5Freitag, 14. Januar 2011

Page 9: Syntax and Parsing

Sentence elements

• [my hovercraft] [is full of eels][it] [is full of eels][my air-powered aquatic vehicle] [is full of eels][my hovercraft] [sank]

• we can exchange certain elements: phrases (or constituents)

6Freitag, 14. Januar 2011

Page 10: Syntax and Parsing

How to spot phrases from a large distance

• substitution:it is full of eels {it = my hovercraft}

• deletion (produces nonsense):*Ø is full of eels

7Freitag, 14. Januar 2011

Page 11: Syntax and Parsing

Recurring structures

• substitution shows: many sentences have the same structure

• pick any two to make a sentence:

my hovercraftDennis Moore

a man with three buttocks

is full of eelshas a brotherowns a shack

is huge

8Freitag, 14. Januar 2011

Page 12: Syntax and Parsing

Recurring structures

• substitution shows: many sentences have the same structure

• pick any two to make a sentence:

my hovercraftDennis Moore

a man with three buttocks

is full of eelshas a brotherowns a shack

is huge

Noun

phrases

8Freitag, 14. Januar 2011

Page 13: Syntax and Parsing

Recurring structures

• substitution shows: many sentences have the same structure

• pick any two to make a sentence:

my hovercraftDennis Moore

a man with three buttocks

is full of eelshas a brotherowns a shack

is huge

Noun

phrasesVerb

phrases

8Freitag, 14. Januar 2011

Page 14: Syntax and Parsing

CS 544 - Syntax and Parsing

Context-Free Grammars

• S ! NP VP

• NP ! Det N

• NP ! NP PP

•PP ! P NP

•VP ! V NP

•VP ! VP PP

• ...

20

• N ! {ball, garden, house, sushi }

• P ! {in, behind, with}

• V ! ...

• Det ! ...

slide by Liang Huang

9Freitag, 14. Januar 2011

Page 15: Syntax and Parsing

CS 544 - Syntax and Parsing

Context-Free Grammars

• S ! NP VP

• NP ! Det N

• NP ! NP PP

•PP ! P NP

•VP ! V NP

•VP ! VP PP

• ...

20

• N ! {ball, garden, house, sushi }

• P ! {in, behind, with}

• V ! ...

• Det ! ...

slide by Liang Huang

most famous rule in linguistics ever…

9Freitag, 14. Januar 2011

Page 16: Syntax and Parsing

CS 544 - Syntax and Parsing

Context-Free Grammars

21

A CFG is a 4-tuple〈N,!,R,S〉 A set of nonterminals N

(e.g. N = {S, NP, VP, PP, Noun, Verb, ....})

A set of terminals !

(e.g. ! = {I, you, he, eat, drink, sushi, ball, })

A set of rules R

R ! {A ! " with left-hand-side (LHS)" A " N

and right-hand-side (RHS) " " (N # !)* }

A start symbol S (sentence)

slide by Liang Huang

10Freitag, 14. Januar 2011

Page 17: Syntax and Parsing

CS 544 - Syntax and Parsing

Parse Trees

• N ! {sushi, tuna}

• P ! {with}

• V ! {eat}

• NP ! N

• NP ! NP PP

• PP!P NP

• VP!V NP

• VP!VP PP

22

slide by Liang Huang

11Freitag, 14. Januar 2011

Page 18: Syntax and Parsing

CS 544 - Syntax and Parsing

Parse Trees

• N ! {sushi, tuna}

• P ! {with}

• V ! {eat}

• NP ! N

• NP ! NP PP

• PP!P NP

• VP!V NP

• VP!VP PP

22

slide by Liang Huang

terminals

11Freitag, 14. Januar 2011

Page 19: Syntax and Parsing

CS 544 - Syntax and Parsing

Parse Trees

• N ! {sushi, tuna}

• P ! {with}

• V ! {eat}

• NP ! N

• NP ! NP PP

• PP!P NP

• VP!V NP

• VP!VP PP

22

slide by Liang Huang

terminalspre-terminals

11Freitag, 14. Januar 2011

Page 20: Syntax and Parsing

CS 544 - Syntax and Parsing

Parse Trees

• N ! {sushi, tuna}

• P ! {with}

• V ! {eat}

• NP ! N

• NP ! NP PP

• PP!P NP

• VP!V NP

• VP!VP PP

22

slide by Liang Huang

terminalspre-terminals

non-terminals

11Freitag, 14. Januar 2011

Page 21: Syntax and Parsing

Grammaticality

• a sentence is grammatical if there is an acceptor for it

DT ADJ NN>

12Freitag, 14. Januar 2011

Page 22: Syntax and Parsing

Generate from CFGs

initialize stack with Swhile stack not empty:

x = stack.pop()if x ∈ terminals:

print xelse if x ∈ rule:

stack.push(y in RHS for selected x → RHS)

13Freitag, 14. Januar 2011

Page 23: Syntax and Parsing

Parsing

• find a path b/w root node S and terminals

• recursively apply CFG rules

• glorified search

• options:

• direction: top-down, bottom-up

• expansion: breadth-first, depth-first, bidirectional

14Freitag, 14. Januar 2011

Page 24: Syntax and Parsing

Probabilistic parsing

• some rules are more likely than others:N → dog, 0.9V → dog, 0.1

• use probabilities to decide best path

15Freitag, 14. Januar 2011

Page 25: Syntax and Parsing

Playtime

• Given the following CFG, how many parses exists for the rose rose rose?

• S→NP• S →NP VP• NP → DT NP2• NP2 →JJ NP2• NP2 →N N• NP2 →N • VP→V• V →rose• N → rose• JJ →rose

16Freitag, 14. Januar 2011

Page 26: Syntax and Parsing

CS 544 - Syntax and Parsing

Ambiguity Explosion by Recursion

• how about...

• I saw her duck with a telescope.

• I saw her duck with a telescope in the garden...9

...

I saw her duck.

slide by Liang Huang

17Freitag, 14. Januar 2011

Page 27: Syntax and Parsing

Why do we care?

• parsing first step for most NLP tasks (MT, IE, IR, etc.)

• disambiguate

• find certain structures (noun phrases = chunking)

• find syntactically related words

18Freitag, 14. Januar 2011

Page 28: Syntax and Parsing

Other parsing• dependency parsing: instead of

constituents, find grammatical relations

Steve/NNP

Young/NNP

throw/VBD

pass/NN

a/DT

to/TO

Michael/NNP

Holt/NNP

nsubj

dobj

prep

nn

nn

pobjdet

• depends on verb

• adds information

• less readable

Steve Young threw a pass to Michael Holt

19Freitag, 14. Januar 2011

Page 29: Syntax and Parsing

CS 544 - Syntax and Parsing

Chomsky Hierarchy

24CS 498 JH: Introduction to NLP (Fall ’08)

computer science and linguistics share the same mathematical foundations.

slide by Liang Huang

20Freitag, 14. Januar 2011

Page 30: Syntax and Parsing

In sum: Syntax

21Freitag, 14. Januar 2011

Page 31: Syntax and Parsing

In sum: Syntax

• syntax = study of word order

21Freitag, 14. Januar 2011

Page 32: Syntax and Parsing

In sum: Syntax

• syntax = study of word order

• sentences consist of phrases (constituents)

I fart [in your general direction][on Sundays]

[with pleasure]

21Freitag, 14. Januar 2011

Page 33: Syntax and Parsing

In sum: Syntax

• syntax = study of word order

• sentences consist of phrases (constituents)

• substitution can determine constituents

I fart [in your general direction][on Sundays]

[with pleasure]

21Freitag, 14. Januar 2011

Page 34: Syntax and Parsing

In sum: Syntax

• syntax = study of word order

• sentences consist of phrases (constituents)

• substitution can determine constituents

• CFGs capture syntax rules

S → NP VP

21Freitag, 14. Januar 2011

Page 35: Syntax and Parsing

In sum: Syntax

• syntax = study of word order

• sentences consist of phrases (constituents)

• substitution can determine constituents

• CFGs capture syntax rules

• syntax rules are recursive

S → NP VPNP → DT N

21Freitag, 14. Januar 2011

Page 36: Syntax and Parsing

In sum: Syntax

• syntax = study of word order

• sentences consist of phrases (constituents)

• substitution can determine constituents

• CFGs capture syntax rules

• syntax rules are recursive

21Freitag, 14. Januar 2011

Page 37: Syntax and Parsing

In sum: Parsing

22Freitag, 14. Januar 2011

Page 38: Syntax and Parsing

In sum: Parsing

• parsers find rule structure of sentence

22Freitag, 14. Januar 2011

Page 39: Syntax and Parsing

In sum: Parsing

• parsers find rule structure of sentence

• different strategies for search

22Freitag, 14. Januar 2011

Page 40: Syntax and Parsing

In sum: Parsing

• parsers find rule structure of sentence

• different strategies for search

• path b/w root and terminals

22Freitag, 14. Januar 2011

Page 41: Syntax and Parsing

In sum: Parsing

• parsers find rule structure of sentence

• different strategies for search

• path b/w root and terminals

• language is ambiguous

22Freitag, 14. Januar 2011

Page 42: Syntax and Parsing

In sum: Parsing

• parsers find rule structure of sentence

• different strategies for search

• path b/w root and terminals

• language is ambiguous

• parse trees are unambiguous

22Freitag, 14. Januar 2011

Page 43: Syntax and Parsing

In sum: Parsing

• parsers find rule structure of sentence

• different strategies for search

• path b/w root and terminals

• language is ambiguous

• parse trees are unambiguous

• used to find structure, constituents, disambiguate words

22Freitag, 14. Januar 2011

Page 44: Syntax and Parsing

If you learned nothing else:

• S → NP VP

• parsing is search

23Freitag, 14. Januar 2011

Page 45: Syntax and Parsing

ask now or enjoy your afternoon…

24Freitag, 14. Januar 2011


Recommended