LING 388 Language and Computers Lecture 20 11/6/03 Sandiway FONG.

Slides:



Advertisements
Similar presentations
Artificial Intelligence: Natural Language and Prolog
Advertisements

Artificial Intelligence 8. The Resolution Method
Some Prolog Prolog is a logic programming language
Computational Semantics Aljoscha Burchardt, Alexander Koller, Stephan Walter, Universität des Saarlandes,
Review of Homework 4 November 20, Exercise 1 (A) 1 pt Modify the DCG to accept the omission of the complementizer that for object relative clauses.
CSA2050: DCG I1 CSA2050 Introduction to Computational Linguistics Lecture 8 Definite Clause Grammars.
LING 388: Language and Computers Sandiway Fong Lecture 5: 9/5.
LING 388: Language and Computers Sandiway Fong Lecture 5: 9/8.
CSA4050: Advanced Topics in NLP Semantics IV Partial Execution Proper Noun Adjective.
LING/C SC/PSYC 438/538 Computational Linguistics Sandiway Fong Lecture 13: 10/9.
LING 388: Language and Computers Sandiway Fong Lecture 28 12/1.
For Monday Read Chapter 23, sections 3-4 Homework –Chapter 23, exercises 1, 6, 14, 19 –Do them in order. Do NOT read ahead.
LING 388: Language and Computers Sandiway Fong Lecture 9: 9/22.
LING 438/538 Computational Linguistics Sandiway Fong Lecture 7: 9/12.
LING/C SC/PSYC 438/538 Computational Linguistics Sandiway Fong Lecture 10: 9/27.
LING 364: Introduction to Formal Semantics Lecture 10 February 14th.
LING 388 Language and Computers Lecture 2 9/04/03 Sandiway FONG.
LING 364: Introduction to Formal Semantics Lecture 9 February 9th.
LING 388 Language and Computers Lecture 19 11/04/03 Sandiway FONG.
LING 438/538 Computational Linguistics Sandiway Fong Lecture 9: 9/21.
LING 388: Language and Computers Sandiway Fong Lecture 15: 10/17.
LING 388 Language and Computers Lecture 14 10/16/03 Sandiway FONG.
LING 388 Language and Computers Lecture 8 9/25/03 Sandiway FONG.
LING 388: Language and Computers Sandiway Fong Lecture 28: 12/6.
LING 364: Introduction to Formal Semantics Lecture 4 January 24th.
LING 388: Language and Computers Sandiway Fong Lecture 14: 10/13.
LING/C SC/PSYC 438/538 Computational Linguistics Sandiway Fong Lecture 9: 9/25.
LING 388: Language and Computers Sandiway Fong Lecture 6: 9/13.
LING 388: Language and Computers Sandiway Fong Lecture 11: 10/3.
LING 388 Language and Computers Lecture 10 10/2/03 Sandiway FONG.
LING 388 Language and Computers Take-Home Final Examination 12/9/03 Sandiway FONG.
LING 438/538 Computational Linguistics Sandiway Fong Lecture 12: 10/5.
LING 364: Introduction to Formal Semantics Lecture 7 February 2nd.
LING 388 Language and Computers Lecture 18 10/30/03 Sandiway FONG.
LING 388: Language and Computers Sandiway Fong Lecture 17: 10/25.
LING 388 Language and Computers Lecture 16 10/23/03 Sandiway FONG.
LING 388: Language and Computers Sandiway Fong Lecture 16: 10/19.
LING 388 Language and Computers Lecture 13 10/14/03 Sandiway FONG.
LING 388: Language and Computers Sandiway Fong Lecture 17: 10/24.
LING 364: Introduction to Formal Semantics Lecture 5 January 26th.
LING 388 Language and Computers Lecture 17 10/28/03 Sandiway FONG.
LING 388: Language and Computers Sandiway Fong Lecture 13: 10/10.
LING 388 Language and Computers Lecture 12 10/9/03 Sandiway FONG.
LING 388 Language and Computers Lecture 6 9/18/03 Sandiway FONG.
LING 388 Language and Computers Lecture 15 10/21/03 Sandiway FONG.
LING 388: Language and Computers Sandiway Fong 10/4 Lecture 12.
LING/C SC/PSYC 438/538 Lecture 19 Sandiway Fong 1.
October 2004csa4050: Semantics II1 CSA4050: Advanced Topics in NLP Semantics II The Lambda Calculus Semantic Representation Encoding in Prolog.
LING 388: Language and Computers Sandiway Fong Lecture 14 10/11.
LING 388: Language and Computers Sandiway Fong Lecture 17.
LING 388: Language and Computers Sandiway Fong Lecture 27.
LING 388: Language and Computers Sandiway Fong Lecture 22: 11/10.
LING 388: Language and Computers Sandiway Fong Lecture 4.
For Friday Finish chapter 23 Homework: –Chapter 22, exercise 9.
LING 388: Language and Computers Sandiway Fong Lecture 7.
LING/C SC/PSYC 438/538 Lecture 14 Sandiway Fong. Administrivia Midterm – This Wednesday – A bit like doing a homework in real time – Bring your laptop.
LING 388: Language and Computers Sandiway Fong Lecture 10.
October 2004CSA4050: Semantics III1 CSA4050: Advanced Topics in NLP Semantics III Quantified Sentences.
LING 388: Language and Computers Sandiway Fong Lecture 13.
For Wednesday Read chapter 23 Homework: –Chapter 22, exercises 1,4, 7, and 14.
1 Predicate (Relational) Logic 1. Introduction The propositional logic is not powerful enough to express certain types of relationship between propositions.
LING 388: Language and Computers Sandiway Fong Lecture 12.
LING 388: Language and Computers Sandiway Fong Lecture 11: 10/4.
Rules, Movement, Ambiguity
LING 388: Language and Computers Sandiway Fong Lecture 25.
LING 388: Language and Computers Sandiway Fong Lecture 16.
LING/C SC/PSYC 438/538 Lecture 19 Sandiway Fong 1.
Propositional and predicate logic
Natural Language Processing
LING/C SC/PSYC 438/538 Lecture 21 Sandiway Fong.
Presentation transcript:

LING 388 Language and Computers Lecture 20 11/6/03 Sandiway FONG

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

Homework 3 Review

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. Add a DCG rule to encode the idiomatic meaning of John kicked the bucket, i.e. s npvp v died john ?- 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].

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].

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

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: Solution:  Write one rule specialized for every and another for some

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: 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) everyman

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: 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

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: 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)) … The same implementation strategy works also for some and exists(X,N(X)) …

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

Homework 4 Concepts

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

Logic and Negation in Prolog np det the n cat lambda xs np vp vjohn sawx np vp v hissed atx s *The cat that John saw hissed at *The cat that John saw hissed at

Logic and Negation in Prolog Example: Example:  All tomatoes are red Define predicates: Define predicates:tomato(X)red(X) Condition: 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

Logic and Negation in Prolog Example: Example:  All tomatoes are red Equivalent condition: Equivalent condition:  It cannot be the case that there exists some tomato and that tomato is not red Implementation: 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

Logic and Negation in Prolog Basic Quantifier Conversion Rules: 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 ( 

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

Implementing the Exactly One Condition In Exercise 5 … 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 x.Y with less than two variables in Yholds if X contains a x.Y with less than two variables in Y

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

Implementing the Universally Quantified Condition Not done yet … 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 x.Y with less than two variables in Yholds if X contains a x.Y with less than two variables in Y I.e. if in X  x.Y with less than two variables in YI.e. if in X  x.Y with less than two variables in Y

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

Overlapping/Non-Overlapping Clauses Question: 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: Example:  operator/1 is overlapping  lt2vars/2 is non-overlapping

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). np(x) Unary branching structure: Unary branching structure: matches two clauses blocks np(x) Want only one match!

Case 1: Non-Overlapping Clauses np(x) Need to block the lower clause from applying Need to block the lower clause from applying it does not set F, and otherwise 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.]  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 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). lambda(x,_) Binary branching structure: Binary branching structure: matches three clauses Want multiple matches!

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). lambda(x,_) operator/1 is a x finder We want it to be able to find and test all x structures within a phrase structure We want it to be able to find and test all x structures within a phrase structure ?- operator(X). will succeed once for each x in X ?- operator(X). will succeed once for each x in X

np det the n cat lambda xs np vp vjohn sawmary np vp v hissed atx lambda xs *Mary hit the man that the cat that John saw Mary hissed at *Mary hit the man that the cat that John saw Mary hissed at Case 2 np det the n man vp v hit s np mary first x

np det the n cat lambda xs np vp vjohn sawmary np vp v hissed atx lambda xs *Mary hit the man that the cat that John saw Mary hissed at *Mary hit the man that the cat that John saw Mary hissed at Case 2 np det the n man vp v hit s np mary first x

Key Concept We need to restrict or use overlap as appropriate 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