ling 388 language and computers lecture 13 10/14/03 sandiway fong

24
LING 388 Language and Computers Lecture Lecture 13 13 10/14 10/14 /03 /03 Sandiway FONG Sandiway FONG

Post on 22-Dec-2015

218 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: LING 388 Language and Computers Lecture 13 10/14/03 Sandiway FONG

LING 388Language and Computers

Lecture Lecture 1313

10/1410/14/03/03

Sandiway FONGSandiway FONG

Page 2: LING 388 Language and Computers Lecture 13 10/14/03 Sandiway FONG

Administrivia

Next Class Next Class … … back in Franklin 210back in Franklin 210

Homework Assignment 3Homework Assignment 3 Exercises 1 and 2 last lectureExercises 1 and 2 last lecture Exercises 3, 4 and 5 todayExercises 3, 4 and 5 today Due date is next Tuesday Due date is next Tuesday

Submit all five exercises together to Charles Submit all five exercises together to Charles ([email protected]) ([email protected])

(Option) Along with extra credit question from (Option) Along with extra credit question from Lecture 11Lecture 11

Page 3: LING 388 Language and Computers Lecture 13 10/14/03 Sandiway FONG

Grammar From Exercises 1 and 2 …

Example grammar so far has been augmented with:Example grammar so far has been augmented with: Parse structureParse structure Determiner/Noun number agreementDeterminer/Noun number agreement

DCG rules:DCG rules: s(s(X,Y)) --> np(X), vp(Y).s(s(X,Y)) --> np(X), vp(Y). np(np(X,Y)) --> det(X,Num), common_noun(Y,Num).np(np(X,Y)) --> det(X,Num), common_noun(Y,Num). np(np(X)) --> proper_noun(X).np(np(X)) --> proper_noun(X). common_noun(n(man),sg) --> [man]. common_noun(n(men),sg) --> [men].common_noun(n(man),sg) --> [man]. common_noun(n(men),sg) --> [men]. proper_noun(john) --> [john].proper_noun(john) --> [john]. det(det(the),_) --> [the].det(det(the),_) --> [the]. det(det(a),sg) --> det(det(a),sg) -->

[a].[a]. vp(vp(X)) --> intransitive_verb(X).vp(vp(X)) --> intransitive_verb(X). vp(vp(X,Y)) --> transitive_verb(X), np(Y).vp(vp(X,Y)) --> transitive_verb(X), np(Y). intransitive_verb(v(ran)) --> [ran].intransitive_verb(v(ran)) --> [ran]. transitive_verb(v(saw)) --> transitive_verb(v(saw)) -->

[saw].[saw].

Page 4: LING 388 Language and Computers Lecture 13 10/14/03 Sandiway FONG

Exercise 3: Count and Mass Nouns

To parseTo parse:: John likes beerJohn likes beer

Note:Note:• beerbeer can be a mass noun and does not need a determiner can be a mass noun and does not need a determiner

We need a rule for mass nouns:We need a rule for mass nouns: np(np(X)) --> mass_noun(X).np(np(X)) --> mass_noun(X).

Note:Note:• beerbeer can also be a count noun can also be a count noun

Implement beer as both a count and mass nounImplement beer as both a count and mass noun Run Prolog Queries for:Run Prolog Queries for:

John likes a beerJohn likes a beer John likes beerJohn likes beer

Page 5: LING 388 Language and Computers Lecture 13 10/14/03 Sandiway FONG

Exercise 4: Logical Forms as Parses

Pseudo-Logical FormsPseudo-Logical Forms From Exercise 1 …From Exercise 1 …

We can see that we have a lot of freedom in deciding what We can see that we have a lot of freedom in deciding what gets returned as a parsegets returned as a parse

• kick the bucket => vp(v(die))kick the bucket => vp(v(die)) In the case of natural language quantifiers, we may wish to In the case of natural language quantifiers, we may wish to

construct corresponding pseudo-logical forms as parsesconstruct corresponding pseudo-logical forms as parses ExamplesExamples::

• Every man likes JohnEvery man likes John• forall forall xx, man(, man(xx), ), xx likes John likes John• Some men like beerSome men like beer• exists exists xx, man(, man(xx), ), xx likes beer likes beer

Page 6: LING 388 Language and Computers Lecture 13 10/14/03 Sandiway FONG

Exercise 4: Logical Forms as Parses

Homework QuestionHomework Question (A) Modify your grammar to incorporate the corresponding (A) Modify your grammar to incorporate the corresponding

pseudo-logical forms (pseudo-logical forms (existsexists and and forallforall) for quantifiers ) for quantifiers somesome and and everyevery

ExampleExample::• Every man likes JohnEvery man likes John• forall forall xx, man(, man(xx), ), xx likes John likes John

Instead of:Instead of:• s(np(q(every),n(man)),vp(v(likes),np(john)))s(np(q(every),n(man)),vp(v(likes),np(john)))

return:return:• s(s(forall(X,man(X)),forall(X,man(X)),vp(v(likes),np(john))))vp(v(likes),np(john))))

NoteNote: : Ignoring Quantifier Raising (QR) for this exercise …Ignoring Quantifier Raising (QR) for this exercise …

Page 7: LING 388 Language and Computers Lecture 13 10/14/03 Sandiway FONG

Exercise 4: Logical Forms as Parses

Homework Question (A) contd.Homework Question (A) contd. Your parser should also handle:Your parser should also handle:

Some men like beerSome men like beer exists exists xx, man(, man(xx), ), xx likes beer likes beer

Want to be able to substitute the fragment:Want to be able to substitute the fragment:• … … exists(X,men(X)) …exists(X,men(X)) …

for for • … … np(q(some),n(men)) …np(q(some),n(men)) …

givinggiving• s(s(exists(X,men(X)),exists(X,men(X)),vp(v(like),np(n(beer))))vp(v(like),np(n(beer))))

Page 8: LING 388 Language and Computers Lecture 13 10/14/03 Sandiway FONG

Exercise 4: Logical Forms as Parses

Homework Question (A) contd.Homework Question (A) contd. Every manEvery man can be parsed using rules: can be parsed using rules:

np(np(Y,Z)) --> quantifier(Y), common_noun(Z).np(np(Y,Z)) --> quantifier(Y), common_noun(Z). quantifier(q(every)) --> [every].quantifier(q(every)) --> [every].

Problem Reduces ToProblem Reduces To: : How to synthesize forall(M,man(M)) instead of np(Y,Z) ?How to synthesize forall(M,man(M)) instead of np(Y,Z) ?

Don’t want to write:Don’t want to write: np(forall(M,np(forall(M,manman(M))) --> quantifier(Y), common_noun(Z).(M))) --> quantifier(Y), common_noun(Z).

… … common noun may not be common noun may not be n(man)n(man) Can’t write the rule:Can’t write the rule:

np(forall(M,np(forall(M,ZZ(M))) --> quantifier(Y), common_noun(Z).(M))) --> quantifier(Y), common_noun(Z).… … because functors can’t be variables in Prologbecause functors can’t be variables in Prolog

Page 9: LING 388 Language and Computers Lecture 13 10/14/03 Sandiway FONG

Exercise 4: Logical Forms as Parses

What can we do?What can we do? To solve this …To solve this …

Need the ability to construct a structure Need the ability to construct a structure pp((XX) (e.g. ) (e.g. man(X)man(X)) ) taking one argument taking one argument XX and and pp (man) as its functor given a (man) as its functor given a simple name simple name pp (e.g. (e.g. manman))

ExampleExample:: man => man(X)man => man(X) np(q(every),n(np(q(every),n(manman)) => forall(X,)) => forall(X,manman(X))(X))

… … we’re going to need the Prolog built-inwe’re going to need the Prolog built-in =.. =.. known as “univ” known as “univ”

Page 10: LING 388 Language and Computers Lecture 13 10/14/03 Sandiway FONG

Univ (=..)

The Prolog built-in predicate =.. The Prolog built-in predicate =.. =.. is known as the =.. is known as the univuniv predicate predicate =.. is an infix predicate that takes two arguments=.. is an infix predicate that takes two arguments X =.. YX =.. Y

X is a structure (or name)X is a structure (or name) Y is a listY is a list

• 1st element of Y is the functor of X1st element of Y is the functor of X• Remaining elements of Y are the arguments of XRemaining elements of Y are the arguments of X

=.. is bi-directional=.. is bi-directional i.e. either X or Y (not both) can be variablesi.e. either X or Y (not both) can be variables

Page 11: LING 388 Language and Computers Lecture 13 10/14/03 Sandiway FONG

Univ (=..)

ExamplesExamples:: ?- man(X) =.. [man,X].?- man(X) =.. [man,X]. ?- the =.. [the].?- the =.. [the]. ? - s(np(john),vp(v(ran))) =.. [s,np(john),vp(v(ran))].? - s(np(john),vp(v(ran))) =.. [s,np(john),vp(v(ran))].

NoteNote:: =.. “unpacks” a structure only one level down=.. “unpacks” a structure only one level down

?- vp(v(ran)) =.. X. ?- vp(v(ran)) =.. X. X = [vp,v(ran)]X = [vp,v(ran)] ?- X =.. [the,man].?- X =.. [the,man]. X = the(man)X = the(man) ?- X =.. Y?- X =.. Y is an erroris an error

Page 12: LING 388 Language and Computers Lecture 13 10/14/03 Sandiway FONG

Exercise 4: Logical Forms as Parses

Summarizing…Summarizing… Modify rule for NP -> Quantifier, N Modify rule for NP -> Quantifier, N

Use =.. to construct the quantified expressionUse =.. to construct the quantified expression

Your modified grammar should produce the following parses:Your modified grammar should produce the following parses: Every man likes JohnEvery man likes John

s(s(forall(X,man(X)),forall(X,man(X)),vp(v(likes),np(john))))vp(v(likes),np(john)))) Some men like beerSome men like beer

s(s(exists(X,men(X)),exists(X,men(X)),vp(v(like),np(n(beer))))vp(v(like),np(n(beer)))) It should rejectIt should reject

*Every man like John/*Every men likes John/*Every men like John*Every man like John/*Every men likes John/*Every men like John *Some men likes beer/*Some man like beer/*Some man likes beer*Some men likes beer/*Some man like beer/*Some man likes beer

Page 13: LING 388 Language and Computers Lecture 13 10/14/03 Sandiway FONG

Exercise 4: Logical Forms as Parses

Homework Question (A) contd.Homework Question (A) contd. HintHint::

Use { … } to insert a call to =..Use { … } to insert a call to =.. NoteNote::

We have seen We have seen { … }{ … } before before

• Recall Lecture 10Recall Lecture 10– s --> [a],t(1),[c].s --> [a],t(1),[c].

– t(N) --> [a],{M is N+1},t(M),[c].t(N) --> [a],{M is N+1},t(M),[c].

– t(N) --> u(N).t(N) --> u(N).

– u(N) --> [b],{M is N-1},u(M).u(N) --> [b],{M is N-1},u(M).

– u(1) --> [b].u(1) --> [b].

Page 14: LING 388 Language and Computers Lecture 13 10/14/03 Sandiway FONG

Exercise 4: Logical Forms as Parses

Homework Question (B) Homework Question (B) Generic interpretation for bare pluralsGeneric interpretation for bare plurals

ExampleExample::• The men drink beerThe men drink beer• Men drink beerMen drink beer• forall forall xx, men(, men(xx), ), xx drink beer drink beer

… … as a first approximationas a first approximation

Write a DCG rule for interpreting bare plurals Write a DCG rule for interpreting bare plurals as universally quantified nounsas universally quantified nouns

Page 15: LING 388 Language and Computers Lecture 13 10/14/03 Sandiway FONG

Exercise 4: Logical Forms as Parses

Homework Question (B) contd.Homework Question (B) contd. Make sure your grammar produces:Make sure your grammar produces:

• s(forall(X,men(X)),vp(v(drink),np(n(beer))))s(forall(X,men(X)),vp(v(drink),np(n(beer))))

for the Prolog query:for the Prolog query:• ?- s(X,[men,drink,beer],[]).?- s(X,[men,drink,beer],[]).

Page 16: LING 388 Language and Computers Lecture 13 10/14/03 Sandiway FONG

Exercise 5: More Agreement

Exercise 2 (last time):Exercise 2 (last time): … … showed how to enforce agreement between two showed how to enforce agreement between two

constituents in a single DCG rule:constituents in a single DCG rule: np(np(X,Y)) --> det(X,np(np(X,Y)) --> det(X,NumNum), common_noun(Y,), common_noun(Y,NumNum).).

Solution depends on fact:Solution depends on fact: Scope of Prolog variable Scope of Prolog variable NumNum is the entire clause is the entire clause

np

X[Num] Y[Num]

Page 17: LING 388 Language and Computers Lecture 13 10/14/03 Sandiway FONG

Exercise 5: More Agreement

QuestionQuestion: : What do when we want to apply agreement when What do when we want to apply agreement when

constituents are not from a single DCG rule?constituents are not from a single DCG rule? ExampleExample::

Subject-Verb agreementSubject-Verb agreement John likes the man/*John like the manJohn likes the man/*John like the man I like the man/*I likes the manI like the man/*I likes the man Every man likes John/ *every man like JohnEvery man likes John/ *every man like John Some men like beer/*some men likes beerSome men like beer/*some men likes beer

Subject and verb need to agree in person and number featuresSubject and verb need to agree in person and number features

Page 18: LING 388 Language and Computers Lecture 13 10/14/03 Sandiway FONG

Exercise 5: More Agreement

But subject-verb agreement can’t be localized in a single But subject-verb agreement can’t be localized in a single

DCG ruleDCG rule Example Parse:Example Parse:

s

np vp

v np

det n

the man

likes[3,sg]

John [3,sg]

Page 19: LING 388 Language and Computers Lecture 13 10/14/03 Sandiway FONG

Exercise 5: More Agreement

Lexicon:Lexicon: proper_noun(john) --> [john].proper_noun(john) --> [john].

transitive_verb(v(likes)) --> [likes].transitive_verb(v(likes)) --> [likes]. Affected phrase structure rules:Affected phrase structure rules:

s(s(X,Y)) --> np(X), vp(Y).s(s(X,Y)) --> np(X), vp(Y). vp(vp(X)) --> intransitive_verb(X).vp(vp(X)) --> intransitive_verb(X). vp(vp(X,Y)) --> transitive_verb(X), np(Y).vp(vp(X,Y)) --> transitive_verb(X), np(Y).

Page 20: LING 388 Language and Computers Lecture 13 10/14/03 Sandiway FONG

Exercise 5: More Agreement Basic IdeaBasic Idea: :

Pass relevant agreement features as variables through intermediate Pass relevant agreement features as variables through intermediate nodesnodes

s

np vp

v np

det n

the man

likes[3,sg]

John [3,sg]

Page 21: LING 388 Language and Computers Lecture 13 10/14/03 Sandiway FONG

Exercise 5: More Agreement Modify existing DCG rules to include variables and values for Modify existing DCG rules to include variables and values for

agreement features person and number agreement features person and number Step 1: Add features to lexical rules:Step 1: Add features to lexical rules:

proper_noun(john,proper_noun(john,33,,sgsg) --> [john].) --> [john]. transitive_verb(v(likes),transitive_verb(v(likes),33,,sgsg) --> [likes].) --> [likes].

QuestionQuestion:: What to do with P and N forWhat to do with P and N for

transitive_verb(v(like),transitive_verb(v(like),PP,,NN) --> [like].) --> [like]. LikeLike agrees with anything that’s not 3rd person singular agrees with anything that’s not 3rd person singular

… … ignoring tense in this exerciseignoring tense in this exercise SolutionSolution::

Recall we can call Prolog code from within DCG rules …Recall we can call Prolog code from within DCG rules … transitive_verb(v(like),transitive_verb(v(like),PP,,NN) --> [like], { \+ ( ) --> [like], { \+ ( PP=3, =3, NN=sg) }.=sg) }.… … this only works if P and N are valued before tests are executedthis only works if P and N are valued before tests are executed

Page 22: LING 388 Language and Computers Lecture 13 10/14/03 Sandiway FONG

Exercise 5: More Agreement Prolog Parse Order (In-Order Tree Traversal)Prolog Parse Order (In-Order Tree Traversal): :

Subject NP is parsed before VPSubject NP is parsed before VP=> P and N are valued before unifying with V=> P and N are valued before unifying with V

s

np vp

v np

det n

the man

likes[3,sg]

John [3,sg]

1

2

3

4

5

Page 23: LING 388 Language and Computers Lecture 13 10/14/03 Sandiway FONG

Exercise 5: More Agreement

Step 2: Pass person and number features through Step 2: Pass person and number features through intermediate nodesintermediate nodes ““Local” constituents:Local” constituents:

s(s(X,Y)) --> np(X,s(s(X,Y)) --> np(X,PP,,NN), vp(Y,), vp(Y,PP,,NN).). Intermediate nodes:Intermediate nodes:

vp(vp(X),vp(vp(X),PP,,NN) --> intransitive_verb(X,) --> intransitive_verb(X,PP,,NN).). vp(vp(X,Y),vp(vp(X,Y),PP,,NN) --> transitive_verb(X,) --> transitive_verb(X,PP,,NN), np(Y,_,_).), np(Y,_,_).

NoteNote:: All np rules need to be revised to take both P and N featuresAll np rules need to be revised to take both P and N features

Page 24: LING 388 Language and Computers Lecture 13 10/14/03 Sandiway FONG

Exercise 5: More Agreement

Homework Question:Homework Question: Revise the DCG rules to accept the examples Revise the DCG rules to accept the examples

listed at the start of the exercise:listed at the start of the exercise: John likes the man/*John like the manJohn likes the man/*John like the man I like the man/*I likes the manI like the man/*I likes the man Every man likes John/ *every man like JohnEvery man likes John/ *every man like John Some men like beer/*some men likes beerSome men like beer/*some men likes beer

Note:Note: You’ll need to write DCG rules for pronounsYou’ll need to write DCG rules for pronouns