1 / 30

LING 388 Language and Computers

LING 388 Language and Computers. Lecture 20 11/6 /03 Sandiway FONG. Administrivia. Next Tuesday (11th) Veterans’ Day Today’s Lecture Homework 3 review Help with Homework 4 Next time … We start a brand-new topic known as Shallow Parsing

uta
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 20 11/6/03 Sandiway FONG

  2. Administrivia • Next Tuesday (11th) • Veterans’ Day • Today’s Lecture • Homework 3 review • Help with Homework 4 • Next time … • We start a brand-new topic known as Shallow Parsing • We’ll begin with Part-of-speech (POS) tagging, stemming …

  3. Homework 3 Review

  4. np vp v john died Exercise 1 Part (B): Encoding the idiom kick the bucket • Add a DCG rule to encode the idiomatic meaning of John kicked the bucket, i.e. s ?- s(X,[john,kicked,the,bucket],[]) X = s(np(john),vp(v(died))) • Hint: see how the terminal string the ball was encoded in Lecture 10 np --> [the,ball].

  5. Sample DCG • s(s(X,Y)) --> np(X), vp(Y). • np(np(X,Y)) --> det(X,Num), common_noun(Y,Num). • np(np(X)) --> proper_noun(X). • vp(vp(X)) --> intransitive_verb(X). • vp(vp(X,Y)) --> transitive_verb(X), np(Y). • common_noun(n(man),sg) --> [man]. • common_noun(n(men),sg) --> [men]. • proper_noun(john) --> [john]. • det(det(the),_) --> [the]. det(det(a),sg) --> [a]. • intransitive_verb(v(ran)) --> [ran]. • transitive_verb(v(saw)) --> [saw].

  6. Exercise 4 Part (A): Implementing every and some • Want parses: • s(forall(X,man(X)),vp(v(likes),np(john)))) • s(exists(X,men(X)),vp(v(like),np(n(beer)))) • for • Every man likes John • Some men like beer

  7. Exercise 4 Part (A): Implementing every and some • NP rules: • np(np(X,Y)) --> quantifier(X,Num), common_noun(Y,Num). • quantifier(q(every),sg) --> [every]. • quantifier(q(some),_) --> [some]. • common_noun(n(man),sg) --> [man]. • common_noun(n(men),pl) --> [men]. • Solution: • Write one rule specialized for every and another for some

  8. Exercise 4 Part (A): Implementing every and some • Case 1: every • np(np(X,Y)) --> quantifier(X,Num), common_noun(Y,Num). • quantifier(q(every),sg) --> [every]. • common_noun(n(man),sg) --> [man]. • Parsing every man will produce the following series of variable bindings: np(np(X,Y)) --> quantifier(X,Num), common_noun(Y,Num). quantifier(q(every),sg) common_noun(n(man),sg) every man

  9. Exercise 4 Part (A): Implementing every and some • Perform a partial substitution; instantiate every: • np(np(X,Y)) --> • quantifier(q(every),Num), • common_noun(n(N),Num). • Note: • NP rule is now particular to sequences every N • I.e. NP rule won’t fire for other NP sequences like: • some men • the cat • John

  10. Exercise 4 Part (A): Implementing every and some • Substitute forall for np: • np(forall(X,Y)) --> • quantifier(q(every),Num), • common_noun(n(N),Num). • Finally, add code in {…} to generate Y from N: • np(forall(X,Y)) --> • quantifier(q(every),Num), • common_noun(n(N),Num), • {Y=..[N,X]}. • The same implementation strategy works also for some and exists(X,N(X)) …

  11. Key Concepts • Use partial variable substitution • … to customize a rule • We can build f(X) where f cannot be determined statically, i.e. at the time we specify the grammar rule by … • using Prolog built-in univ (=..), and • the DCG rule out-call mechanism {…}

  12. Homework 4 Concepts

  13. Logic and Negation in Prolog • Filter 1: • All variables must be bound by an operator • Implementation: • \+ (variable(X,F), var(F)) • variable/2 is an np(x) finder • F bound when lx can be found • Question: • Why are we implementing a positive condition using negation (\+)?

  14. Logic and Negation in Prolog s np vp np lambda v np n det x s hissed at x cat the np vp • *The cat that John saw hissed at john v np saw x

  15. Logic and Negation in Prolog • Example: • All tomatoes are red • Define predicates: tomato(X) red(X) • Condition: • ?- tomato(X), red(X). • holds if there exists some X such that X is a tomato and X is red • Doesn’t check all the tomatoes in the box • Hence, query does not guarantee that all the tomatoes in the box are red

  16. Logic and Negation in Prolog • Example: • All tomatoes are red • Equivalent condition: • It cannot be the case that there exists some tomato and that tomato is not red • Implementation: • ?- \+ ( tomato(X), \+ red(X)). • holds if it is not the case that there exists some X such that X is a tomato and X is not red • Guarantees that all the tomatoes in the box are red

  17. Logic and Negation in Prolog • Basic Quantifier Conversion Rules: • "x p(x) <=> Ø$x Øp(x) • Ø$x p(x) <=> "x Øp(x) • Examples: • "X tomato(X), red(X) • <=> Ø$X tomato(X), \+ red(X) • Prolog variables? • By default, existentially quantified ($)

  18. Logic and Negation in Prolog • Filter 1: • All variables must be bound by an operator • Conversion: • There must not exist a variable that is not bound by an operator • Implementation: • \+ (variable(X,F), var(F)) • variable/2 is an np(x) finder • F bound when lx can be found

  19. Implementing the Exactly One Condition • In Exercise 5 … • Filter 2: • All operators must bind exactly one variable • Implementation: • filter2(X) :- operator(X). • Predicate: • operator(X) • holds if X contains a lx.Y with less than two variables in Y

  20. Implementing the Exactly One Condition • Operator/1 calls predicate lt2vars/2: • lt2vars(X,F) • holds if there are less than two variables in X • F is bound to one if there is one variable in X • We’ll need to impose either that: • F == one or • \+ var(F) to the output of lt2vars/2 to implement the condition for exactly one variable

  21. Implementing the Universally Quantified Condition • Not done yet … • Filter 2: • All operators must bind exactly one variable • Implementation: • filter2(X) :- operator(X). • Predicate: • operator(X) • holds if X contains a lx.Y with less than two variables in Y • I.e. if in X $ lx.Y with less than two variables in Y

  22. Implementing the Universally Quantified Condition • Filter 2: • All operators must bind exactly one variable • So we must convert this to an existentially quantified condition • Equivalently: • In X, it cannot be the case that operator(X) holds and the number of variables bound is not one

  23. Overlapping/Non-Overlapping Clauses • Question: • For tree-walkers, why do we sometimes want overlapping clauses, i.e. have more than one applicable clause, and why sometimes we don’t? • Example: • operator/1 is overlapping • lt2vars/2 is non-overlapping

  24. Case 1: Non-Overlapping Clauses • lt2vars(np(x),F) :- • var(F), F = one. • lt2vars(X,F) :- • X =.. [_,A1,A2], • lt2vars(A1,F), • lt2vars(A2,F). • lt2vars(X,F) :- • \+ X = np(x), • X =.. [_,A], • lt2vars(A,F). • lt2vars(X,_) :- atom(X). • Unary branching structure: np(x) matches two clauses blocks np(x) Want only one match!

  25. lt2vars(np(x),F) :- • var(F), F = one. • lt2vars(X,F) :- • X =.. [_,A1,A2], • lt2vars(A1,F), • lt2vars(A2,F). • lt2vars(X,F) :- • \+ X = np(x), • X =.. [_,A], • lt2vars(A,F). • lt2vars(X,_) :- atom(X). Case 1: Non-Overlapping Clauses np(x) • Need to block the lower clause from applying • it does not set F, and otherwise • ?- lt2vars(X,F), var(F). • will succeed when X has, say, three np(x)s [Upper clause will reject 3 np(x)s, but lower clause will pass it.]

  26. Case 2: Overlapping Clauses • operator(lambda(x,Y)):- • lt2vars(Y,_). • operator(X) :- • X =.. [_,A1,_], • operator(A1). • operator(X) :- • X =.. [_,_,A2], • operator(A2). • operator(X) :- • X =.. [F,A], • operator(A). • Binary branching structure: lambda(x,_) matches three clauses Want multiple matches!

  27. Case 2: Overlapping Clauses lambda(x,_) • operator(lambda(x,Y)):- • lt2vars(Y,_). • operator(X) :- • X =.. [_,A1,_], • operator(A1). • operator(X) :- • X =.. [_,_,A2], • operator(A2). • operator(X) :- • X =.. [F,A], • operator(A). • operator/1 is a lx finder • We want it to be able to find and test all lx structures within a phrase structure • ?- operator(X). will succeed once for each lx in X

  28. s vp np Case 2 first lx np v mary np lambda hit x s det n np vp the man np lambda v np n det x s hissed at x cat the np vp • *Mary hit the man that the cat that John saw Mary hissed at john v np saw mary

  29. s vp np Case 2 first lx np v mary np lambda hit x s det n np vp the man np lambda v np n det x s hissed at x cat the np vp • *Mary hit the man that the cat that John saw Mary hissed at john v np saw mary

  30. Key Concept • We need to restrict or use overlap as appropriate • Because of Prolog’s search strategy • i.e. if a clause fails during a query, Prolog will look for another way to succeed

More Related