LING/C SC/PSYC 438/538 Lecture 19 Sandiway Fong 1.

19
LING/C SC/PSYC 438/538 Lecture 19 Sandiway Fong 1

Transcript of LING/C SC/PSYC 438/538 Lecture 19 Sandiway Fong 1.

Page 1: LING/C SC/PSYC 438/538 Lecture 19 Sandiway Fong 1.

1

LING/C SC/PSYC 438/538

Lecture 19Sandiway Fong

Page 2: LING/C SC/PSYC 438/538 Lecture 19 Sandiway Fong 1.

Today's Topic

• Let's write a phrase structure grammar (PSG) using Prolog

• Mechanisms:1. Extra argument for Prolog term representation

of a parse2. Extra arguments for feature value agreement3. Dealing with left recursive rules: grammar

transformation

Page 3: LING/C SC/PSYC 438/538 Lecture 19 Sandiway Fong 1.

Topics

• Mechanisms:1. Extra argument for Prolog term representation

of a parse2. Extra arguments for feature value agreement3. Dealing with left recursive rules: grammar

transformation

Page 4: LING/C SC/PSYC 438/538 Lecture 19 Sandiway Fong 1.

Parse

• Let's write a simple grammar returning appropriate parse trees for sentences like:– John kicked the ball– the men kicked the ball– a man kicked the ball

• Stanford Parser:– (ROOT– (S– (NP (DT the) (NNS men))– (VP (VBD kicked)– (NP (DT the) (NN ball)))))

Page 5: LING/C SC/PSYC 438/538 Lecture 19 Sandiway Fong 1.

Topics

• Mechanisms:1. Extra argument for Prolog term representation

of a parse2. Extra arguments for feature value agreement3. Dealing with left recursive rules: grammar

transformation

Page 6: LING/C SC/PSYC 438/538 Lecture 19 Sandiway Fong 1.

6

Extra Arguments: Agreement• Idea:

– We can also use an extra argument to impose constraints between constituents within a DCG rule

• Example: – English determiner-noun number agreement– Data:

• the man• the men• a man• *a men

– Lexical Features:• man singular• men plural

Page 7: LING/C SC/PSYC 438/538 Lecture 19 Sandiway Fong 1.

7

Extra Arguments: Agreement

• Data:– the man/men– a man/*a men

• Grammar: (NP section)np(np(Y)) --> pronoun(Y).np(np(D,N)) --> det(D,Number),

common_noun(N,Number).det(det(the),sg) --> [the].det(det(the),pl) --> [the].det(det(a),sg) --> [a].common_noun(n(ball),sg) --> [ball].common_noun(n(man),sg) --> [man].common_noun(n(men),pl) --> [men].pronoun(i) --> [i].pronoun(we) --> [we].

–Idea:give determiners a number feature as welland make it agree with the noun

•Rules• the can combine with

singular or plural nouns

• a can combine only with singular nouns

Page 8: LING/C SC/PSYC 438/538 Lecture 19 Sandiway Fong 1.

8

Extra Arguments: Agreement• Simplifying the grammar:

det(det(the),sg) --> [the].det(det(the),pl) --> [the].det(det(a),sg) --> [a].

• Grammar is ambiguous:– two rules for determiner the

• Agreement Rule (revisited):• the can combine with singular or plural nouns• i.e. the doesn’t care about the number of the noun

• DCG Rule:np(np(D,N)) --> det(D,Number), common_noun(N,Number).det(det(the),_) --> [the].

Note: _ is a variableused underscore character because we don’t care about the value of the variable

Page 9: LING/C SC/PSYC 438/538 Lecture 19 Sandiway Fong 1.

9

Extra Arguments: Agreement

Note:• Use of the extra

argument for agreement here is basically “syntactic sugar” and lends no more expressive power to the grammar rule system

• i.e. we can enforce the agreement without the use of the extra argument at the cost of more rules

• Instead ofnp(np(D,N)) --> det(D,Number),

common_noun(N,Number).

we could have written:np(np(D,N)) --> detsg(D), common_nounsg(N).np(np(D,N)) --> detpl(D), common_nounpl(N).detsg(det(a)) --> [a].detsg(det(the)) --> [the].detpl(det(the)) --> [the].common_nounsg(n(ball)) --> [ball].common_nounsg(n(man)) -->[man]. common_nounpl(n(men)) --> [men].

Page 10: LING/C SC/PSYC 438/538 Lecture 19 Sandiway Fong 1.

Extra Arguments: Agreement

• English exhibits subject-verb agreement

• Examples:– John kicked the ball– The men kicked the ball– John kicks the balls– The men *kicks/kick the

ballConstraint:

1. -s form of the verb is compatible with 3rd person singular only for the subject NP

2. uninflected form is not compatible with 3rd person singular for the subject NP

Page 11: LING/C SC/PSYC 438/538 Lecture 19 Sandiway Fong 1.

Subject Verb Agreement

• We need feature percolation:

eats*eat

Form EndingComment

eat uninflected not 3rd person singular

eats -s3rd person singular

ate -edpast

eaten -enpast participle

eating -inggerund

PersonNumber

Ending

Subject and VP come together at this rule

PersonNumber Ending

POS tags

Page 12: LING/C SC/PSYC 438/538 Lecture 19 Sandiway Fong 1.

Subject Verb Agreement

• Implementation: using POS tags

• Constraint table:– % table of Person Number Tag possible combinations– check(3,plural,vb).– check(3,plural,vbd).– check(3,singular,vbz).– check(3,singular,vbd).

Person, Numberfrom Subject NP

POS tagfrom verb

Page 13: LING/C SC/PSYC 438/538 Lecture 19 Sandiway Fong 1.

Topics

• Mechanisms:1. Extra argument for Prolog term representation

of a parse2. Extra arguments for feature value agreement3. Dealing with left recursive rules: grammar

transformation

Page 14: LING/C SC/PSYC 438/538 Lecture 19 Sandiway Fong 1.

Today’s Topic

Left recursive parses:• We know from an earlier lecture that left recursive

rules are a no-no given Prolog’s left-to-right depth-first computation rule…

• Example:1. s --> a, [!].2. a --> ba, [a]. 3. a --> a, [a].4. ba --> b, [a].5. b --> [b].

?- s([b,a,!],[]).ERROR: Out of local stack

s

a

a

a

a...

Page 15: LING/C SC/PSYC 438/538 Lecture 19 Sandiway Fong 1.

Preposition Phrase (PP) Attachment

• The preferred syntactic analysis is a left recursive parse

• Examples:– John saw the boy with a telescope – (structural ambiguity: automatically handled by Prolog)

possessive with instrument with

Page 16: LING/C SC/PSYC 438/538 Lecture 19 Sandiway Fong 1.

Preposition Phrase (PP) Attachment

• The preferred syntactic analysis is a left recursive parseCan “stack” PPs:– John saw the boy with a limp with Mary with a telescope – ambiguity: withpossessive , withaccompaniment, withinstrument

Page 17: LING/C SC/PSYC 438/538 Lecture 19 Sandiway Fong 1.

Preposition Phrase Attachment

• Linguistically: – PP (recursively) adjoins to NP or VP– np(np(NP,PP)) --> np(NP), pp(PP).– vp(vp(VP,PP)) --> vp(VP), pp(PP).

• Left recursion gives Prolog problems• Derivation (top-down, left-to-right):

1. vp2. vp pp3. vp pp pp4. vp pp pp pp5. vp pp pp pp pp infinite loop…

Page 18: LING/C SC/PSYC 438/538 Lecture 19 Sandiway Fong 1.

Transformation

• Apply the general transformation:

• to NP and VP rules:1. np(np(DT,NN)) --> dt(DT,Number), nn(NN,Number).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

Note:w is a newNon-terminalThat takes 2arguments

Page 19: LING/C SC/PSYC 438/538 Lecture 19 Sandiway Fong 1.

Transformed grammar