1 / 23

LING 388 Language and Computers

LING 388 Language and Computers. Lecture 15 10/21 /03 Sandiway FONG. Administrivia. Homework Assignment 3 Due today Need help? 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).

Download Presentation

LING 388 Language and Computers

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. LING 388Language and Computers Lecture 15 10/21/03 Sandiway FONG

  2. Administrivia • Homework Assignment 3 • Due today • Need help? • Error in Lecture 10 slide for anbncn 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. l-Calculus • Lambda (l) calculus: • Concerned with the definition of anonymous functions and their application • Invented by Alonzo Church to explore computability of functions • Example definition: • lx.x+3 “is a function that adds 3 to x” • Note : • we did not give this function a name - hence the term “anonymous”

  4. l-Calculus • Example of application: • (lx.x+3) 2 “apply lambda function to 2” (b-reduction) • (x+3) [2/x] “substitute 2 for x” • 2+3 “evaluate function” • 5 • There is much more to l-calculus • But this is all we need …

  5. Last Time … • We looked at the parsing of empty NPs in relative clause constructions • Example: • the cat that I saw • the cati that I saw [NP ei] • (the cat)(lx.I saw x) By analogy: • that I saw [NP ei] has the semantics of lx.I saw x • This function returns x

  6. Last Time … • The rule that generated the empty category [NP ei] allowed for considerable overgeneration • Examples: • *Hit the ball [NP ei] hit the ball • *John hit John hit [NP ei] • *Hit [NP ei] hit [NP ei] • … 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 … • Filter: • All variables must be bound by an operator (lx) • Example: • *John hit s(np(john),vp(v(hit),np(x))) • Today’s Lecture: • How to implement this filter

  8. Condition on Representation • Basic Idea: • Scan phrase structure looking for a variable and operator • Succeed only if matching operator found • 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. s vp np np v John [3,sg] det n likes [3,sg] the man Condition on Representation • 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 P,N

  10. Tree-Walker • Question: • How to scan phrase structure tree? • Answer: • Write a recursive predicate, a tree-walker, to visit every node of a tree

  11. A vp B v np ran det n C the man Tree-Walker • Assuming phrase structure trees are binary branching at the most… • Tree-Walker must deal with three cases: • Binary branching visit both subtrees • Unary branching visit child subtree • Terminal node done

  12. A vp B v np ran det n C the man Tree-Walker X F=np A1 A2 • 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 X F=vp A

  13. s np vp v np john det n saw the man Tree-Walker • visit/1 example: • Inorder traversal 1 2 4 5 3 7 6 8 10 9 11

  14. Tree-Walker • visit/1 doesn’t really do anything yet • Need to add a specific test for np(x) • Example: • *John hit s(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) • 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). • visit(np(x)). • visit(X) :- • X =.. [F,A1,A2], • visit(A1), • visit(A2). • visit(X) :- • X =.. [F,A], • visit(A). • visit(X) :- atom(X). • Succeeds always • Succeeds only if np(x) exists

  16. Tree-Walker • New visit/1 example for *John hit [NPe]: s visit(X) fails visit(X) succeeds np vp v np john hit x

  17. Visit A1 and A2 Either visit A1 or A2 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(X) :- • X =.. [F,A1,A2], • visit(A2). • visit(X) :- • X =.. [F,A], • visit(A). • visit(np(x)). • visit(X) :- • X =.. [F,A1,A2], • visit(A1), • visit(A2). • visit(X) :- • X =.. [F,A], • visit(A). • visit(X) :- atom(X).

  18. Tree-Walker • 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 • Examples: • ?- variable(s(np(john),vp(v(hit),np(x)))). • Yes • ?- variable(s(np(john),vp(v(hit),np(mary)))). • No • ?-variable(np(np(det(the),n(cat)), • lambda(x,s(np(i),vp(v(saw),np(x)))))). • Yes

  19. Tree-Walker • Let’s build another modified version of visit/1 that succeeds only if there exists an operator lx, 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)))). • No • ?- operator(s(np(john),vp(v(hit),np(mary)))). • No • ?-operator(np(np(det(the),n(cat)), • lambda(x,s(np(i),vp(v(saw),np(x)))))). • Yes

  20. Filter Implementation • Filter: • All variables must be bound by an operator (lx) • 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: • ?- 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: • All variables must be bound by an operator (lx) • Implementation: • filter(X) :- variable(X), operator(X). • filter(X) :- \+ variable(X). • 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: • filter(X) :- variable(X) -> operator(X) ; true. • Advantage: one clause implementation instead of two … • 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

  23. Filter Implementation • Note: • filter(X) :- variable(X) -> operator(X) ; true. is only a first approximation implementation of • All variables must be bound by an operator (lx) • 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))) 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

More Related