1 / 21

LING 388: Language and Computers

LING 388: Language and Computers. Sandiway Fong Lecture 17: 10/25. Administrivia. Heads-up : there may be a computer lab scheduled for next Wednesday I’ll keep you posted . sbar. np. s[ objectwh ]. aux. what. np. did. vp [ objectwh ]. v. john. buy. Last Time.

bryson
Télécharger la présentation

LING 388: Language and Computers

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. LING 388: Language and Computers Sandiway Fong Lecture 17: 10/25

  2. Administrivia • Heads-up: • there may be a computer lab scheduled for next Wednesday • I’ll keep you posted ...

  3. sbar np s[objectwh] aux what np did vp [objectwh] v john buy Last Time • English wh-questions • subject wh-questions: simple • object wh-questions: complex • wh-word fronting • do-support • tense goes with do • Technology employed • extra argument • nonterminal renaming

  4. Today’s Topic • Components: • English Grammar • Japanese Grammar • Putting it all together... • Machine Translation (MT)

  5. Japanese: Data • Declarative • Taroo-ga hon-o katta • John a book bought • ga = nominative case marker • o = accusative case marker • Wh-questions • Taroo-ga nani-o katta ka • nani: means what • ka: sentence-final question particle • dare-ga hon-o katta ka • dare: means who

  6. Japanese: Grammar • DCG rules: • s(s(Y,Z)) --> np(Y,Q1), nomcase, vp(Z,Q2), sf(Q1,Q2). • 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]. can both parse and generate with this simple grammar

  7. Japanese: Grammar • DCG rules: • js(s(Y,Z)) --> jnp(Y,Q1), nomcase, jvp(Z,Q2), sf(Q1,Q2). • jvp(vp(Z,Y),Q) --> jnp(Z,Q), acccase, jtransitive(Y). • jtransitive(v(katta)) --> [katta]. • nomcase --> [ga]. • acccase --> [o]. • jnp(np(taroo),notwh) --> [taroo]. • jnp(np(hon),notwh) --> [hon]. • jnp(np(dare),wh) --> [dare]. • jnp(np(nani),wh) --> [nani]. • sf(wh,notwh) --> [ka]. • sf(notwh,wh) --> [ka]. • sf(notwh,notwh) --> []. • sf(wh,wh) --> [ka]. rename Japanese nonterminals to not clash with English grammar – we’re going to be loading them both at the same time

  8. English: Data • Declarative: • John bought a book • Wh-Questions: • Who bought a book? (subject wh-phrase) • *John bought what? (only possible as an echo-question) • What did John buy? (object wh-phrase)

  9. 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(s(Y,Z)) --> np(Y,_), vp(Z). 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

  10. English: Grammar • We can also generate with this grammar • like with the Japanese grammar • Examples: • ?- sbar(s(np(john),vp(v(bought),np(det(a),n(book)))),Y,[]). • Y = [john,bought,a,book] • ?- sbar(sbar(np(what),aux(did),s(np(john),vp(v(buy)))),Y,[]). • Y = [what,did,john,buy] • ?- sbar(s(np(who),vp(v(bought),np(det(a),n(book)))),Y,[]). • Y = [who,bought,a,book]

  11. Example 1 • Declarative Example: • John bought a book • Taroo-ga hon-o katta • Word Correspondences: • katta = bought • hon = book • Taroo John • ga = nominative case marker • o = accusative case marker • Database facts: • je(katta,bought). • je(hon,book). • je(taroo,john).

  12. Example 1 • Declarative Example: • John bought a book • Taroo-ga hon-o katta • Database facts: • je(katta,bought). • je(hon,book). • je(taroo,john). • Parse trees: • ?- sbar(X,[john,bought,a,book],[]). • X = s(np(john),vp(v(bought),np(det(a),n(book)))) • ?- js(X,[taroo,ga,hon,o,katta],[]). • X = s(np(taroo),vp(np(hon),v(katta))) • Translator (top-level): • ?- sbar(X,EnglishSentence,[]),maptree(X,Y),js(Y,JapaneseSentence,[]). • Problem reduces to: • How to write maptree/2 ?

  13. Example 1 • Declarative Example: • John bought a book s(np(john),vp(v(bought),np(det(a),n(book)))) • Taroo-ga hon-o katta s(np(taroo),vp(np(hon),v(katta))) • Database facts (modified): • je(katta,bought).je(v(katta),v(bought)). • je(hon,book). je(np(hon),np(_,n(book))). • % no corresponding indefinite determiner in Japanese • je(taroo,john).je(np(taroo),np(john)). • maptree/2: • Idea: • map subject to subject, verb to verb, object to object, and • respect word-order differences in the trees • maptree(s(S,vp(V,O)),s(SJ,vp(OJ,VJ))) :- • je(SJ,S), • je(VJ,V), • je(OJ,O).

  14. Example 1 • Declarative Example: • John bought a book s(np(john),vp(v(bought),np(det(a),n(book)))) • Taroo-ga hon-o katta s(np(taroo),vp(np(hon),v(katta))) • maptree/2: • maptree(s(S,vp(V,O)),s(SJ,vp(OJ,VJ))) :- • je(SJ,S), • je(VJ,V), • je(OJ,O). • je(v(katta),v(bought)). • je(np(hon),np(_,n(book))). • je(np(taroo),np(john)). • translate/2: • translate(E,J) :- • sbar(X,E,[]), • maptree(X,Xp), • js(Xp,J,[]). • Computation tree (modified): • ?- translate([john,bought,a,book],J). • ?- sbar(X,[john,bought,a,book,][]). • ?- maptree(X,Xp). • ?- js(Xp,J,[]).

  15. Example 1 • Declarative Example: • John bought a book s(np(john),vp(v(bought),np(det(a),n(book)))) • Taroo-ga hon-o katta s(np(taroo),vp(np(hon),v(katta))) • maptree/2: • maptree(s(S,vp(V,O)),s(SJ,vp(OJ,VJ))) :- • je(SJ,S), je(VJ,V), je(OJ,O). • je(v(katta),v(bought)). • je(np(hon),np(_,n(book))). • je(np(taroo),np(john)). • Computation tree (modified): • ?- translate([john,bought,a,book],J). • ?- sbar(X,[john,bought,a,book,][]). • X =s(np(john),vp(v(bought),np(det(a),n(book)))) • ?- maptree(s(np(john),vp(v(bought),np(det(a),n(book)))),Xp). • ?- js(Xp,J,[]). • ?- maptree(s(np(john),vp(v(bought),np(det(a),n(book)))),Xp). • S = np(john) V = v(bought) O = np(det(a),n(book)) Xp = s(SJ,vp(OJ,VJ) • ?- je(SJ,np(john)). • SJ = np(taroo) • ?- je(VJ,v(bought)). • VJ = v(katta) • ?- je(OJ,np(det(a),n(book))). • OJ = np(hon) • ?- js(s(np(taroo),vp(np(hon),v(katta))),J,[]). • J = [taroo,ga,hon,o,katta]

  16. Example 1 • Declarative Example: • John bought a book s(np(john),vp(v(bought),np(det(a),n(book)))) • Taroo-ga hon-o katta s(np(taroo),vp(np(hon),v(katta))) • Query (EJ): • ?- translate([john,bought,a,book],J). • J = [taroo,ga,hon,o,katta] • Query (JE): • ?- translate(E,[taroo,ga,hon,o,katta]). • E = [john,bought,the,book] (surprising!) • Computation tree (JE): • ?- translate(E,[taroo,ga,hon,o,katta]). • ?- sbar(X,E,[]). • ?- maptree(X,Xp). • ?- js(Xp,[taroo,ga,hon,o,katta],[]). • What does the query ?- sbar(X,E,[]). do? • X represents the parse tree • E represents the input sentence • but both arguments are variables! • i.e. we’re not providing any information to the English grammar/parser • translate(E,J) :- • sbar(X,E,[]), • maptree(X,Xp), • js(Xp,J,[]).

  17. Example 1 ?- sbar(X,E,[]). E = [who,did,who,hit], X = sbar(np(who),aux(did),s(np(who),vp(v(hit)))) ? ; E = [who,did,who,eat], X = sbar(np(who),aux(did),s(np(who),vp(v(eat)))) ? ; E = [who,did,who,buy], X = sbar(np(who),aux(did),s(np(who),vp(v(buy)))) ? ; E = [who,did,what,hit], X = sbar(np(who),aux(did),s(np(what),vp(v(hit)))) ? ; E = [who,did,what,eat], X = sbar(np(who),aux(did),s(np(what),vp(v(eat)))) ? ; E = [who,did,what,buy], X = sbar(np(who),aux(did),s(np(what),vp(v(buy)))) ? ; E = [who,did,i,hit], X = sbar(np(who),aux(did),s(np(i),vp(v(hit)))) ? ; E = [who,did,i,eat], X = sbar(np(who),aux(did),s(np(i),vp(v(eat)))) ? ; E = [who,did,i,buy], X = sbar(np(who),aux(did),s(np(i),vp(v(buy)))) ? ; E = [who,did,we,hit], X = sbar(np(who),aux(did),s(np(we),vp(v(hit)))) ? ; E = [who,did,we,eat], X = sbar(np(who),aux(did),s(np(we),vp(v(eat)))) ? ; E = [who,did,we,buy], X = sbar(np(who),aux(did),s(np(we),vp(v(buy)))) ? ; E = [who,did,me,hit], X = sbar(np(who),aux(did),s(np(me),vp(v(hit)))) ? ; E = [who,did,me,eat], X = sbar(np(who),aux(did),s(np(me),vp(v(eat)))) ? ; E = [who,did,me,buy], X = sbar(np(who),aux(did),s(np(me),vp(v(buy)))) ? ; E = [who,did,john,hit], X = sbar(np(who),aux(did),s(np(john),vp(v(hit)))) ? ; E = [who,did,john,eat], X = sbar(np(who),aux(did),s(np(john),vp(v(eat)))) ? ; E = [who,did,john,buy], X = sbar(np(who),aux(did),s(np(john),vp(v(buy)))) ? ; E = [who,did,the,ball,hit], X = sbar(np(who),aux(did),s(np(det(the),n(ball)),vp(v(hit)))) ? ; • What does the query ?- sbar(X,E,[]). do? • X represents the parse tree • Y represents the input sentence • but both arguments are variables! • The English grammar doesn’t just parse and generate • but it is also an enumerater

  18. Example 1 ?- findall((X,Y),sbar(X,Y,[]),L),length(L,N). L = [(sbar(np(who),aux(did),s(np(who),vp(v(hit)))),[who,did,who,hit]),(sbar(np(who),aux(did),s(np(who),vp(v(eat)))),[who,did,who,eat]),(sbar(np(who),aux(did),s(np(who),vp(v(buy)))),[who,did,who,buy]),(sbar(np(who),aux(did),s(np(what),vp(v(hit)))),[who,did,what,hit]),(sbar(np(who),aux(did),s(np(what),vp(v(eat)))),[w\ ho,did,what,eat]),(sbar(np(who),aux(did),s(np(what),vp(v(...)))),[who,did,what,buy]),(sbar(np(who),aux(did),s(np(...),vp(...))),[who,did,i|...]),(sbar(np(...),aux(...),s(...)),[who,did|...]),(sbar(...),[...|...]),(...,...)|...], N = 1456 ? yes • What does the query ?- sbar(X,E,[]). do? • X represents the parse tree • Y represents the input sentence • but both arguments are variables! • The English grammar doesn’t just parse and generate • but it is also an enumerater

  19. Example 2 • Subject wh-Question: • Who bought a book s(np(who),vp(v(bought),np(det(a),n(book)))) • dare-ga hon-o katta ka s(np(dare),vp(np(hon),v(katta))) • New Word Correspondences: • dare = who • ka = question particle • Database facts: • je(v(katta),v(bought)). • je(np(hon),np(_,n(book))). • je(np(taroo),np(john)). • je(np(dare),np(who)). • Does our translation code work for this case? • Yes! • In maptree/2, we pattern-match: • s(np(who),vp(v(bought),np(det(a),n(book)))) • s(S,vp(V,O)) • S = np(who) V = v(bought) O = np(det(a),n(book)) • output: • SJ = np(dare) VJ= v(katta) OJ = np(hon) • s(SJ,vp(OJ,VJ)) • s(np(dare),vp(np(hon),v(katta))) • translate(E,J) :- • sbar(X,E,[]), • maptree(X,Xp), • js(Xp,J,[]). • maptree(s(S,vp(V,O)),s(SJ,vp(OJ,VJ))) :- • je(SJ,S), • je(VJ,V), • je(OJ,O).

  20. Example 2 • Subject wh-Question: • Who bought a book s(np(who),vp(v(bought),np(det(a),n(book)))) • dare-ga hon-o katta ka s(np(dare),vp(np(hon),v(katta))) • Database facts: • je(v(katta),v(bought)). • je(np(hon),np(_,n(book))). • je(np(taroo),np(john)). • je(np(dare),np(who)). • Does our translation code work for this case? Yes! • Queries: • ?- translate([who,bought,a,book],J). • J = [dare,ga,hon,o,katta,ka] • ?- translate(E,[dare,ga,hon,o,katta,ka]). • E = [who,bought,the,book] • Why “the” and not “a” is generated ? • translate(E,J) :- • sbar(X,E,[]), • maptree(X,Xp), • js(Xp,J,[]). • maptree(s(S,vp(V,O)),s(SJ,vp(OJ,VJ))) :- • je(SJ,S), • je(VJ,V), • je(OJ,O). • Mapping result: • s(np(who),vp(v(bought),np(_,n(book)))) • np(np(D,N),Q) --> det(D,Number), common_noun(N,Number,Q). • det(det(the),_) --> [the]. • det(det(a),sg) --> [a].

  21. Next Time • We’ll look at the object wh-question case ... • Example 3: • 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)))

More Related