Title: LING 388: Language and Computers
1LING 388 Language and Computers
- Sandiway Fong
- Lecture 23 11/13
2Administrivia
- Homework 5
- graded and returned by email
- if you dont see an email from me, I assume you
didnt submit the homework
3Last Time
- English wh-questions
- subject wh-questions simple
- object wh-questions complex
- wh-word fronting
- do-support
- tense goes with do
- DCG technology employed
- extra argument
- nonterminal renaming
sbar
np
sobjectwh
aux
what
np
vp objectwh
did
v
john
buy
4Last Exercise
- Modify the grammar to use traces of movement.
- Generate the following structures
- Sbar Who S NP trace VP bought NP a book
- Sbar What did S NP John VP buy NP trace
5English Grammar from last time
- sbar(sbar(WhNP,DO,S)) --gt np(WhNP,wh),
do(DO,Form), \ Form root, s_objectwh(S). - sbar(sbar(WhNP,S)) --gt np(WhNP,wh),
s_subjectwh(S). - sbar(S) --gt s(S).
- s(s(Y,Z)) --gt np(Y,notwh), vp(Z).
- s_subjectwh(s(np(trace),Z)) --gt vp(Z).
- s_objectwh(s(Y,Z)) --gt np(Y,_Wh), vp_objectwh(Z).
- np(np(Y),notwh) --gt proper_noun(Y).
- np(np(Y),Wh) --gt pronoun(Y,Wh).
- np(np(D,N),notwh) --gt det(D,Number),
common_noun(N,Number). - det(det(the),_) --gt the.
- det(det(a),sg) --gt a.
- proper_noun(john) --gt john.
6English Grammar from last time
- common_noun(n(ball),sg) --gt ball.
- common_noun(n(man),sg) --gt man.
- common_noun(n(men),pl) --gt men.
- common_noun(n(book),sg) --gt book.
- common_noun(n(books),pl) --gt books.
- pronoun(i,notwh) --gt i.
- pronoun(we,notwh) --gt we.
- pronoun(me,notwh) --gt me.
- pronoun(who,wh) --gt who.
- pronoun(what,wh) --gt what.
- vp(vp(Y)) --gt unergative(Y).
- vp(vp(Y,Z)) --gt transitive(Y,Form), \ Form
en , np(Z,notwh). - vp(vp(A,V)) --gt aux(A), transitive(V,en).
- vp_objectwh(vp(Y,np(trace))) --gt
transitive(Y,root).
7English Grammar from last time
- unergative(v(ran)) --gt ran.
- transitive(v(hit),_) --gt hit.
- transitive(v(eat),root) --gt eat.
- transitive(v(eats),s) --gt eats.
- transitive(v(ate),ed) --gt ate.
- transitive(v(eaten),en) --gt eaten.
- transitive(v(buy),root) --gt buy.
- transitive(v(buys),s) --gt buys.
- transitive(v(bought),ed) --gt bought.
- transitive(v(bought),en) --gt bought.
- aux(aux(was)) --gt was.
- do(aux(do),root) --gt do.
- do(aux(does),s) --gt does.
- do(aux(did),ed) --gt did.
8English Grammar from last time
- Builds traces for wh-questions
- Subject-wh Question
- ?- sbar(X,who,bought,a,book,).
- X sbar(np(who),s(np(trace),vp(v(bought),np(det(a
),n(book))))) ? - no
- but if s(s(Y,Z)) --gt np(Y,notwh), vp(Z). is
changed to - s(s(Y,Z)) --gt np(Y,_), vp(Z).
- we get two parses
- ?- sbar(X,who,bought,a,book,).
- X sbar(np(who),s(np(trace),vp(v(bought),np(det(a
),n(book))))) ? - X s(np(who),vp(v(bought),np(det(a),n(book)))) ?
- no
9English Grammar from last time
- Builds traces for wh-questions
- Object-wh Question
- ?- sbar(X,what,did,john,buy,).
- X sbar(np(what),aux(did),s(np(john),vp(v(buy),np
(trace)))) ? - no
- ?- sbar(X,what,did,john,bought,).
- no
- ?- sbar(X,what,do,john,bought,).
- no
- ?- sbar(X,what,do,john,buy,).
- no
10English Grammar from last time
- Compare
- What did who buy?
- Who bought what?
- What does our grammar do (at the moment)?
- ?- sbar(X,what,did,who,buy,).
- X sbar(np(what),aux(did),s(np(who),vp(v(buy),np(
trace)))) ? - no
- ?- sbar(X,who,bought,what,).
- no
- We can play around with our grammar to get the
right effects...
11Todays Topic
- grammar components so far
- English DCG
- Japanese DCG
- both are bi-directional
- can generate and parse with the same grammar
- advantage of using Prolog for that
- putting it all together...
- Machine Translation (MT)
12Japanese 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
- DCG rules
- s(s(Y,Z)) --gt np(Y,Q1), nomcase, vp(Z,Q2),
sf(Q1,Q2). - vp(vp(Z,Y),Q) --gt np(Z,Q), acccase,
transitive(Y). - transitive(v(katta)) --gt katta.
- nomcase --gt ga.
- acccase --gt o.
- np(np(taroo),notwh) --gt taroo.
- np(np(hon),notwh) --gt hon.
- np(np(dare),wh) --gt dare.
- np(np(nani),wh) --gt nani.
- sf(wh,notwh) --gt ka.
- sf(notwh,wh) --gt ka.
- sf(notwh,notwh) --gt .
- sf(wh,wh) --gt ka.
13Japanese Grammar
- DCG rules
- js(s(Y,Z)) --gt jnp(Y,Q1), nomcase, jvp(Z,Q2),
sf(Q1,Q2). - jvp(vp(Z,Y),Q) --gt jnp(Z,Q), acccase,
jtransitive(Y). - jtransitive(v(katta)) --gt katta.
- nomcase --gt ga.
- acccase --gt o.
- jnp(np(taroo),notwh) --gt taroo.
- jnp(np(hon),notwh) --gt hon.
- jnp(np(dare),wh) --gt dare.
- jnp(np(nani),wh) --gt nani.
- sf(wh,notwh) --gt ka.
- sf(notwh,wh) --gt ka.
- sf(notwh,notwh) --gt .
- sf(wh,wh) --gt ka.
rename Japanese nonterminals to not clash with
English grammar were going to be loading them
both at the same time
14English 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)
15English Grammar
- DCG rules
- sbar(sbar(X,A,Y)) --gt np(X,wh), do(A),
s_objectwh(Y). - sbar(S) --gt s(S).
- s_objectwh(s(Y,Z)) --gt np(Y,_), vp_objectwh(Z).
- s(s(Y,Z)) --gt np(Y,_), vp(Z).
- np(np(Y),Q) --gt pronoun(Y,Q).
- np(np(Y),notwh) --gt proper_noun(Y).
- np(np(D,N),Q) --gt det(D,Number),
common_noun(N,Number,Q). - det(det(the),_) --gt the.
- det(det(a),sg) --gt a.
- common_noun(n(ball),sg,notwh) --gt ball.
- common_noun(n(man),sg,notwh) --gt man.
- common_noun(n(men),pl,notwh) --gt men.
- common_noun(n(book),sg,notwh) --gt book.
- pronoun(who,wh) --gt who.
- pronoun(what,wh) --gt what.
- pronoun(i,notwh) --gt i.
- pronoun(we,notwh) --gt we.
- pronoun(me,notwh) --gt me.
- proper_noun(john) --gt john.
- vp(vp(Y)) --gt unergative(Y).
- vp(vp(Y,Z)) --gt transitive(Y,_), np(Z,notwh).
- vp(vp(A,V)) --gt aux(A), transitive(V,en).
- vp_objectwh(vp(Y)) --gt transitive(Y,root).
- unergative(v(ran)) --gt ran.
- transitive(v(hit),_) --gt hit.
- transitive(v(eat),root) --gt eat.
- transitive(v(eats),s) --gt eats.
- transitive(v(ate),ed) --gt ate.
- transitive(v(eaten),en) --gt eaten.
- transitive(v(buy),root) --gt buy.
- transitive(v(bought),ed) --gt bought.
- aux(aux(was)) --gt was.
- do(aux(did)) --gt did.
- do(aux(does)) --gt does.
- do(aux(do)) --gt do.
16English 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
17Example 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).
18Example 1
tree mapping idea
19Example 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,Ja
paneseSentence,). - problem reduces to
- how to write predicate maptree/2 ?
20Example 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(katt
a))) - 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)).
- predicate 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).
21Example 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(katt
a))) - predicate 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)).
- define predicate 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,).
22Example 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(katt
a))) - predicate 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(boo
k)))),Xp). - ?- js(Xp,J,).
- ?- maptree(s(np(john),vp(v(bought),np(det(a),n(boo
k)))),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)
23Example 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(katt
a))) - 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. were not providing any information to the
English grammar/parser
translate(E,J) - sbar(X,E,),
maptree(X,Xp), js(Xp,J,).
24Example 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
- E represents the input sentence
- but both arguments are variables!
- the English grammar doesnt just parse and
generate - but it is also an enumerator
25Example 1
?- findall((X,Y),sbar(X,Y,),L),length(L,N). L
(sbar(np(who),aux(did),s(np(who),vp(v(hit)))),wh
o,did,who,hit),(sbar(np(who),aux(did),s(np(who),v
p(v(eat)))),who,did,who,eat),(sbar(np(who),aux(d
id),s(np(who),vp(v(buy)))),who,did,who,buy),(sba
r(np(who),aux(did),s(np(what),vp(v(hit)))),who,di
d,what,hit),(sbar(np(who),aux(did),s(np(what),vp(
v(eat)))),who,did,what,eat),(sbar(np(who),aux(di
d),s(np(what),vp(v(...)))),who,did,what,buy),(sb
ar(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
- E represents the input sentence
- but both arguments are variables!
- the English grammar doesnt just parse and
generate - but it is also an enumerator