370 likes | 476 Views
LING 388: Language and Computers. Sandiway Fong Lecture 21: 11/8. Administrivia. Homework 3 graded and returned some email problems... Homework 4 out today usual rules. Last Time. Reached a course landmark we built a simple working translator out of a Japanese DCG and an English DCG
E N D
LING 388: Language and Computers Sandiway Fong Lecture 21: 11/8
Administrivia • Homework 3 • graded and returned • some email problems... • Homework 4 • out today • usual rules
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...
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).
English parse tree Japanese parse tree Japanese Grammar English Grammar Japanese sentence English sentence Translator Architecture • tree-to-tree mapping construction-based
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)
Translator Architecture • predicate-argument mapping p(A1,A2) construction independent particular-language parse tree independent English predicate-argument structure Japanese predicate-argument structure more advanced: language-independent interlingua Japanese Grammar English Grammar Japanese sentence English sentence
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).
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]. English Grammar: Modified
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)
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). sbar np s aux what np vp did v john buy • sbar(np(what),aux(did),s(np(john),vp(v(buy))))
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,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]. English Grammar: Modified
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
Translator Architecture • predicate-argument mapping p(A1,A2) construction independent particular-language parse tree independent English predicate-argument structure Japanese predicate-argument structure Japanese Grammar English Grammar Japanese sentence English sentence
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(A1,A2) • just have to translate terms p, A1 and A2 into the other language • Example: • John bought a book bought(john,book) • Taroo-ga hon-o katta katta(taroo,hon)
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).
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)).
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]).
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
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
Idioms 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). • 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].
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
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]. English Grammar: e20.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]. English Grammar: e20.pl
Japanese Grammar: j20.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
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).
Question 1: Translation • load all 3 files e21.pl, j21.pl and t.pl into the Prolog system • preliminary exercises (don’t submit): • verify both parsers works individually by running the following sentences: • John bought the books • Taroo-ga hon-o katta • verify the translator works by running • Taroo-ga hon-o katta • and see how many English translations are reported • run the translator in reverse
Question 1: Translation • Homework Question • using the debugger (trace) 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
Question 2: Tense • Homework Question • (A) English morphology and tense • (1) (1pt) • Why does • ?- translate(X,[taroo,ga,hon,o,katta]). • return duplicate answers? • (2) (2pts) • fix the problem • (3) (1pt) • *John buy the book (John buys the book) • are accepted by the English grammar • fix the problem • submit both your grammar and relevant examples
Question 2: Tense • Homework Question • (B) Tense and predicate-argument structure • let’s expand the grammar slightly • assume kau (buy(s)) is the present tense form of katta (bought) • (3pts) • Modify the translator to respect tenses when translating between • John buys a book taroo-ga hon-o kau • John bought a book taroo-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]).
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))
Question 3: Yes-No Questions • Homework Question • (A) (3pts) • modify the English and Japanese grammars to incorporate yes-no questions • (B) (2pts) • 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 kayesno(katta(taroo,hon))
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)
Question 5: Japanese Idiom • example • taroo-ga sensei-ni goma-o sutta • taroo-nom teacher-dat sesame-acc grinded • “John flattered the teacher” • taroo-ga Hanako-ni goma-o sutta • taroo-nom Hanako-dat sesame-acc grinded • “John flattered Mary” • ni = (dat) dative Case marker • odateta is the Japanese counterpart for flattered • Homework Question: • (6pts) • Implement the examples and the idiomatic translations • submit code and examples
Homework Summary • Question 1: Translation • 3 pts • Question 2: Tense • 7 pts • Question 3: Yes-No Questions • 5 pts • Question 4: English Idiom • 6 pts • Question 5: Japanese Idiom • 6 pts Total: 27 pts