Documents
Resources
Learning Center
Upload
Plans & pricing Sign in
Sign Out

LING 388 Language and Computers

VIEWS: 1 PAGES: 35

									LING 388: Language and
      Computers
      Sandiway Fong
     Lecture 26: 11/28
             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

                                      2
                      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...

                                                                   3
                               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).




                                                                                     4
     Translator Architecture
• tree-to-tree mapping



     English parse tree                         Japanese parse tree




    English Grammar       construction-based   Japanese Grammar



     English sentence                            Japanese sentence
                                                                      5
                                  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)




                                                                    6
     Translator Architecture
• predicate-argument mapping

                            p(A1,A2)
                          construction independent
     English predicate-   particular-language parse    Japanese predicate-
     argument structure   tree independent             argument structure
                           more advanced:
                           language-independent
                           interlingua

    English Grammar                                   Japanese Grammar



     English sentence                                   Japanese sentence
                                                                             7
                      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].                        predarg(X,Y,Order,PA) :-
     • np(np(taroo),notwh) --> [taroo].                headof(X,S),
     • np(np(hon),notwh) --> [hon].                    headof(Y,P),
     • np(np(dare),wh) --> [dare].                     order(Order,Y,NP),
     • np(np(nani),wh) --> [nani].                     headof(NP,O),
     • sf(wh,notwh) --> [ka].                          PA =.. [P,S,O].
     • sf(notwh,wh) --> [ka].
     • sf(notwh,notwh) --> [].
     • sf(wh,wh) --> [ka].                     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).             8
    English Grammar: Modified
                                              •    pronoun(we,notwh) --> [we].
•   DCG rules:                                •    pronoun(me,notwh) --> [me].
•   sbar(sbar(X,A,Y)) --> np(X,wh), do(A),    •    proper_noun(john) --> [john].
    s_objectwh(Y).
                                              •    vp(vp(Y)) --> unergative(Y).
•   sbar(S) --> s(S).                         •    vp(vp(Y,Z)) --> transitive(Y,_),
•   s_objectwh(s(Y,Z)) --> np(Y,_),                np(Z,_).
    vp_objectwh(Z).                            •   vp(vp(A,V)) --> aux(A),
•   s(PA) --> np(Y,_),vp(Z),{predarg(Y,Z,1,PA).    transitive(V,en).
•   np(np(Y),Q) --> pronoun(Y,Q).              •   vp_objectwh(vp(Y)) -->
                                                   transitive(Y,root).
•   np(np(Y),notwh) --> proper_noun(Y).
                                               •   unergative(v(ran)) --> [ran].
•   np(np(D,N),Q) --> det(D,Number),
                                               •   transitive(v(hit),_) --> [hit].
    common_noun(N,Number,Q).
                                               •   transitive(v(eat),root) --> [eat].
•   det(det(the),_) --> [the].
                                               •   transitive(v(eats),s) --> [eats].
•   det(det(a),sg) --> [a].                    •   transitive(v(ate),ed) --> [ate].
•   common_noun(n(ball),sg,notwh) --> [ball]. •    transitive(v(eaten),en) --> [eaten].
•   common_noun(n(man),sg,notwh) --> [man].    •   transitive(v(buy),root) --> [buy].
•   common_noun(n(men),pl,notwh) --> [men].    •   transitive(v(bought),ed) --> [bought].
•   common_noun(n(book),sg,notwh) --> [book]. •    aux(aux(was)) --> [was].
•   pronoun(who,wh) --> [who].                 •   do(aux(did)) --> [did].
•   pronoun(what,wh) --> [what].               •   do(aux(does)) --> [does].
•   pronoun(i,notwh) --> [i].                  •   do(aux(do)) --> [do].
                                                                                  9
    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)




                                                                        10
    Mapping: Predicate-Argument Structure

• Task 2:
     – Modify the English grammar to also generate
       predicate argument structure
                                                                   sbar

•   Example 3 (Object wh-Question):                           np
     – What did John buy            buy(john,what)                  aux           s

                                                             what
•   Modified SBar rules:                                            did   np            vp
     –   sbar(PA) --> np(X,wh), do(A), s_objectwh(Y,S,P),
         {headof(X,O),PA =.. [P,S,O]}.                                            v
                                                                           john
     –   s_objectwh(s(Y,Z),S,P) --> np(Y,_),                                      buy
         vp_objectwh(Z), {headof(Y,S),headof(Z,P)}.
                                              •sbar(np(what),aux(did),s(np(john),vp(v(buy))))
     –   vp_objectwh(vp(Y)) --> transitive(Y,root).

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


                                         13
     Translator Architecture
• predicate-argument mapping

                            p(A1,A2)
                          construction independent
     English predicate-   particular-language parse    Japanese predicate-
     argument structure   tree independent             argument structure




    English Grammar                                   Japanese Grammar



     English sentence                                   Japanese sentence
                                                                             14
                       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)

                                                                         15
                                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).



                                                        16
                                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).                   Tree-to-tree mapping dictionary
     –   je(dare,who).
     –   je(nani,what).                    je(v(katta), v(bought)).
     –   je(katta,buy).                    je(np(hon), np(_,n(book))).
                                           je(np(taroo),np(john)).
                                           je(np(dare), np(who)).
                                           je(np(nani), np(what)).           17
                               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]).


                                                                                    18
Homework 7




             19
                 Files

file   description          also contains

e.pl   English DCG

j.pl   Japanese DCG         predicate-argument code

t.pl   Translator/mapping   bilingual dictionary




                                                      20
        English Grammar: e.pl
•   DCG rules                             •   vp_objectwh(vp(Y)) -->
                                              transitive(Y,root).
•   sbar(PA) --> np(X,wh), do(_,_),
    s_objectwh(_,S,P), {headof(X,O), PA   •   det(det(the),_) --> [the].
    =..[P,S,O]}.                          •   det(det(a),sg) --> [a].
•   sbar(S) --> s(S).                     •   common_noun(n(bucket),sg,notwh)
•   s_objectwh(s(Y,Z),S,P) --> np(Y,_),       --> [bucket].
    vp_objectwh(Z),                       •   common_noun(n(buckets),pl,notwh
    {headof(Y,S),headof(Z,P)}.                ) --> [buckets].
•   s(PA) --> np(Y,_), vp(Z,_),           •   common_noun(n(apple),sg,notwh)
    {predarg(Y,Z,1,PA)}.                      --> [apple].
•   np(np(Y),Q) --> pronoun(Y,Q).         •   common_noun(n(apples),pl,notwh)
•   np(np(Y),notwh) --> proper_noun(Y).       --> [apples].
•   np(np(D,N),Q) --> det(D,Number),      •   common_noun(n(man),sg,notwh) --
    common_noun(N,Number,Q).                  > [man].
•   vp(vp(v(died)),ed) -->                •   common_noun(n(book),sg,notwh) -
    [kicked,the,bucket].                      -> [book].
•   vp(vp(Y,Z),F) --> transitive(Y,F),    •   common_noun(n(books),pl,notwh)
    np(Z,_).                                  --> [books].
•   vp(vp(A,V),F) --> aux(A,F),
    transitive(V,en).
                                                                        21
        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].
                                             22
     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].                    predarg(X,Y,Order,PA) :-
          • acccase --> [o].                             headof(X,S),
          • np(np(taroo),notwh) --> [taroo].             headof(Y,P),
                                                         order(Order,Y,NP),
          • np(np(hon),notwh) --> [hon].                 headof(NP,O),
          • np(np(dare),wh) --> [dare].                  PA =.. [P,S,O].
          • np(np(nani),wh) --> [nani].          predarg(X,Y,_,PA) :-
          • sf(wh,notwh) --> [ka].                        headof(X,S),
          • sf(notwh,wh) --> [ka].                         headof(Y,P),
                                                           Y = vp(_),
          • sf(notwh,notwh) --> [].                        PA =.. [P,S].
          • sf(wh,wh) --> [ka].
                                                      order(1,vp(_,NP),NP).
                                                      order(2,vp(NP,_),NP).

bilingual predicate-argument structure code           headof(np(_,n(N)),N).
stored in j21.pl but used by both grammars            headof(vp(v(V),_),V).
                                                      headof(vp(_,v(V)),V).
                                                      headof(vp(v(V)),V).
                                                      headof(np(N),N).
                                                                              23
                   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).




                                                               24
               Exercise 0: Translation

•   load all 3 files e.pl, j.pl and t.pl into the Prolog system
•   preliminary exercise
•   (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



                                                                         25
            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




                                                                       26
                   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 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]).




                                                                           27
      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))




                                                                   28
      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))




                                                                   29
                                               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




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



                                                                                          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                                    predarg(X,Y,Order,PA) :-
                                                                            headof(X,S),
           •   VP “kicked the buckets”
                  –   has only a literal interpretation
                                                                            headof(Y,P),
                                                                            order(Order,Y,NP),
•   idiomatic interpretation                                                headof(NP,O),
     –   Verb Phrase: kicked the bucket                                     PA =.. [P,S,O].
     –   vp(vp(v(died))) --> [kicked,the,bucket].

•   Predicate-Argument structure (intransitive verbs)               order(1,vp(_,NP),NP).
                                                                    order(2,vp(NP,_),NP).
     –   predarg(X,Y,_,PA) :-
     –           headof(X,S),                                       headof(np(_,n(N)),N).
     –           headof(Y,P),                                       headof(vp(v(V),_),V).
                                                                    headof(vp(_,v(V)),V).
     –           Y = vp(_),                                         headof(vp(v(V)),V).
     –           PA =.. [P,S].                                      headof(np(N),N).



                                                                                        32
                                               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




                                                                   33
      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)


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




                                                             35

								
To top