Download presentation
Presentation is loading. Please wait.
1
LING 388 Language and Computers Lecture 15 10/21/03 Sandiway FONG
2
Administrivia Homework Assignment 3 Homework Assignment 3 Due today Need help? Error in Lecture 10 slide for a n b n c n fixed … Error in Lecture 10 slide for a n b n c n fixed … s --> [a],t(1),[c]. t(N) --> [a],{M is N+1},t(M),[c]. t(N) --> u(N). u(N) --> {N>1}, [b],{M is N-1},u(M). u(1) --> [b].
3
-Calculus Lambda ( ) calculus: Lambda ( ) calculus: Concerned with the definition of anonymous functions and their application Invented by Alonzo Church to explore computability of functions Example definition: Example definition: x.x+3“is a function that adds 3 to x” Note : we did not give this function a name - hence the term “anonymous”we did not give this function a name - hence the term “anonymous”
4
-Calculus Example of application: Example of application: x.x+3) 2“apply lambda function to 2” ( -reduction) x+3) [2/x]“substitute 2 for x” 2+3“evaluate function” 5 There is much more to -calculus There is much more to -calculus But this is all we need …
5
Last Time … We looked at the parsing of empty NPs in relative clause constructions We looked at the parsing of empty NPs in relative clause constructions Example: the cat that I saw the cat i that I saw [ NP e i ] (the cat)( x.I saw x) By analogy: that I saw [ NP e i ] has the semantics of x.I saw x This function returns x
6
Last Time … The rule that generated the empty category [ NP e i ] allowed for considerable overgeneration The rule that generated the empty category [ NP e i ] allowed for considerable overgeneration Examples: *Hit the ball[ NP e i ] hit the ball *John hitJohn hit [ NP e i ] *Hit [ NP e i ] hit [ NP e i ] … all of which can be accepted as complete sentences by the DCG
7
Last Time … To control the overgeneration, we needed some condition on representation … To control the overgeneration, we needed some condition on representation … Filter: All variables must be bound by an operator ( x) Example: *John hits(np(john),vp(v(hit),np(x))) Today’s Lecture: Today’s Lecture: How to implement this filter
8
Condition on Representation Basic Idea: Basic Idea: Scan phrase structure looking for a variable and operator Succeed only if matching operator found Scan Operation: Scan Operation: Tree-walker Walk through a tree node-by-node, testing each node to see if we have found what we’re looking for
9
Condition on Representation Also make use of two elements that we’ve already seen: Also make use of two elements that we’ve already seen: =.. (univ) man(X) =.. [man,X] to deconstruct structures Feature propagation to send information up the tree s np vp v np detn theman likes [3,sg] John [3,sg] P,N
10
Tree-Walker Question: Question: How to scan phrase structure tree? Answer: Answer: Write a recursive predicate, a tree- walker, to visit every node of a tree
11
Tree-Walker Assuming phrase structure trees are binary branching at the most… Assuming phrase structure trees are binary branching at the most… Tree-Walker must deal with three cases: Tree-Walker must deal with three cases: A. Binary branching visit both subtrees B. Unary branching visit child subtree C. Terminal node done np detn theman vp ran v A B C
12
Tree-Walker Example Prolog code: Example Prolog code: Define a predicate visit/1 taking as its argument a phrase structure tree visit(X) :- % Case A X =.. [F,A1,A2], visit(A1), visit(A2). visit(X) :-% Case B X =.. [F,A], visit(A). visit(X) :-% Case C atom(X).atom/1 built-in np detn theman vp ran v A B C X F=np A1 A2 X F=vp A
13
Tree-Walker visit/1 example: visit/1 example: Inorder traversal s npvp vnp detn theman saw john 1 11 10 9 8 7 6 5 4 3 2
14
Tree-Walker visit/1 doesn’t really do anything yet visit/1 doesn’t really do anything yet Need to add a specific test for np(x) Example: *John hits(np(john),vp(v(hit),np(x))) visit(X) :- X =.. [F,A1,A2], visit(A1), visit(A2). visit(X) :- X =.. [F,A], visit(A). visit(X) :- atom(X). visit(np(x)).
15
Tree-Walker We can write visit/1 to succeed only if it finds np(x) We can write visit/1 to succeed only if it finds np(x) visit(np(x)). visit(X) :- X =.. [F,A1,A2], visit(A1), visit(A2). visit(X) :- X =.. [F,A], visit(A). visit(X) :- atom(X). visit(np(x)). visit(X) :- X =.. [F,A1,A2], visit(A1). visit(X) :- X =.. [F,A1,A2], visit(A2). visit(X) :- X =.. [F,A], visit(A). Succeeds always Succeeds only if np(x) exists
16
Tree-Walker New visit/1 example for *John hit [ NP e]: New visit/1 example for *John hit [ NP e]: s npvp vnp x hit john visit(X) succeeds visit(X) fails
17
Tree-Walker Call the first form a conjunctive tree-walker, the 2nd a disjunctive tree-walker Call the first form a conjunctive tree-walker, the 2nd a disjunctive tree-walker visit(np(x)). visit(X) :- X =.. [F,A1,A2], visit(A1), visit(A2). visit(X) :- X =.. [F,A], visit(A). visit(X) :- atom(X). visit(np(x)). visit(X) :- X =.. [F,A1,A2], visit(A1). visit(X) :- X =.. [F,A1,A2], visit(A2). visit(X) :- X =.. [F,A], visit(A). Either visit A1 or A2 Visit A1 and A2
18
Tree-Walker Let’s rename our modified version of visit/1 to reflect the new semantics Let’s rename our modified version of visit/1 to reflect the new semantics variable(np(x)). variable(X) :- X =.. [F,A1,A2], variable(A1). variable(X) :- X =.. [F,A1,A2], variable(A2). variable(X) :- X =.. [F,A], variable(A). variable/1 holds only if there exists np(x) in the phrase structure variable/1 holds only if there exists np(x) in the phrase structure Examples: ?- variable(s(np(john),vp(v(hit),np(x)))).?- variable(s(np(john),vp(v(hit),np(x)))). YesYes ?- variable(s(np(john),vp(v(hit),np(mary)))).?- variable(s(np(john),vp(v(hit),np(mary)))). NoNo ?-variable ( np(np(det(the),n(cat)),?-variable ( np(np(det(the),n(cat)),lambda(x,s(np(i),vp(v(saw),np(x)))))). YesYes
19
Tree-Walker Let’s build another modified version of visit/1 that succeeds only if there exists an operator x, i.e. lambda(x,_), in the phrase structure Let’s build another modified version of visit/1 that succeeds only if there exists an operator x, i.e. lambda(x,_), in the phrase structure operator(lambda(x,_)). operator(X) :- X =.. [F,A1,A2], operator(A1). operator(X) :- X =.. [F,A1,A2], operator(A2). operator(X) :- X =.. [F,A], operator(A). Examples: ?- operator(s(np(john),vp(v(hit),np(x)))).?- operator(s(np(john),vp(v(hit),np(x)))). NoNo ?- operator(s(np(john),vp(v(hit),np(mary)))).?- operator(s(np(john),vp(v(hit),np(mary)))). NoNo ?-operator ( np(np(det(the),n(cat)),?-operator ( np(np(det(the),n(cat)),lambda(x,s(np(i),vp(v(saw),np(x)))))). YesYes
20
Filter Implementation Filter: Filter: All variables must be bound by an operator ( x) Implementation (Initial try) : Implementation (Initial try) : filter(X) :- variable(X), operator(X). filter(X) :- \+ variable(X). succeeds either when there is no variable in X or when a variable and an operator co-occur in X Use : Use : ?- s(X,Sentence,[]), filter(X). X is the phrase structure returned by the DCG Sentence is the input sentence encoded as a list filter/1 is a condition on representation
21
Filter Implementation Filter: Filter: All variables must be bound by an operator ( x) Implementation : Implementation : filter(X) :- variable(X), operator(X). filter(X) :- \+ variable(X). Description: Description: filter(X) succeeds either when there is no variable in X or when a variable and an operator co-occur in X
22
Filter Implementation A simpler rendering of filter/1 : A simpler rendering of filter/1 : filter(X) :- variable(X) -> operator(X) ; true. Advantage: one clause implementation instead of two … Note: Note: -> is the “then” operator in Prolog compare with the DCG operator --> Semantics: X -> Y ; Z if X is true then Y must be true if X is not true, Z must be true if X is not true, Z must be true
23
Filter Implementation Note: Note: filter(X) :- variable(X) -> operator(X) ; true. is only a first approximation implementation of All variables must be bound by an operator ( x) Example: *the cat that I saw hit s(np(np(det(the),n(cat)),lambda(x,s(np(i),vp(v(saw),np(x))))), vp(v(hit),np(x))) vp(v(hit),np(x))) filter/1 (incorrectly) holds for the above example because: filter/1 looks only for one variable, and filter/1 looks for an operator anywhere in the phrase structure
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.