210 likes | 327 Views
CSA4050: Advanced Topics in NLP. Semantics IV Partial Execution Proper Noun Transitive Verb Phrase. Partial Execution. Partial execution involves the replacing of certain runtime computations with changes to the source of the Prolog program itself.
E N D
CSA4050:Advanced Topics in NLP Semantics IV Partial Execution Proper Noun Transitive Verb Phrase
Partial Execution • Partial execution involves the replacing of certain runtime computations with changes to the source of the Prolog program itself. • For example, we can replace the rule:s(S) --> np(NP), vp(VP) { reduce(NP,VP,S) }.withs(S) --> np(VP^S), vp(S). • This is because the computation of reduce involves only the mutual binding of several variables. CSA4050 Advanced NLP
How it works s(S) --> np(NP), vp(VP) { reduce(NP,VP,S)}. 1. match reduce(A^F,A,F) 2. rewrite s(F) --> np(A^F), vp(A). 3. rename s(S) --> np(VP^S), vp(VP). CSA4050 Advanced NLP
Exercise • What is the result of eliminating the reduce clause by partial execution in the following rule? np(NP) --> d(D), n(N), {reduce(D,N,NP)}. CSA4050 Advanced NLP
Answer np(NP) --> d(D), n(N) { reduce(D,N,NP)}. 1. match reduce(A^F,A,F) 2. rewrite np(F) --> d(A^F), n(A). 3. rename np(NP) --> d(N^NP), n(N). CSA4050 Advanced NLP
DCG with QuantificationProgram 4 % grammar s(S) --> np(VP^S), vp(VP). np(NP) --> d(N^NP), n(N). vp(VP) --> v(VP). % lexicon v(X^walk(X)) --> [walks]. n(X^man(X)) --> [man]. n(suzie) --> [‘Suzie’]. det(RL^SL^all(X,R,S) --> [every], {reduce(RL,X,R), reduce(SL,X,S) }. CSA4050 Advanced NLP
Handling Proper Nouns • The grammar handles every man walksX = all(_G, man(_G), walk(_G)) • Will this grammar parse Suzie walks? • Let’s try it! • ?- s(X,['Suzie',walks],[ ]). CSA4050 Advanced NLP
?- s(X,['Suzie',walks],[ ]). Call: (8) s(_G492, ['Suzie', walks], []) ? Call: (9) np(_L183, ['Suzie', walks], _L184) ? Call: (10) pn(_L183, ['Suzie', walks], _L184) ? Exit: (10) pn(suzie, ['Suzie', walks], [walks]) ? Exit: (9) np(suzie, ['Suzie', walks], [walks]) ? Call: (9) vp(_L185, [walks], _L186) ? Call: (10) iv(_L185, [walks], _L186) ? Exit: (10) iv(_G556^walk(_G556), [walks], []) ? Exit: (9) vp(_G556^walk(_G556), [walks], []) ? Call: (9) reduce(suzie, _G556^walk(_G556), _G492) ? Fail: (9) reduce(suzie, _G556^walk(_G556), _G492)? ........ suzie is not a function
Handling Proper Nouns • Problem is with the “type” of LF of Suzie. • We require that LF of Suzie has the same type as any other NP - such as every man, i.e. • As a lambda expression it would be λp.p(suzie). • In Prolog we can regard this as a function from [VP] to [S] such that reduce(VP,john,S) holds. CSA4050 Advanced NLP
DCG with QuantificationProgram 4 % grammar s(S) --> np(VP^S), vp(VP). np(NP) --> n(NP). np(NP) --> d(N^NP), n(N). vp(VP) --> v(VP). % lexicon v(X^walk(X)) --> [walks]. n(X^man(X)) --> [man]. n(VP^S) --> [‘Suzie’], {reduce(VP,suzie,S)}. det(RL^SL^all(X,R => S) --> [every], {reduce(RL,X,R), reduce(SL,X,S) }. CSA4050 Advanced NLP
Exercise 2 Using partial execution, eliminate the reduce clause in pn(VP^S) --> [‘Suzie’],{reduce(VP,suzie,S)}. CSA4050 Advanced NLP
s(X, ['Suzie', walks], [ ]) ? Call: (7) s(_G292, ['Suzie', walks], []) ? ↓ Exit: (9) pn((suzie^_G357)^_G357, ['Suzie', walks], [walks]) ? ↓ Exit: (9) iv(_G362^walk(_G362), [walks], []) ? Exit: (8) vp(_G362^walk(_G362), [walks], []) ? : Call: (8) reduce((suzie^_G357)^_G357, _G362^walk(_G362), _G292) ? : Exit: (8) reduce((suzie^walk(suzie))^walk(suzie), suzie^walk(suzie), walk(suzie)) ? Exit: (7) s(walk(suzie), ['Suzie', walks], []) ? creep X = walk(suzie) CSA4050 Advanced NLP
Transitive Verb Phases • Transitive verb phrases take an object, e.g.chased a cat • To handle transitive VPs we need another VP rulevp(VP) --> v(V), np(NP). • In this case we have: V = λx. λy. chased(x,y) NP = λs.some(w,cat(w),s(w)) • Issues: • What is the LF of the resulting VP and • How do the component LFs combine? CSA4050 Advanced NLP
Resulting VP λz.some(y,cat(y),chased(z,y)) • Note that this has the form of a standard VP that is waiting for a subject, so is compatible with the rest of the grammar. CSA4050 Advanced NLP
Making VP VP λz.some(y,cat(y),chased(z,y)) V λx. λy. chased(x,y) chased NP λs.some(w,cat(w),s(w)) some cat CSA4050 Advanced NLP
Apply NP to Vdoesn't work! λs.some(w,cat(w), s(w)) (λx. λy. chased(x,y)) β some(w,cat(w), (λy. λx. chased(x,y))(w)) β some(w,cat(w), λx.chased(x,w)) NP V CSA4050 Advanced NLP
Solution • Need a more complex way of combining V and NP:λNP.λV.λz.NP(V(z)) λs.some(w,cat(w), s(w)) ← NP arg λx. λy. chased(x,y))← V arg CSA4050 Advanced NLP
How it works λNP.λV.λz.NP(V(z)) λs.some(w,cat(w), s(w)) λx. λy. chased(x,y)) λ z.λs.some(w,cat(w), s(w)) λx.λy.chased(x,y)(z) β λ z.λs.some(w,cat(w), s(w)) (λy. chased(z,y)) β λ z. some(cat(w), (λy.chased(z,y))(w)) β λ z. some(cat(w), chased(z,w)) CSA4050 Advanced NLP
VP Rule Revisited vp(VP) --> v(V), np(NP), {instructions}. • The instructions encode the combinationλNP.λV.λz.NP(V(z))vp(Z^P) --> v(V2), np(NP), {reduce(V2,Z,V1), reduce(NP,V1,P)}. CSA4050 Advanced NLP
Program 5 % grammar s(S) --> np(NP), vp(VP), {reduce(NP,VP,S)}. np(NP) --> n(NP). np(NP) --> d(D), n(N), {reduce(D,N,NP) }. vp(VP) --> v(VP). vp(Z^P)--> v(V2), np(NP), {reduce(V2,Z,V1), reduce(NP,V1,P)}. % lexicon v(X^walk(X)) --> [walks]. v(X^Y^chased(X,Y)) --> [chased]. n(X^cat(X)) --> [cat]. n(VP^S) --> [suzie], {reduce(VP,suzie,S)}. d(RL^SL^some(X,R,S)) --> [a], {reduce(RL,X,R),reduce(SL,X,S) }. CSA4050 Advanced NLP
Test ?- s(X,[suzie,chased,a,cat],[]). X = some(_G245, cat(_G245), chased(suzie, _G245)) ?- s(X,[a,cat,chased,a,cat],[]). X = some(_G245, cat(_G245), some(_G266, cat(_G266), chased(_G245, _G266))) ; CSA4050 Advanced NLP