april 2010csa50061 logic, representation and inference simple question answering nl access to...

22
April 2010 CSA5006 1 Logic, Representation and Inference Simple Question Answering NL Access to Databases Semantics of Questions and Answers Simple Interpreters for Questions

Upload: cruz-gamage

Post on 19-Jan-2016

219 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: April 2010CSA50061 Logic, Representation and Inference Simple Question Answering NL Access to Databases Semantics of Questions and Answers Simple Interpreters

April 2010 CSA5006 1

Logic, Representation and Inference

Simple Question Answering• NL Access to Databases• Semantics of Questions and Answers• Simple Interpreters for Questions

Page 2: April 2010CSA50061 Logic, Representation and Inference Simple Question Answering NL Access to Databases Semantics of Questions and Answers Simple Interpreters

April 2010 CSA5006 2

Access to Databases:3 Possible Approaches

• Natural Language

• DB Query Language

• Form Interface

Page 3: April 2010CSA50061 Logic, Representation and Inference Simple Question Answering NL Access to Databases Semantics of Questions and Answers Simple Interpreters

April 2010 CSA5006 3

Natural Language

• How many countries are there in each continent?

• What is their average population?

Page 4: April 2010CSA50061 Logic, Representation and Inference Simple Question Answering NL Access to Databases Semantics of Questions and Answers Simple Interpreters

April 2010 CSA5006 4

SQL: DB Query Language

range of C is countriesrange of Cont is continentsrange of I is inclusionsretrieve(

Cont.name, count(C.name

where C.name = I.inside

and I.outside = Cont.name))

Page 5: April 2010CSA50061 Logic, Representation and Inference Simple Question Answering NL Access to Databases Semantics of Questions and Answers Simple Interpreters

April 2010 CSA5006 5

Form Interface

Page 6: April 2010CSA50061 Logic, Representation and Inference Simple Question Answering NL Access to Databases Semantics of Questions and Answers Simple Interpreters

April 2010 CSA5006 6

Issues• Accessibility

– Type of query language– What needs to be learned to make a query?– Data input vs. data output

• Flexibility– Can types of question be predicted?– Can types of question be easily changed?

• Expressivity– Limitations on kinds of information present– What types of query is possible

Page 7: April 2010CSA50061 Logic, Representation and Inference Simple Question Answering NL Access to Databases Semantics of Questions and Answers Simple Interpreters

April 2010 CSA5006 7

Chat 80 Pereira and Warren (1983)General Architecture

ENGLISH

LOGICAL FORM

PROLOG

ANSWER

Translation: what does the question mean

Planning: how shall I answer it

Execution: what is the answer?

Page 8: April 2010CSA50061 Logic, Representation and Inference Simple Question Answering NL Access to Databases Semantics of Questions and Answers Simple Interpreters

April 2010 CSA5006 8

Different Types of Sentence

Sentence Type Communicative Act

Declarative Sentence Assertion

Interrogative Sentence Question

Imperative Sentence Command

Page 9: April 2010CSA50061 Logic, Representation and Inference Simple Question Answering NL Access to Databases Semantics of Questions and Answers Simple Interpreters

April 2010 CSA5006 9

Sentences and Assertions

• Assertions are usually expressed by declarative sentences.

• Our grammar/lexicon deals with very simple examples , e.g. John saw Fido

• More complex declarative sentences includeAll candidates for CSA4050 failed.Candidates who fail more than four credits shall not be allowed to take resits.

Page 10: April 2010CSA50061 Logic, Representation and Inference Simple Question Answering NL Access to Databases Semantics of Questions and Answers Simple Interpreters

April 2010 CSA5006 10

Sentences and Questions

• Questions are usually expressed by interrogative sentences.

• Our simple grammar/lexicon does not yet deal with interrogative sentences.

• To handle them we must modify the grammar

• Issue: how do we recognise interrogative sentences?

Page 11: April 2010CSA50061 Logic, Representation and Inference Simple Question Answering NL Access to Databases Semantics of Questions and Answers Simple Interpreters

April 2010 CSA5006 11

Execution ofCommunicative Acts

• Assertions add information to the database.The meaning of a declarative sentence involves execution an appropriate assert operation

• Questions query information in the database.The meaning of an interrogative sentence involves execution of an appropriate query operation

• Commands identify actions to be carried out.• Representation of communicative act is in

addition to representation of content.

Page 12: April 2010CSA50061 Logic, Representation and Inference Simple Question Answering NL Access to Databases Semantics of Questions and Answers Simple Interpreters

April 2010 CSA5006 12

Representation of Communicative Acts

• Basic idea is to “wrap” the semantic content P in a special form to yield (P).

• In the following examples, has the general formca(<type>,<var>,<proposition>)

• The next two examples deal with – simple assertions and

– yes-no queries.

Page 13: April 2010CSA50061 Logic, Representation and Inference Simple Question Answering NL Access to Databases Semantics of Questions and Answers Simple Interpreters

April 2010 CSA5006 13

Assertions and Questions: Semantic Representation

Sentence Representation of Semantic Content

Representation of Communicative Act

John sees Fido

see(john,fido) ca(a1,_,see(john,fido))

Does John see Fido

see(john,fido) ca(q1,_,see(john,fido))

Page 14: April 2010CSA50061 Logic, Representation and Inference Simple Question Answering NL Access to Databases Semantics of Questions and Answers Simple Interpreters

April 2010 CSA5006 14

Basic Processing

process(Sent,Result) :-

s(SEM,Sent,[]),

interpret(SEM,Result).

In other words: to process the sentence:• Parse it to produce semantic representation SEM• Interpret SEM and give back RESULT• Next we must define the interpret predicate

Page 15: April 2010CSA50061 Logic, Representation and Inference Simple Question Answering NL Access to Databases Semantics of Questions and Answers Simple Interpreters

April 2010 CSA5006 15

Defining the Interpreter

interpret(ca(a1,_,A),Result) :-

mk_assertion(A,Result).

interpret(ca(q1,_,A),Result) :-

yes_no_query(A,Result).

Page 16: April 2010CSA50061 Logic, Representation and Inference Simple Question Answering NL Access to Databases Semantics of Questions and Answers Simple Interpreters

April 2010 CSA5006 16

Very Basic Intepretation

mk_assertion(SEM,ok) :- assert(SEM).

• In the case of an assertion, just assert it. N.B. no check for previous assertion.

yes_no_query(SEM,yes) :- call(SEM), !.

yes_no_query (SEM,no).• If it’s a yes-no question, see if it’s true

Page 17: April 2010CSA50061 Logic, Representation and Inference Simple Question Answering NL Access to Databases Semantics of Questions and Answers Simple Interpreters

April 2010 CSA5006 17

Dealing with Syntax

• We now have a primitive interpretation mechanism in place.

• It remains to modify the grammar/lexicon to handle the syntax of these very simple questions.

• To begin with, we will limit ourselves to yes/no questions

Page 18: April 2010CSA50061 Logic, Representation and Inference Simple Question Answering NL Access to Databases Semantics of Questions and Answers Simple Interpreters

April 2010 CSA5006 18

Yes/No Questions:Grammar Rules for S

% Declarative sentence

s --> np, vp.

Mia loves Vincent

% Interrogative sentence

s --> aux, np, vp.

does Mia love Vincent ?

Page 19: April 2010CSA50061 Logic, Representation and Inference Simple Question Answering NL Access to Databases Semantics of Questions and Answers Simple Interpreters

April 2010 CSA5006 19

Grammar Rules with Semantics (Blackburn)

% Declarative sentences(app(NP,VP)) --> np(NP), vp(VP). Mia loves Vincent

np(app(DET,N)) --> det(NP), noun(N). this car

Page 20: April 2010CSA50061 Logic, Representation and Inference Simple Question Answering NL Access to Databases Semantics of Questions and Answers Simple Interpreters

April 2010 CSA5006 20

Grammar Rules with Pragmatics

% Declarative sentences(ca(a1,_app(NP,VP))) --> np(NP), vp(VP). Mia loves Vincent

np(app(DET,N)) --> det(NP), noun(N). this car

Page 21: April 2010CSA50061 Logic, Representation and Inference Simple Question Answering NL Access to Databases Semantics of Questions and Answers Simple Interpreters

April 2010 CSA5006 21

Demo

?- process([does,vincent,love,mia],A).A=no

?- process([vincent,loves,mia],A).A=ok

?- process([does,vincent,love,mia],A).A=yes

Page 22: April 2010CSA50061 Logic, Representation and Inference Simple Question Answering NL Access to Databases Semantics of Questions and Answers Simple Interpreters

April 2010 CSA5006 22

Improving the Interpreter

dbq :- readLine(L), dbq1(L), !, dbq.dbq.

dbq1([halt]) :- nl, write(bye), !, fail.dbq1(Sent) :- process(Sent,A).