150 likes | 258 Vues
This module explores advanced semantics in NLP, focusing on partial execution techniques within Prolog. Partial execution replaces specific runtime computations by modifying the source code of the program. The lecture explains how this can be applied to rules involving proper nouns and adjectives, showcasing the translation of statements into structured forms. Exercises challenge students to apply partial execution to eliminate unnecessary clauses in grammar definitions, enhancing understanding of logical structure and computation in semantic representation.
E N D
CSA4050:Advanced Topics in NLP Semantics IV Partial Execution Proper Noun Adjective
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(VP). • This is because the computation of reduce involves only the mutual binding of several variables.
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).
Exercise 1 • 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)}.
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).
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) }.
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],[ ]).
?- 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,suzie,S) holds.
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)}. d(RL^SL^all(X,R => S)) --> [every], {reduce(RL,X,R), reduce(SL,X,S) }.
Exercise 2 Using partial execution, eliminate the reduce clause in pn(VP^S) --> [‘Suzie’],{reduce(VP,suzie,S)}.
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)
In english, adjectives combine with nouns, e.g. big dog. We will call the an adjective/noun combination (without the article) N1. Here is a syntactic rulefor a simplified version of N1:N1 → A N Adjectives N1 A N dog big
Semantics of N1 • Adjectives and common nouns translate to one-place predicates. • big = x.big(x) • dog = x.dog(x) • To get the semantics of the N1 we need to join the predicates together with & (and), i.e. • big dog = x.big(x) & dog(x)
N1 in Prolog %grammar n1(X^(P&Q)) --> a(X^P), n(X^Q). %lexicon n(X^dog(X)) --> [dog]. a(X^big(X)) --> [big]. Behaviour is as follows: ?- n1(X, [big,dog],[]). X = _G343^ (big(_G343)&dog(_G343))