Top Banner
Abductive reasoning and language analysis with Prolog and Constraint Handling Rules Tilburg School of Humanities, March 1, 2012 Henning Christiansen professor of Computer Science Research group PLIS: Programming, Logic and Intelligent Systems Department of Communication, Business and Information Technologies Roskilde University P.O.Box 260, DK-4000 Roskilde, DENMARK http://www.ruc.dk/~henning, [email protected] Coordinator for international student exchanges: • Computer Science • Informatics • Humanities-Technology Studies
33

Abductive reasoning and language analysis with Prolog and Constraint Handling Rules Tilburg School of Humanities, March 1, 2012 Henning Christiansen professor.

Dec 28, 2015

Download

Documents

Stewart Gregory
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Abductive reasoning and language analysis with Prolog and Constraint Handling Rules Tilburg School of Humanities, March 1, 2012 Henning Christiansen professor.

Abductive reasoning and language analysis with Prologand Constraint Handling Rules

Tilburg School of Humanities, March 1, 2012

Henning Christiansenprofessor of Computer Science

Research group PLIS: Programming, Logic and Intelligent Systems

Department of Communication, Business and Information Technologies

Roskilde University

P.O.Box 260, DK-4000 Roskilde, DENMARK

http://www.ruc.dk/~henning, [email protected]

Coordinator for international student exchanges:• Computer Science• Informatics• Humanities-Technology Studies

Page 2: Abductive reasoning and language analysis with Prolog and Constraint Handling Rules Tilburg School of Humanities, March 1, 2012 Henning Christiansen professor.

2

About the speaker

Research, teaching, management in Computer Science since 1980ies full prof. at Roskilde from 2004

Research interests– Initially Programming languages (compilers, denotation semantics, ...)– Logic and constraint programming, probabilistic extensions

• applied for AI, language analysis, NLP, reasoning, bioinformatics

– Formal linguistics, language evolution– Logical aspects of databases– Emerging Interactive installations, context comprehension, virtual characters

Recent projects– “Constraints for Robust Language Processing” (2004–8)– “Logic-Statistical analysis of biological sequence data” (2007–2012)

Conferences and workshop involvements– FQAS, Int’l Conf. on Flexible Query Answering Systems– CONTEXT, Int’l Conf. on Modelling and Using Context– CSLP, Int’l Workshop on Constraint Solving and Language Processing

Page 3: Abductive reasoning and language analysis with Prolog and Constraint Handling Rules Tilburg School of Humanities, March 1, 2012 Henning Christiansen professor.

3

Motivation & intuition

Logic programming in teaching for a variety of students

• Logic progr. in Prolog is simple, intuitive, easy to learn

• Programs are formal specification

• Programs are easy to write and test

• You can do logic without being a mathematician • You can even program without being a programmer

My approach: Involving constraints logic program

• An easy way to semantics/pragmatics in language analysis

• Provides abductive reasoning for diagnosis, etc.

• while keeping the qualities of Prolog programming

Page 4: Abductive reasoning and language analysis with Prolog and Constraint Handling Rules Tilburg School of Humanities, March 1, 2012 Henning Christiansen professor.

4

Outline of this talk1. Crash course on Prolog programming

2. Definite Clause Grammars, DCGs (add-on to Prolog)

3. Constraint Handling Rules, CHR (another add-on to Prolog)

4. Relation to Abductive Reasoning

5. Using CHR for to add meanings to DCGs

6. A practical application (sketch)

7. Related research and future direction

8. A little extra: The Experience Cylinder

• Approach won’t solve all problems, but good for illustrative purposes,• for teaching,• (prototype) applications• and (not least) fun to play with and to learn from!

Page 5: Abductive reasoning and language analysis with Prolog and Constraint Handling Rules Tilburg School of Humanities, March 1, 2012 Henning Christiansen professor.

A crash course on PrologProlog differs from Java, C, etc.:• based on logic

– focuses on "what" rather that "how"– programs are concise compact and (often) more intuitive– rule-based: programs can be tested and built incrementally

• symbols and structure (rather that numbers)• very easy to learn!

History• A.Colmerauer & co. (Marseille), ca. 1970: "Prolog"• D.H.D. Warren: Efficient compiler, 1975• Book: R.Kowalski "Logic for Problem solving", 1979, ....• Since then: several available systems

5

Page 6: Abductive reasoning and language analysis with Prolog and Constraint Handling Rules Tilburg School of Humanities, March 1, 2012 Henning Christiansen professor.

Program is a description of data

parent( tom, bob).

parent( tom, liz).

parent( bob, ann).

parent( bob, pat).

parent( pat, jim).

parent( pam, bob). % Pam is a parent of Bob

pam tom

bob liz

ann pat

jim

Page 7: Abductive reasoning and language analysis with Prolog and Constraint Handling Rules Tilburg School of Humanities, March 1, 2012 Henning Christiansen professor.

Basic notions:

• predicates: parent– describes a relation– defined by facts, rules, collectively called clauses

• constants: tom, bob, x, y• variables: X, Y, Tom• simple goals: parent(A,a)• Queries....

Page 8: Abductive reasoning and language analysis with Prolog and Constraint Handling Rules Tilburg School of Humanities, March 1, 2012 Henning Christiansen professor.

Queries

Atomic queries

?- parent(X,Y).

... give me values of X and Y so parent(X,Y) logically follows from program

Compound query

?- parent(pam, X), parent(X, Y).

... give me X and Y, so that...

Page 9: Abductive reasoning and language analysis with Prolog and Constraint Handling Rules Tilburg School of Humanities, March 1, 2012 Henning Christiansen professor.

Procedural semantics

parent( pam, bob).

parent( tom, bob).

parent( tom, liz).

parent( bob, ann).

parent( bob, pat).

parent( pat, jim).

?- parent(pam, X), parent(X, Y).

X=bob

?- parent(bob, Y).

Y=ann

Success!Other solutions?

Y=pat Success!Other Solutions?

No more solutionswith X=bob :/

No more possiblesolutions at all

• Unification term=term?

• from left to right

• from start to end

• backtracking

≈ undo and try new choices

Page 10: Abductive reasoning and language analysis with Prolog and Constraint Handling Rules Tilburg School of Humanities, March 1, 2012 Henning Christiansen professor.

Rules

grandparent(X,Z):- parent(X, Y), parent(Y, Z).

Procedural semantics

as before + rewrite subgoal using rules

Declarative semantics ≈ logical consequence in 1st order logic

The nice property:

procedural ≈ declarative

Other features

• structures and lists (will see later)

• control mechanisms (advanced; not needed for today)

Page 11: Abductive reasoning and language analysis with Prolog and Constraint Handling Rules Tilburg School of Humanities, March 1, 2012 Henning Christiansen professor.

11

Definite Clause Grammars

Syntactic sugar for Prolog programs that perform top-down, backtracking parsing.

In Prolog since 1970ies [Colmerauer; Pereira, Warren; ...]

Features ≈ arguments and terms as in Prolog predicates

Example:

Popular, easy to work with, fun to play with, etc.

?- [simpleDCG].

Page 12: Abductive reasoning and language analysis with Prolog and Constraint Handling Rules Tilburg School of Humanities, March 1, 2012 Henning Christiansen professor.

12

Adding contexts ≈ knowledge bases

Usual approach: more and complex features.

Discourse analysis with semantics

story(C0,M1+M2) --> s(C0,C1,M1), ['.'], story(C1,M2) ; [].

We try something different: use a global resource to store context and meanings.

Thus stay with the rule

story --> s, ['.'], story ; [].

But “global resource” in Prolog??= constraint store and meanings etc. as constraints...

Page 13: Abductive reasoning and language analysis with Prolog and Constraint Handling Rules Tilburg School of Humanities, March 1, 2012 Henning Christiansen professor.

13

Constraint Handling Rules, CHR

A recent addition to Prolog; available in several major Prologs [Frühwirth, 1992, 1998]

A “glass box” approach to constraint solving:• defining constraints and their behaviour in a

declarative language

Prolog: Backward chaining

CHR: Forward chaining

Prolog+CHR by an example that anticipates applications for reasoning and language analysis...

?- [happy1]. ?- [happy2]. ?- [happy3].

Page 14: Abductive reasoning and language analysis with Prolog and Constraint Handling Rules Tilburg School of Humanities, March 1, 2012 Henning Christiansen professor.

14

Theoretical interlude:

You have just seen an implementation of Abductive Reasoning using Prolog+CHR (C.S. Peirce, 18-something); (Conan Doyle, 19-something - Sherlock Holmes); Kakas, Kowalski, etc. (1980ies, ......)

Compared with other approaches to Abductive Logic Programming• Most efficient of known approaches: Uses existing tehnology directly;

no interpretational overhead• Accessible, easy to use• Limited support of negation

Relationship Abduction <-> CHR:

[S.Abdennadher, HC, 2000; HC, V.Dahl, 2004, etc.]

H.Christiansen. Executable specifications for hypothesis-based reasoning with Prolog and Constraint Handling Rules, Journal of Applied Logic, 2009.

Page 15: Abductive reasoning and language analysis with Prolog and Constraint Handling Rules Tilburg School of Humanities, March 1, 2012 Henning Christiansen professor.

15

Back to CHR

Three kinds of rules:

Propagatec, c, ..., c ==> Guard | ... c ...

adds constraints

Simplify c, c, ..., c <=> Guard | ... c ...

replaces constraints

Simpagate c, ... \ c, ... <=> Guard | ... c ...

remove some, keep some and add others

———————————————————————

Declarative semantics: as indicated by the arrow shapes

Theorem: Our implementation of abduction is correct :)

Page 16: Abductive reasoning and language analysis with Prolog and Constraint Handling Rules Tilburg School of Humanities, March 1, 2012 Henning Christiansen professor.

16

Back to discourse analysis

First version, just collecting facts

Second version, adding rules about semantic/pragmatic universe

—————————————————————————————Reflections:• An instance of “Interpretation of abduction”, [Hobbs & al, 1993]• Notice that distinction semantics/pragmatics disappears, i.e.,

– i.e., no “objective and context independent” meaning before mapping to “real world objects”,

• [Christiansen, Dahl, Context05] formalize “Meaning in Context” with possible-worlds semantics and relate to abduction and CHR

?- [discourse1].

?- [discourse2].

Page 17: Abductive reasoning and language analysis with Prolog and Constraint Handling Rules Tilburg School of Humanities, March 1, 2012 Henning Christiansen professor.

17

An practical application (sketch)

Mapping use case text (a la OOP/OOD) into UML diagrams

Example of discourse analysis, building a

knowledge base ≈ context ≈ constraint store

Features:• non-trivial properties of semantic/pragmatic universe• resolution of pronouns based on well-defined heuristics

[Christiansen, Have, Tveitane, RANLP2007, CSLP2007]

Page 18: Abductive reasoning and language analysis with Prolog and Constraint Handling Rules Tilburg School of Humanities, March 1, 2012 Henning Christiansen professor.

The setting...

• Use Cases– Textual examples of what an IT system does without

specifying how.– Used in the inception phase of the object oriented software

development process.

• Restricted English language, unambiguous meaning but preserving natural flow

• Interpretation as abduction by DCG+CHR:– extract “programmatic semantics”– Build knowledge base as Constraint store ≈ abducibles– Result: Diagrammatic representation (UML)

Page 19: Abductive reasoning and language analysis with Prolog and Constraint Handling Rules Tilburg School of Humanities, March 1, 2012 Henning Christiansen professor.

Overview of the process by example

Use case text: “The professor teaches.”

class(professor)method(professor, teach)

Abductive analysiswith DCG+CHR

A little code that exports to GraphViz

Page 20: Abductive reasoning and language analysis with Prolog and Constraint Handling Rules Tilburg School of Humanities, March 1, 2012 Henning Christiansen professor.

Several classes and methodsUse case text: “A student reads, writes projects and takes exams.”

class(student)class(project)class(exam)method(student, read)method(student, write(project))method(student, take(exam))

Page 21: Abductive reasoning and language analysis with Prolog and Constraint Handling Rules Tilburg School of Humanities, March 1, 2012 Henning Christiansen professor.

Classes and properties

Use case text: “A professor has an office.”

class(professor)class(office)property(professor,office:1)

Page 22: Abductive reasoning and language analysis with Prolog and Constraint Handling Rules Tilburg School of Humanities, March 1, 2012 Henning Christiansen professor.

Classes and inheritance

Use case text: “Students and professors are persons.”

class(professor)class(student)class(person)extends(professor, person)extends(student, person)

Page 23: Abductive reasoning and language analysis with Prolog and Constraint Handling Rules Tilburg School of Humanities, March 1, 2012 Henning Christiansen professor.

sentence --> fc_noun_phrase(Number,_ , subj, IdSub), subord_verb(Number,_ ), fc_noun_phrase(_ , Number, obj, IdObj), {extends(IdSub,IdObj)}.

There are sentence grammar rules like this for different sentence types Each rule captures the semantic features of a particular type of sentence

fc_ “cats and dogs” cat+dogindiv_ “her, Peter and Paul” mary+peter+paulrc_ “Mary and the boys” woman+boyq_ “a tail and some legs” tail:1+legs:n

Example of a grammar rule

Page 24: Abductive reasoning and language analysis with Prolog and Constraint Handling Rules Tilburg School of Humanities, March 1, 2012 Henning Christiansen professor.

Semantic rules in CHR, I

extends(A+B, C) <=> extends(A,C), extends(B,C).

extends(A, B+C) <=> extends(A, B), extends(A, C).

Example:“Professors and students are persons.”

extends(professor+student, person)

extends(professor, person)extends(student, person)

extends(professor, teacher+researcher)

Example:“A professor is a teacher and a researcher.”

extends(professor, teacher)extends(professor, researcher)

Rule: Rule:

Sample constraint store: Sample constraint store:

Page 25: Abductive reasoning and language analysis with Prolog and Constraint Handling Rules Tilburg School of Humanities, March 1, 2012 Henning Christiansen professor.

Semantic rules in CHR, II

property(C,P:N), property(C,P:M) <=> q_count(N), q_count(M), q_less_eq(N,M) | property(C,P:(N..M)).

Example: “Paul has a dog and Peter has five dogs.” (Peter and Paul known to be men).

...property(man, dog:1)property(man, dog:5)

Rule:

property(man, dog:(1..5))

Sample constraint store:

Page 26: Abductive reasoning and language analysis with Prolog and Constraint Handling Rules Tilburg School of Humanities, March 1, 2012 Henning Christiansen professor.

Semantic rules in CHR, IIIRanges can be merged

property(C,P:(N1..M1)),property(C,P:(N2..M2)) <=> q_min(N1,N2,N), q_max(M1,M2,M), property(C,P:(N..M)).

property(man, dog:(0..2))property(man, dog:(1..n)) property(man, dog:(0..n))

Rule:

Sample constraint store:

Page 27: Abductive reasoning and language analysis with Prolog and Constraint Handling Rules Tilburg School of Humanities, March 1, 2012 Henning Christiansen professor.

Semantic rules in CHR, IV (anaphora, i) Individuals as prototypes

Example: “John is a student. John studies.”

class(student)object(john, student)method(john, study)

class(student)object(john, student)method(student, study)

object(Id, Cl) \ method(Id, M) <=> method(Cl, M)

Rule:

Page 28: Abductive reasoning and language analysis with Prolog and Constraint Handling Rules Tilburg School of Humanities, March 1, 2012 Henning Christiansen professor.

Example: “Jack and John are teachers. Jack teaches music. John teaches computer science. Mary is a student. He has many students.”

He should refer to John.Constraint store:

Principle• Referents are labelled with the sentence number in which they occur.

• Resolve to the most recent entity matching number and gender

• Ambiguous pronouns are rejected.

sentence_no(Now), referent(No,G,Id,T) \ expect_referent(No,G,X) <=>

T < Now, there is no other relevant referent with Timestamp > T

|

if there is another relevant referent with Timestamp = T then X = errorcode(ambiguous) else X = Id.

Rule (sketch):

Semantic rules in CHR, V (anaphora, ii) Pronouns

...referent(sing,masc,1,jack)referent(sing,masc,1,john)referent(sing,masc,2,jack)referent(sing,masc,3,john)referent(sing,fem,4,mary)property(john, student:n)

...referent(sing,masc,1,jack)referent(sing,masc,1,john)referent(sing,masc,2,jack)referent(sing,masc,3,john)referent(sing,fem,4,mary)property(X, student:n)expect_referent(sing,masc,X)

Page 29: Abductive reasoning and language analysis with Prolog and Constraint Handling Rules Tilburg School of Humanities, March 1, 2012 Henning Christiansen professor.

30

Conclusions

Example shows an application of discourse analysis with• restricted language• concise and “shallow” semantics• a desire of an unambiguous interpretation

Demonstrates Prolog+DCG+CHR applied for “interpretation as abduction”:

• flexibility and ease of modeling• concise, executable specifications

– logic embedded in a full programming language, i.e., you can hack the logic if you feel like it

• apply existing technology directly– no interpretational overhead– no additional tools and notations to learn

Page 30: Abductive reasoning and language analysis with Prolog and Constraint Handling Rules Tilburg School of Humanities, March 1, 2012 Henning Christiansen professor.

31

Related research and future direction

CHR grammars [Christiansen, 2002-3, TPLP2005]– Grammar notation on top of CHR (analogous to DCG on top of Prolog)– Features powerful context-sensitive rules and a lot of other stuff

Probabilistic abduction [Christiansen, LNCS 5388, 2008; Christiansen, Saleh, CHR-workshop, 2011 ]

– identify most probable explanation, best-first search; only prototype impl’s

The LoSt project: Apply probabilistic-logic models in bioinformatics [several publ.; see http://akira.ruc.dk/~henning/publications/]

adaptation of T.Sato & al’s PRISM system to huuuuuge sequences

Possible new directions• Apply (probabilistic) abduction in interactive installations

– guess user intentions and foci of interest– assist virtual robots inside installations

• Integrate analysis of biological sequences and metabolic/control pathways (abduction+induction)

Page 31: Abductive reasoning and language analysis with Prolog and Constraint Handling Rules Tilburg School of Humanities, March 1, 2012 Henning Christiansen professor.

32

A little extra: The Experience Cylinder

Circular screen, n projectors, kinect to trace users•Reacts on user’s position in the cylinder (currently one, prepared for many)•First prototype application with the Viking Ship Museum of Roskilde•Presenting the Sea Stallion’s voyage Roskilde Dublin

Figure from

: Andreasen, G

allagher, Mø

bius, Padfield: T

he Experience C

ylinder, an im

mersive interactive platform

, The S

ea Stallion's voyage: a case study. A

MB

IEN

T

2011.

Page 32: Abductive reasoning and language analysis with Prolog and Constraint Handling Rules Tilburg School of Humanities, March 1, 2012 Henning Christiansen professor.

ReferencesTexts• Intro to Prolog with CHR, abduction for language analysis and diagnosis

H.Christiansen: Logic Programming for Linguistics: A short introduction to Prolog, and Logic Grammars with Constraints as an easy way to Syntax and Semantics, (2010)

http://www.ruc.dk/~henning/LP-For-Linguists/

• Intro to Prolog, focus on DCGP.Blackburn, J.Bos, and K.Striegnitz: Learn Prolog Now! (2001)http://www.learnprolognow.org

Good Prolog systems with CHR• SICStus Prolog (costs money, institution license? 30 days test version)

http://www.sics.se/isl/sicstuswww/site/index.html

• SWI Prolog, freehttp://www.swi-prolog.org/

Software systems:• HYPROLOG: http://www.ruc.dk/~henning/hyprolog/

• CHR Grammars: http://www.ruc.dk/~henning/chrg/

More information: http://www.ruc.dk/~henning, [email protected]

Page 33: Abductive reasoning and language analysis with Prolog and Constraint Handling Rules Tilburg School of Humanities, March 1, 2012 Henning Christiansen professor.

34

The end