LING 388 Language and Computers Lecture 18 10/30/03 Sandiway FONG.

Slides:



Advertisements
Similar presentations
Artificial Intelligence: Natural Language and Prolog
Advertisements

LING 388: Language and Computers
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.
 Christel Kemke 2007/08 COMP 4060 Natural Language Processing Feature Structures and Unification.
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 364: Introduction to Formal Semantics Lecture 24 April 13th.
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/C SC/PSYC 438/538 Lecture 22 Sandiway Fong 1.
LING 388: Language and Computers Sandiway Fong Lecture 2: 8/24.
LING 388: Language and Computers Sandiway Fong Lecture 15.
LING 364: Introduction to Formal Semantics Lecture 8 February 7th.
LING 438/538 Computational Linguistics Sandiway Fong Lecture 3: 8/29.
LING 438/538 Computational Linguistics Sandiway Fong Lecture 7: 9/12.
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 364: Introduction to Formal Semantics
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 20: 11/2.
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 364: Introduction to Formal Semantics Lecture 11 February 16th.
LING 388: Language and Computers Sandiway Fong Lecture 6: 9/7.
 Christel Kemke 2007/08 COMP 4060 Natural Language Processing Feature Structures and Unification.
LING 438/538 Computational Linguistics Sandiway Fong Lecture 6: 9/7.
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 364: Introduction to Formal Semantics Lecture 7 February 2nd.
LING 388 Language and Computers Lecture 20 11/6/03 Sandiway FONG.
LING 364: Introduction to Formal Semantics Lecture 3 January 19th.
LING 388: Language and Computers Sandiway Fong Lecture 17: 10/25.
LING 364: Introduction to Formal Semantics Lecture 13 February 23rd.
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 Sandiway Fong Lecture 4: 9/1.
LING 388 Language and Computers Lecture 13 10/14/03 Sandiway FONG.
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 15 10/21/03 Sandiway FONG.
LING 388: Language and Computers Sandiway Fong Lecture 8.
LING 388: Language and Computers Sandiway Fong 10/4 Lecture 12.
LING/C SC/PSYC 438/538 Lecture 19 Sandiway Fong 1.
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 4.
LING 388: Language and Computers Sandiway Fong Lecture 7.
LING 388: Language and Computers Sandiway Fong Lecture 6.
LING 388: Language and Computers Sandiway Fong Lecture 18.
LING 388: Language and Computers Sandiway Fong Lecture 10.
LING 388: Language and Computers Sandiway Fong Lecture 19.
LING 388: Language and Computers Sandiway Fong Lecture 13.
Semantic Construction lecture 2. Semantic Construction Is there a systematic way of constructing semantic representation from a sentence of English? This.
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 388: Language and Computers Sandiway Fong Lecture 20.
LING/C SC/PSYC 438/538 Lecture 19 Sandiway Fong 1.
LING/C SC/PSYC 438/538 Lecture 21 Sandiway Fong.
Presentation transcript:

LING 388 Language and Computers Lecture 18 10/30/03 Sandiway FONG

Administrivia Computer Laboratory next time as well … Computer Laboratory next time as well …  November 4th in SBS 224 Homework 4 Homework 4  3 exercises today  1 extra-credit question  Homework 4 continues next time Lecture 17 slides updated… Lecture 17 slides updated…  Added an appendix illustrating the use of negation to implement counting up to 2 instead of the extra argument method [from suggestion in class]

Exercise 1: Relative Clauses Examples: Examples:  The cat that John saw(object)  The cat that saw John(subject)

Exercise 1: Relative Clauses Sample DCG: Sample DCG:  s(s(X,Y)) --> np(X), vp(Y).  vp(vp(X,Y)) --> transitive_verb(X), np(Y).  np(np(X)) --> proper_noun (X). % Special rules for relative clauses  np(np(np(Y,Z),U)) --> det(Y), common_noun(Z), sbar(U).  np(np(x)) --> [].  sbar(lambda(x,Y)) --> complementizer, s(Y).  complementizer --> [that]. % Lexicon  transitive_verb(v(hit)) --> [hit]. transitive_verb(v(saw)) --> [saw].  proper_noun(john) --> [john]. proper_noun(mary) --> [mary].  common_noun(n(man)) --> [man]. common_noun(n(cat)) --> [cat].  det(det(the)) --> [the].

Exercise 1: Relative Clauses Consult DCG Consult DCG Parsing noun phrases (NPs): Parsing noun phrases (NPs):  Run queries  ?- np(X,[the,cat,that,john,saw],[]).  ?- np(X,[the,cat,that,saw,john],[]). Verify DCG also (incorrectly) accepts as NPs: Verify DCG also (incorrectly) accepts as NPs:  *The cat that John saw Mary  *The cat that saw

Exercise 1: Relative Clauses Pseudo-Logical Form for the cat that John saw: Pseudo-Logical Form for the cat that John saw: np det the n cat lambda xs np vp vjohn sawx

Exercise 1: Relative Clauses Homework Question (A): Homework Question (A):  Modify the DCG to accept the omission of the complementizer that for object relative clauses  Your DCG should accept both of the following:  the cat John saw  the cat that John saw as NPs  Hint:  Write an empty category rule in place of the complementizer

Exercise 1: Relative Clauses Parsing complete sentences: Parsing complete sentences:  Run queries:  ?- s(X,[mary,hit,the,cat,that,john,saw],[]).  ?- s(X,[mary,hit,the,cat,that,saw,john],[]). Verify the DCG also (incorrectly) accepts as sentences: Verify the DCG also (incorrectly) accepts as sentences:  *Mary hit  *hit John  *hit

Exercise 1: Relative Clauses Multiple Embeddings Multiple Embeddings  Add rule  transitive_verb(v(hissed_at)) --> [hissed,at].  Turn on full printing (taken from Lecture 4)  ?- set_prolog_flag(toplevel_print_options,[max_depth(0)]).  Run query for  Mary hit the man that the cat that John saw hissed at

Exercise 1: Relative Clauses Homework Question (B): Homework Question (B):  The previous sentence  Mary hit the man that the cat that John saw hissed at has a doubly-embedded object relative clause structure:  Mary hit [ NP [ NP the man i ] that [ NP [ NP the cat j ] that John saw [ NP e j ]] hissed at [ NP e i ]]

Exercise 1: Relative Clauses Homework Question (B) contd.: Homework Question (B) contd.:  Without any further modification to the DCG, construct and show parses for:  A sentence with two levels of embedding using subject relative clauses  A sentence with two levels of embedding using one subject and one object relative clause  Any sentence with a triply-embedded relative clause structure  Notes:  i.e. you cannot add any rules or words to the DCG so far  The DCG only allows Det N sequences in relative clause constructions, i.e. you have to make do without NP -> Det N

Extra Credit Homework Question Answer for Exercise 1 Part (A) will also allow the complementizer to be dropped (incorrectly) for subject relative clauses: Answer for Exercise 1 Part (A) will also allow the complementizer to be dropped (incorrectly) for subject relative clauses:  the cat that saw John  *the cat saw John(as a complex NP)

Extra Credit Homework Question Modify the DCG to allow that to be omitted only in the case of object relative clauses, i.e. grammar should still accept: Modify the DCG to allow that to be omitted only in the case of object relative clauses, i.e. grammar should still accept:  the cat John saw but reject its subject relative clause counterpart:  *the cat saw John Hint (for one possible implementation): Hint (for one possible implementation):  Look at how subject/verb agreement was enforced

Exercise 2: Disjunctive Tree-Walker Tree-walker template (disjunctive form): Tree-walker template (disjunctive form):  visit(X) :-  X =.. [_,A1,_],  visit(A1).  visit(X) :-  X =.. [_,_,A2],  visit(A2).  visit(X) :-  X =.. [_,A],  visit(A).  visit(X) :- atom(X). Note: Note:  used underscores to substitute for variables that are only mentioned once

Exercise 2: Disjunctive Tree-Walker Let’s modify visit/1 to look for John only: Let’s modify visit/1 to look for John only:  visit(X) :-  X =.. [_,A1,_],  visit(A1).  visit(X) :-  X =.. [_,_,A2],  visit(A2).  visit(X) :-  X =.. [_,A],  visit(A).  visit(X) :- atom(X).<- to be substituted by -visit(john).

Exercise 2: Disjunctive Tree-Walker Consult visit/1 Consult visit/1  Make sure DCG is still loaded ?- listing. to check Turn on tracing for visit/1 only Turn on tracing for visit/1 only  ?- spy(visit/1). Run the query: Run the query:  ?- s(X,[mary,hit,the,cat,that,hissed,at,john],[]), visit(X).  Step through debugger using the command l (leap)  Prolog should succeed and report X.

Exercise 2: Disjunctive Tree-Walker Test the structures for sentences: Test the structures for sentences:  Mary hit the cat that hissed at Mary  Query should fail  John saw the cat that saw John  Query should succeed twice

Exercise 2: Disjunctive Tree-Walker Homework Question: Homework Question:  Modify visit/1 to search for all NP nodes  How many times should visit/1 succeed for the following sentence?  Mary hit the cat that hissed at John Hint: Hint:  You’ll need to add more than one clause to visit/1

Exercise 3: Collecting Answers Instead of entering ; (possibly repeated) to the Prolog interpreter … Instead of entering ; (possibly repeated) to the Prolog interpreter …  we can used a higher-order predicate findall/3 to collect together all possible answers to a query findall/3 findall/3  Prolog build-in  Usage:  findall(X,Query,List) X may be a variable or constant or structure bound once per successful call to QueryX may be a variable or constant or structure bound once per successful call to Query Query is the Prolog query we wish to test (minus ?- and.)Query is the Prolog query we wish to test (minus ?- and.) List is the collected list of values of X per successful callList is the collected list of values of X per successful call

Exercise 3: Collecting Answers Example: Example:  male(john).  male(pete).  female(mary).  female(jill).  human(X) :- female(X) ; male(X).( ; indicates disjunction) Prolog query: Prolog query:  ?- human(X).  X = mary ;  X = jill ;  X = john ;  X = pete ;  No

Exercise 3: Collecting Answers Using findall/3: Using findall/3:  ?- findall(X,human(X),List).  X = _G283(an internally generated variable)  List = [mary,jill,john,pete] ;  No length/2 length/2  Prolog built-in  Usage:  length(List,N) List is a listList is a list N is bound to the number of elements in ListN is bound to the number of elements in List Example: Example:  ?- findall(X,human(X),List), length(List,N).  N = 4

Exercise 3: Collecting Answers Basic (unmodified) disjunctive tree-walker: Basic (unmodified) disjunctive tree-walker:  visit(X) :-  X =.. [_,A1,_],  visit(A1).  visit(X) :-  X =.. [_,_,A2],  visit(A2).  visit(X) :-  X =.. [_,A],  visit(A).  visit(X) :- atom(X).

Exercise 3: Collecting Answers Homework Question: Homework Question:  Assuming the unmodified version of visit/1  What does the query  ?- s(X,[mary,hit,the,cat,that,hissed,at,john],[]), findall(once,visit(X),L), findall(once,visit(X),L), length(L,N). length(L,N).do?