ling 388: language and computers sandiway fong 10/15 lecture 15

36
LING 388: Language and Computers Sandiway Fong 10/15 Lecture 15

Upload: kenya-millham

Post on 31-Mar-2015

218 views

Category:

Documents


1 download

TRANSCRIPT

Page 1: LING 388: Language and Computers Sandiway Fong 10/15 Lecture 15

LING 388: Language and Computers

Sandiway Fong10/15

Lecture 15

Page 2: LING 388: Language and Computers Sandiway Fong 10/15 Lecture 15

Adminstrivia

• Reminder– Homework 4 due tonight…

• Extra credit homework out today– due Thursday– easy way to pick up extra points…

Page 3: LING 388: Language and Computers Sandiway Fong 10/15 Lecture 15

Last Time

• Applied the transformation:

• to NP and VP rules:1. np(np(DT,NN)) --> dt(DT), nn(NN).2. np(np(NP,PP)) --> np(NP), pp(PP).

3. vp(vp(VBD,NP)) --> vbd(VBD), np(NP).4. vp(vp(VP,PP)) --> vp(VP), pp(PP).

x(x(X,y)) --> x(X), [y].x(x(z)) --> [z].

[z]

[y]xx

x(X) --> [z], w(X,x(z)).x(x(z)) --> [z].w(W,X) --> [y], w(W,x(X,y)).w(x(X,y),X) --> [y].

[z]

[y]xx

Page 4: LING 388: Language and Computers Sandiway Fong 10/15 Lecture 15

Last Time

Page 5: LING 388: Language and Computers Sandiway Fong 10/15 Lecture 15

Last Time

• 2nd page:

Page 6: LING 388: Language and Computers Sandiway Fong 10/15 Lecture 15

Last Time

• Parses for:– I saw a boy with a telescope with a limp with no money

• Stanford Parser:

Page 7: LING 388: Language and Computers Sandiway Fong 10/15 Lecture 15

Last Time

• Parses for:– I saw a boy with a telescope with a limp with no money

3 PPswith a telescopewith a limpwith no money

14 parses …

Page 8: LING 388: Language and Computers Sandiway Fong 10/15 Lecture 15

sawa boy

a telescopea limpno money

Page 9: LING 388: Language and Computers Sandiway Fong 10/15 Lecture 15

sawa boy

a telescopea limp

no money

Page 10: LING 388: Language and Computers Sandiway Fong 10/15 Lecture 15

sawa boy

a telescopea limp

no money

Page 11: LING 388: Language and Computers Sandiway Fong 10/15 Lecture 15

sawa boy

a telescopea limpno money

Page 12: LING 388: Language and Computers Sandiway Fong 10/15 Lecture 15

sawa boy

a telescopea limp

no money

Page 13: LING 388: Language and Computers Sandiway Fong 10/15 Lecture 15

sawa telescopea limpno money

a boy

Page 14: LING 388: Language and Computers Sandiway Fong 10/15 Lecture 15

sawa telescopea limp

no moneya boy

Page 15: LING 388: Language and Computers Sandiway Fong 10/15 Lecture 15

sawa telescope

a limpno money

a boy

Page 16: LING 388: Language and Computers Sandiway Fong 10/15 Lecture 15

sawa telescope

a limpno money

a boy

Page 17: LING 388: Language and Computers Sandiway Fong 10/15 Lecture 15

sawa telescope

a limpno money

a boy

Page 18: LING 388: Language and Computers Sandiway Fong 10/15 Lecture 15

sawno money

a boya telescopea limp

Page 19: LING 388: Language and Computers Sandiway Fong 10/15 Lecture 15

sawa limpno money

a boya telescope

Page 20: LING 388: Language and Computers Sandiway Fong 10/15 Lecture 15

sawa limp

no moneya boy

a telescope

Page 21: LING 388: Language and Computers Sandiway Fong 10/15 Lecture 15

sawno money

a boya telescope

a limp

Page 22: LING 388: Language and Computers Sandiway Fong 10/15 Lecture 15

Why 14 parses?

• Parses for:– I saw a boy with a telescope with a limp with no money

• Two attachment points VP (saw a boy) and NP (a boy) for the three PPs (1. with a telescope, 2. with a limp, 3. with no money)

• Four cases:– 1. NP (1,2,3) VP– 2. NP (1,2) VP (3)– 3. NP (1) VP (2,3)– 4. NP VP (1,2,3)

Two items to attach: two possibilitiesXP 1 XP 1 2 2

Three items to attach: five possibilitiesXP 1 XP 1 XP 1 XP 1

XP 1 2 2 2

2 2 3 3 3 3

3

Total number of parses: 5 + 2 + 2 + 5 = 14

Page 23: LING 388: Language and Computers Sandiway Fong 10/15 Lecture 15

General recursive formula for # parses

• Let dk = configuration at depth k (k is depth of last PP)

• Formula:– dk d1 + ..+ dk + dk+1 (k=1,2,3,…)

• Start:– d1 (case: one PP, only one place to

attach it)– d1+ d2

– (d1+ d2 ) + (d1+ d2 + d3 ) = 2 d1+ 2 d2 + 1 d3

– 2 (d1+ d2 ) + 2 (d1+ d2 + d3 ) + (d1+ d2 + d3 + d4 ) = 5 d1+ 5 d2 + 3 d3 + 1 d4

Total for one PP: 1

Total for two PPs: 2Total for 3 PPs: 5

Total for 4 PPs: 14

XP 1 XP 1 XP 1

2 2 2 3 3 3Depth: 1 1

2

Page 24: LING 388: Language and Computers Sandiway Fong 10/15 Lecture 15

General recursive formula for # parses

• In principle, the formula allows to extrapolate the number of syntactically valid parses to an arbitrary number of PPs in a row…

perhaps of academic interest only…

Page 25: LING 388: Language and Computers Sandiway Fong 10/15 Lecture 15

General recursive formula for # parses

• Use the formula in conjunction with the possible attachments at the top level:– Case: just one PP phrase, e.g. [PP1 with a telescope]

• NP (1) VP 1 d1

• NP VP (1) 1 d1 = 2 (total)

– Case: two PP phrases, e.g. [PP1with a telescope] [PP2 with a limp]• NP (1,2) VP d1+ d2

• NP (1) VP (2) 1 d1 x 1 d1

• NP VP (1,2) d1+ d2 = 5 (total)

Page 26: LING 388: Language and Computers Sandiway Fong 10/15 Lecture 15

General recursive formula for # parses

– Case: three PP phrases, e.g. [PP1with a telescope] [PP2 with a limp] [PP3 with no money]• NP (1,2,3) VP 2 d1+ 2 d2 + d3

• NP (1,2) VP (3) (d1+ d2 ) x 1 d1

• NP (1) VP (2,3) 1 d1 x (d1+ d2 )

• NP VP (1,2,3) 2 d1+ 2 d2 + d3 = 14 (total)

Page 27: LING 388: Language and Computers Sandiway Fong 10/15 Lecture 15

General recursive formula for # parses

• Let’s see if our formula correctly predicts the number of parses for four PPs:– Case: three PP phrases, e.g. [PP1with a telescope] [PP2

with a limp] [PP3 with no money] ] [PP4 with a smile]• NP (1,2,3,4) VP 5 d1+ 5 d2 + 3 d3 + d4

• NP (1,2,3) VP (4) (2 d1+ 2 d2 + d3 ) x 1 d1

• NP (1,2) VP (3,4) (d1+ d2 ) x (d1+ d2 )

• NP (1) VP (2,3,4) 1 d1 x (2 d1+ 2 d2 + d3 )

• NP VP (1,2,3,4) 5 d1+ 5 d2 + 3 d3 + d4= 42 (total)

Page 28: LING 388: Language and Computers Sandiway Fong 10/15 Lecture 15

Extended grammar

Page 29: LING 388: Language and Computers Sandiway Fong 10/15 Lecture 15

Counting Parses

• To count the number of parses, run the command:– findall(Parse,s(Parse,

[i,saw,a,boy,with,a,telescope,with,a,limp,with,no,money,with,a,smile],[]),List), length(List,Number).

– Note:• findall/3 finds all solutions to the s/3 query, each time it finds a

solution it puts it into a list (called List here)• we evaluate the length of that List = Number

Page 30: LING 388: Language and Computers Sandiway Fong 10/15 Lecture 15

Counting Parses

Page 31: LING 388: Language and Computers Sandiway Fong 10/15 Lecture 15

Counting Parses

Page 32: LING 388: Language and Computers Sandiway Fong 10/15 Lecture 15

Counting Parses

Page 33: LING 388: Language and Computers Sandiway Fong 10/15 Lecture 15

Counting Parses

Page 34: LING 388: Language and Computers Sandiway Fong 10/15 Lecture 15

Counting Parses

Page 35: LING 388: Language and Computers Sandiway Fong 10/15 Lecture 15

Counting Parses

Number of parses increases exponentially..

Page 36: LING 388: Language and Computers Sandiway Fong 10/15 Lecture 15

Homework 5

• Extra Credit (optional)– We know there are 5 attachment possibilities for 2 PPs following V

NP– Show that all 5 are possible in natural language

• i.e. construct sentences where each of the 5 possibilities would be the most likely parse

• (you may change the words for each example)e.g. I saw a boy with a telescope on a heavy tripod