Presentation is loading. Please wait.

Presentation is loading. Please wait.

LING 388: Language and Computers Sandiway Fong Lecture 26: 11/28.

Similar presentations


Presentation on theme: "LING 388: Language and Computers Sandiway Fong Lecture 26: 11/28."— Presentation transcript:

1 LING 388: Language and Computers Sandiway Fong Lecture 26: 11/28

2 2 Administrivia Last Homework out today –due next Tuesday –extra credit question No Computer Lab Class on Thursday –Lab is not available –Homework help is available –bring in your laptop

3 3 Last Time Reached a course landmark –we built a simple working translator out of –a Japanese DCG and –an English DCG possible because –both DCGs were bidirectional – we didn’t have to write both a generator and a parser for each language let’s review what we did...

4 4 Last Time Tree-to-Tree Mapping –Object wh-Question: What did John buy sbar(np(what),aux(did),s(np(john),vp(v(buy)))) taroo-ga nani-o katta ka s(np(taroo),vp(np(nani),v(katta))) –Added a rule for maptree/2 maptree(sbar(O,_,s(S,vp(V))),s(SJ,vp(OJ,VJ))) :- –je(SJ,S), –je(VJ,V), –je(OJ,O).

5 5 Translator Architecture tree-to-tree mapping Japanese Grammar Japanese parse tree Japanese sentence English Grammar English parse tree English sentence construction-based

6 6 Last Time Predicate-argument –much more simple mapping –also the correspondence dictionary will be more simple too Example 1 (Declarative case): –John bought a book bought(john,book) –Taroo-ga hon-o katta katta(taroo,hon) Example 2 (Subject wh-Question): –Who bought a book bought(who,book) –dare-ga hon-o katta ka katta(dare,hon) Example 3 (Object wh-Question): –What did John buy bought(john,what) –taroo-ga nani-o katta ka katta(taroo,nani)

7 7 Translator Architecture predicate-argument mapping Japanese Grammar Japanese predicate- argument structure Japanese sentence English Grammar English predicate- argument structure English sentence construction independent particular-language parse tree independent p(A 1,A 2 ) more advanced: language-independent interlingua

8 8 Last Time Predicate-Argument Structure Mapping –Modified DCG rules (Japanese Grammar): s(PA) --> np(Y,Q1), nomcase, vp(Z,Q2), sf(Q1,Q2), { predarg(Y,Z,2,PA)}. vp(vp(Z,Y),Q) --> np(Z,Q), acccase, transitive(Y). transitive(v(katta)) --> [katta]. nomcase --> [ga]. acccase --> [o]. np(np(taroo),notwh) --> [taroo]. np(np(hon),notwh) --> [hon]. np(np(dare),wh) --> [dare]. np(np(nani),wh) --> [nani]. sf(wh,notwh) --> [ka]. sf(notwh,wh) --> [ka]. sf(notwh,notwh) --> []. sf(wh,wh) --> [ka]. predarg(X,Y,Order,PA) :- headof(X,S), headof(Y,P), order(Order,Y,NP), headof(NP,O), PA =.. [P,S,O]. order(1,vp(_,NP),NP). order(2,vp(NP,_),NP). headof(np(_,n(N)),N). headof(vp(v(V),_),V). headof(vp(_,v(V)),V). headof(vp(v(V)),V). headof(np(N),N).

9 9 English Grammar: Modified DCG rules: sbar(sbar(X,A,Y)) --> np(X,wh), do(A), s_objectwh(Y). sbar(S) --> s(S). s_objectwh(s(Y,Z)) --> np(Y,_), vp_objectwh(Z). s(PA) --> np(Y,_),vp(Z),{predarg(Y,Z,1,PA). np(np(Y),Q) --> pronoun(Y,Q). np(np(Y),notwh) --> proper_noun(Y). np(np(D,N),Q) --> det(D,Number), common_noun(N,Number,Q). det(det(the),_) --> [the]. det(det(a),sg) --> [a]. common_noun(n(ball),sg,notwh) --> [ball]. common_noun(n(man),sg,notwh) --> [man]. common_noun(n(men),pl,notwh) --> [men]. common_noun(n(book),sg,notwh) --> [book]. pronoun(who,wh) --> [who]. pronoun(what,wh) --> [what]. pronoun(i,notwh) --> [i]. pronoun(we,notwh) --> [we]. pronoun(me,notwh) --> [me]. proper_noun(john) --> [john]. vp(vp(Y)) --> unergative(Y). vp(vp(Y,Z)) --> transitive(Y,_), np(Z,_). vp(vp(A,V)) --> aux(A), transitive(V,en). vp_objectwh(vp(Y)) --> transitive(Y,root). unergative(v(ran)) --> [ran]. transitive(v(hit),_) --> [hit]. transitive(v(eat),root) --> [eat]. transitive(v(eats),s) --> [eats]. transitive(v(ate),ed) --> [ate]. transitive(v(eaten),en) --> [eaten]. transitive(v(buy),root) --> [buy]. transitive(v(bought),ed) --> [bought]. aux(aux(was)) --> [was]. do(aux(did)) --> [did]. do(aux(does)) --> [does]. do(aux(do)) --> [do].

10 10 Mapping: Predicate-Argument Structure Task 2: –Modify the English grammar to also generate predicate argument structure Modified English DCG Rule: –s(PA) --> np(X), vp(Y), { predarg(X,Y,1,PA)}. Applies to: John bought a book bought(john,book) Who bought a book bought(who,book)

11 11 Mapping: Predicate-Argument Structure Task 2: –Modify the English grammar to also generate predicate argument structure Example 3 (Object wh-Question): –What did John buy buy(john,what) Modified SBar rules: –sbar(PA) --> np(X,wh), do(A), s_objectwh(Y,S,P), {headof(X,O),PA =.. [P,S,O]}. –s_objectwh(s(Y,Z),S,P) --> np(Y,_), vp_objectwh(Z), {headof(Y,S),headof(Z,P)}. –vp_objectwh(vp(Y)) --> transitive(Y,root). s npvp v sbar np buy john aux did what sbar(np(what),aux(did),s(np(john),vp(v(buy))))

12 12 English Grammar: Modified DCG rules: sbar(PA) --> np(X,wh), do(A), s_objectwh(_,S,P), {headof(X,O), PA =.. [P,S,O]}. sbar(S) --> s(S). s_objectwh(s(Y,Z),S,P) --> np(Y,_), vp_objectwh(Z), {headof(Y,S),headof(Z,P)}. s(PA) --> np(Y,_),vp(Z),{predarg(Y,Z,1,P)}. np(np(Y),Q) --> pronoun(Y,Q). np(np(Y),notwh) --> proper_noun(Y). np(np(D,N),Q) --> det(D,Number), common_noun(N,Number,Q). det(det(the),_) --> [the]. det(det(a),sg) --> [a]. common_noun(n(ball),sg,notwh) --> [ball]. common_noun(n(man),sg,notwh) --> [man]. common_noun(n(men),pl,notwh) --> [men]. common_noun(n(book),sg,notwh) --> [book]. pronoun(who,wh) --> [who]. pronoun(what,wh) --> [what]. pronoun(i,notwh) --> [i]. pronoun(we,notwh) --> [we]. pronoun(me,notwh) --> [me]. proper_noun(john) --> [john]. vp(vp(Y)) --> unergative(Y). vp(vp(Y,Z)) --> transitive(Y,_), np(Z,_). vp(vp(A,V)) --> aux(A), transitive(V,en). vp_objectwh(vp(Y)) --> transitive(Y,root). unergative(v(ran)) --> [ran]. transitive(v(hit),_) --> [hit]. transitive(v(eat),root) --> [eat]. transitive(v(eats),s) --> [eats]. transitive(v(ate),ed) --> [ate]. transitive(v(eaten),en) --> [eaten]. transitive(v(buy),root) --> [buy]. transitive(v(bought),ed) --> [bought]. aux(aux(was)) --> [was]. do(aux(did)) --> [did]. do(aux(does)) --> [does]. do(aux(do)) --> [do].

13 13 Mapping: Predicate-Argument Structure queries –?- sbar(X,[what,did,john,buy],[]). –X = buy(john,what) –?- sbar(X,[who,bought,a,book],[]). –X = bought(who,book) –?- sbar(X,[who,bought,what],[]). –X = bought(who,what) –uniform structures

14 14 Translator Architecture predicate-argument mapping Japanese Grammar Japanese predicate- argument structure Japanese sentence English Grammar English predicate- argument structure English sentence construction independent particular-language parse tree independent p(A 1,A 2 )

15 15 Translation Translation code: –translate(E,J) :- – sbar(X,E,[]), % English grammar – mapPA(X,Xp), % Map predicate-argument – js(Xp,J,[]). % Japanese grammar mapPA/2 replaces maptree/2 –easier to write –general form: p(A 1,A 2 ) –just have to translate terms p, A 1 and A 2 into the other language Example: –John bought a book bought(john,book) –Taroo-ga hon-o katta katta(taroo,hon)

16 16 Translation example –John bought a book bought(john,book) –Taroo-ga hon-o katta katta(taroo,hon) mapPA/2 –mapPA(E,J) :- E =.. [P,S,O], je(PJ,P), je(SJ,S), je(OJ,O), J =.. [PJ,SJ,OJ]. Bilingual Dictionary (Word Correspondences) –je(katta,bought). –je(hon,book). –je(taroo,john). –je(dare,who). –je(nani,what). –je(katta,buy).

17 17 Translation example –John bought a book bought(john,book) –Taroo-ga hon-o katta katta(taroo,hon) mapPA/2 –mapPA(E,J) :- E = bought(john,book) – E =.. [P,S,O], P = bought, S = john, O = book – je(PJ,P), PJ = katta – je(SJ,S), SJ = taroo – je(OJ,O), OJ = hon – J =.. [PJ,SJ,OJ]. J = katta(taroo,hon) Bilingual Dictionary (Word Correspondences) –je(katta,bought). –je(hon,book). –je(taroo,john). –je(dare,who). –je(nani,what). –je(katta,buy). Tree-to-tree mapping dictionary je(v(katta), v(bought)). je(np(hon), np(_,n(book))). je(np(taroo),np(john)). je(np(dare), np(who)). je(np(nani), np(what)).

18 18 Translation translation code –translate(E,J) :- – sbar(X,E,[]), % English grammar – mapPA(X,Xp), % Map predicate-argument – js(Xp,J,[]). % Japanese grammar example –John bought a book bought(john,book) –Taroo-ga hon-o katta katta(taroo,hon) computation –?- translate([john,bought,a,book],J). ?- sbar(X,[john,bought,a,book],[]).% English grammar ?- sbar(bought(john,book),[john,bought,a,book],[]). ?- mapPA(bought(john,book),Xp). % Map predicate-argument ?- mapPA(bought(john,book),katta(taroo,hon)). ?- js(katta(taroo,hon),J,[]). % Japanese grammar ?- js(katta(taroo,hon),[taroo,ga,hon,o,katta],[]). –?- translate([john,bought,a,book], [taroo,ga,hon,o,katta]).

19 19 Homework 7

20 20 Files filedescriptionalso contains e.pl English DCG j.pl Japanese DCGpredicate-argument code t.pl Translator/mappingbilingual dictionary

21 21 English Grammar: e.pl DCG rules sbar(PA) --> np(X,wh), do(_,_), s_objectwh(_,S,P), {headof(X,O), PA =..[P,S,O]}. sbar(S) --> s(S). s_objectwh(s(Y,Z),S,P) --> np(Y,_), vp_objectwh(Z), {headof(Y,S),headof(Z,P)}. s(PA) --> np(Y,_), vp(Z,_), {predarg(Y,Z,1,PA)}. np(np(Y),Q) --> pronoun(Y,Q). np(np(Y),notwh) --> proper_noun(Y). np(np(D,N),Q) --> det(D,Number), common_noun(N,Number,Q). vp(vp(v(died)),ed) --> [kicked,the,bucket]. vp(vp(Y,Z),F) --> transitive(Y,F), np(Z,_). vp(vp(A,V),F) --> aux(A,F), transitive(V,en). vp_objectwh(vp(Y)) --> transitive(Y,root). det(det(the),_) --> [the]. det(det(a),sg) --> [a]. common_noun(n(bucket),sg,notwh) --> [bucket]. common_noun(n(buckets),pl,notwh ) --> [buckets]. common_noun(n(apple),sg,notwh) --> [apple]. common_noun(n(apples),pl,notwh) --> [apples]. common_noun(n(man),sg,notwh) -- > [man]. common_noun(n(book),sg,notwh) - -> [book]. common_noun(n(books),pl,notwh) --> [books].

22 22 English Grammar: e.pl pronoun(who,wh) --> [who]. pronoun(what,wh) --> [what]. proper_noun(john) --> [john]. transitive(v(eats),s) --> [eats]. transitive(v(ate),ed) --> [ate]. transitive(v(eaten),en) --> [eaten]. transitive(v(buy),root) --> [buy]. transitive(v(buys),s) --> [buys]. transitive(v(bought),ed) --> [bought]. transitive(v(bought),en) --> [bought]. transitive(v(kicks),s) --> [kicks]. transitive(v(kicked),ed) --> [kicked]. transitive(v(kicked),en) --> [kicked]. aux(aux(was),ed) --> [was]. aux(aux(is),s) --> [is]. do(aux(does),s) --> [does]. do(aux(did),ed) --> [did].

23 23 Japanese Grammar: j.pl DCG Rules s(PA) --> np(Y,Q1), nomcase, vp(Z,Q2), sf(Q1,Q2), {predarg(Y,Z,2,PA)}. vp(vp(Z,Y),Q) --> np(Z,Q), acccase, transitive(Y). transitive(v(katta)) --> [katta]. nomcase --> [ga]. acccase --> [o]. np(np(taroo),notwh) --> [taroo]. np(np(hon),notwh) --> [hon]. np(np(dare),wh) --> [dare]. np(np(nani),wh) --> [nani]. sf(wh,notwh) --> [ka]. sf(notwh,wh) --> [ka]. sf(notwh,notwh) --> []. sf(wh,wh) --> [ka]. predarg(X,Y,Order,PA) :- headof(X,S), headof(Y,P), order(Order,Y,NP), headof(NP,O), PA =.. [P,S,O]. predarg(X,Y,_,PA) :- headof(X,S), headof(Y,P), Y = vp(_), PA =.. [P,S]. order(1,vp(_,NP),NP). order(2,vp(NP,_),NP). headof(np(_,n(N)),N). headof(vp(v(V),_),V). headof(vp(_,v(V)),V). headof(vp(v(V)),V). headof(np(N),N). bilingual predicate-argument structure code stored in j21.pl but used by both grammars

24 24 Translator: t.pl Prolog translation code –translate(E,J) :-% Translator – sbar(X,E,[]), % English grammar – mapPA(X,Xp), – js(Xp,J,[]). % Japanese grammar –mapPA(E,J) :- % Map predicate-argument E =.. [P,S,O], je(PJ,P), je(SJ,S), je(OJ,O), J =.. [PJ,SJ,OJ]. –je(katta,bought).% Bilingual dictionary –je(hon,book). –je(taroo,john). –je(dare,who). –je(nani,what). –je(katta,buy).

25 25 Exercise 0: Translation load all 3 files e.pl, j.pl and t.pl into the Prolog system preliminary exercise (don’t submit): 1.verify both parsers works individually by running the following sentences: –John bought the books –Taroo-ga hon-o katta 2.verify the translator works by running –Taroo-ga hon-o katta –and see how many English translations are reported 3.run the translator in reverse

26 26 Question 1: Translation Homework Question –using the debugger ( ?- spy(sbar). ) for the Japanese example: taroo-ga hon-o katta (A) (1pt) –How many English sentences are explored by the translator before a compatible sentence is found? (B) (2pts) –How would you rewrite translate/2 to avoid this inefficiency for the Japanese ➙ English direction –submit your definition of translate/2

27 27 Question 2: Tense Homework Question –Tense and predicate-argument structure –let’s expand the grammar slightly –assume kau (buy(s)) is the present tense form of katta (bought) –(5pts) –Modify the translator to respect tenses when translating between John buys a booktaroo-ga hon-o kau John bought a booktaroo-ga hon-o katta –submit both your code and all relevant translations, e.g. ?- translate([john,buys,a,book],X). ?- translate(X,[taroo,ga,hon,o,kau]).

28 28 Question 3: Yes-No Questions example: –Did John buy the books? –auxiliary do preceding subject signals the yes-no question assume predicate-argument structure: –yesno(buy(john,books)) example (Japanese): –Taroo-ga hon-o katta ka –ka = question particle predicate-argument structure: –yesno(katta(taroo,hon))

29 29 Question 3: Yes-No Questions Homework Question –(A) (8pts) –modify the English and Japanese grammars to incorporate yes-no questions –modify the translator to operate on yes-no questions –submit your code and examples using: Did John buy a book? yesno(buy(john,book)) Taroo-ga hon-o katta ka yesno(katta(taroo,hon))

30 30 Idioms idioms –non-composition meaning i.e. meaning of idiom cannot be inferred from the meaning of the constitutive words examples –John kicked the bucket VP “kicked the bucket” –has a literal interpretation –has an idiomatic interpretation “John died” –Pete gave me the cold shoulder VP “give X the cold shoulder” –has an (unlikely) literal interpretation –has a (more likely) idiomatic interpretation “be unfriendly towards X” –(French) cassé sa pipe –(literal) break his pipe –(idiomatic) died

31 31 Idioms examples –John kicked the bucket VP “kicked the bucket” –has a literal interpretation –has an idiomatic interpretation “John died” –John kicked the buckets VP “kicked the buckets” –has only a literal interpretation English grammar modifications: –verb: kicked –transitive(v(kicked),ed) --> [kicked]. –transitive(v(kicked),en) --> [kicked]. –common noun: bucket(s) –common_noun(n(bucket),sg,notwh) --> [bucket]. –common_noun(n(buckets),pl,notwh) --> [buckets]. queries –?- sbar(X,[john,kicked,the,bucket],[]). –X = kicked(john,bucket) –?- sbar(X,[john,kicked,the,buckets ],[]). –X = kicked(john,buckets) –Literal meanings only

32 32 Idioms examples –John kicked the bucket VP “kicked the bucket” –has a literal interpretation –has an idiomatic interpretation “John died” –John kicked the buckets VP “kicked the buckets” –has only a literal interpretation idiomatic interpretation –Verb Phrase: kicked the bucket –vp(vp(v(died))) --> [kicked,the,bucket]. Predicate-Argument structure (intransitive verbs) –predarg(X,Y,_,PA) :- – headof(X,S), – headof(Y,P), – Y = vp(_), – PA =.. [P,S]. predarg(X,Y,Order,PA) :- headof(X,S), headof(Y,P), order(Order,Y,NP), headof(NP,O), PA =.. [P,S,O]. order(1,vp(_,NP),NP). order(2,vp(NP,_),NP). headof(np(_,n(N)),N). headof(vp(v(V),_),V). headof(vp(_,v(V)),V). headof(vp(v(V)),V). headof(np(N),N).

33 33 Idioms example –John kicked the bucket VP “kicked the bucket” –has a literal interpretation –has an idiomatic interpretation “John died” –John kicked the buckets VP “kicked the buckets” –has only a literal interpretation queries –?- sbar(X,[john,kicked,the,bucket],[]). –X = died(john) ? ; –X = kicked(john,bucket) ? ; –?- sbar(X,[john,kicked,the,buckets],[]). –X = kicked(john,buckets) ? ; –no

34 34 Question 4: English Idiom example –John kicked the bucket the VP “kicked the bucket” has a literal interpretation and an idiomatic interpretation “John died” vp(vp(v(died))) --> [kicked,the,bucket]. (6pts) Complete the translator so that –John kicked the bucket has both a literal and an idiomatic translation Taroo-ga buketsu-o ketta Taroo-ga shinda buketsu = bucket shinda = died ketta = kicked –John kicked the buckets has only a literal translation Taroo-ga buketsu-o ketta (assuming Japanese does not distinguish number)

35 35 Question 5: Japanese Idiom extra credit question example –taroo-ga saji-o nageta –taroo-nom spoon-acc threw –“John threw the spoon” (literal) –“John gave up” (idiomatic) Homework Question: –(8pts) –Implement the example and the idiomatic and the literal translations –submit code and examples


Download ppt "LING 388: Language and Computers Sandiway Fong Lecture 26: 11/28."

Similar presentations


Ads by Google