330 likes | 477 Views
Abductive reasoning and language analysis with Prolog and Constraint Handling Rules. Coordinator for international student exchanges: • Computer Science • Informatics • Humanities-Technology Studies. Tilburg School of Humanities, March 1, 2012 Henning Christiansen
E N D
Abductive reasoning and language analysis with Prologand Constraint Handling Rules Coordinator for international student exchanges: • Computer Science • Informatics • Humanities-Technology Studies 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, henning@ruc.dk
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
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
Outline of this talk • Crash course on Prolog programming • Definite Clause Grammars, DCGs(add-on to Prolog) • Constraint Handling Rules, CHR (another add-on to Prolog) • Relation to Abductive Reasoning • Using CHR for to add meanings to DCGs • A practical application (sketch) • Related research and future direction • 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!
A crash course on Prolog Prolog 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
Program is a description of data parent( pam, bob). % Pam is a parent of Bob parent( tom, bob). parent( tom, liz). parent( bob, ann). parent( bob, pat). parent( pat, jim). pam tom bob liz ann pat jim
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....
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...
Procedural semantics X=bob • Unification term=term? • from left to right • from start to end • backtracking • ≈ undo and try new choices parent( pam, bob). parent( tom, bob). parent( tom, liz). parent( bob, ann). parent( bob, pat). parent( pat, jim). ?- parent(pam, X), parent(X, Y). ?- parent(bob, Y). Y=ann Success! Other solutions? Success! Other Solutions? Y=pat No more possible solutions at all No more solutions with X=bob :/
Rules Procedural semantics as before + rewrite subgoal using rules Declarative semantics ≈ logical consequence in 1st order logic The nice property: procedural ≈ declarative grandparent(X,Z):- parent(X, Y), parent(Y, Z). • Other features • structures and lists (will see later) • control mechanisms (advanced; not needed for today)
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].
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...
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].
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.
Back to CHR Three kinds of rules: Propagate c, 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 :)
Back to discourse analysis ?- [discourse1]. First version, just collecting facts Second version, adding rules about semantic/pragmatic universe ?- [discourse2]. • ————————————————————————————— • 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
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]
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)
Overview of the process by example Use case text: “The professor teaches.” Abductive analysis with DCG+CHR class(professor) method(professor, teach) A little code that exports to GraphViz
Several classes and methods Use 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))
Classes and properties Use case text: “A professor has an office.” class(professor) class(office) property(professor,office:1)
Classes and inheritance Use case text: “Students and professors are persons.” class(professor) class(student) class(person) extends(professor, person) extends(student, person)
sentence --> fc_noun_phrase(Number,_ , subj, IdSub), subord_verb(Number,_ ), fc_noun_phrase(_ , Number, obj, IdObj), {extends(IdSub,IdObj)}. Example of a grammar rule fc_ “cats and dogs” cat+dog indiv_ “her, Peter and Paul” mary+peter+paul rc_ “Mary and the boys” woman+boy q_ “a tail and some legs” tail:1+legs:n • There are sentence grammar rules like this for different sentence types • Each rule captures the semantic features of a particular type of sentence
Semantic rules in CHR, I Example: “Professors and students are persons.” Example: “A professor is a teacher and a researcher.” Rule: Rule: extends(A+B, C) <=> extends(A,C), extends(B,C). extends(A, B+C) <=> extends(A, B), extends(A, C). Sample constraint store: Sample constraint store: extends(professor+student, person) extends(professor, teacher+researcher) extends(professor, person) extends(student, person) extends(professor, teacher) extends(professor, researcher)
Semantic rules in CHR, II Example:“Paul has a dog and Peter has five dogs.” (Peter and Paul known to be men). Rule: property(C,P:N), property(C,P:M) <=> q_count(N), q_count(M), q_less_eq(N,M) | property(C,P:(N..M)). Sample constraint store: ... property(man, dog:1) property(man, dog:5) property(man, dog:(1..5))
Semantic rules in CHR, III Ranges can be merged Sample constraint store: property(man, dog:(0..2)) property(man, dog:(1..n)) property(man, dog:(0..n)) Rule: 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)).
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) Rule: object(Id, Cl) \ method(Id, M) <=> method(Cl, M)
Semantic rules in CHR, V (anaphora, ii) Pronouns 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: ... 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) ... 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) 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. Rule (sketch): sentence_no(Now), referent(No,G,Id,T) \ expect_referent(No,G,X) <=> T < Now,there is no other relevant referent withTimestamp > T | if there is another relevant referent withTimestamp = Tthen X = errorcode(ambiguous) else X = Id.
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
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)
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, Gallagher, Møbius, Padfield: The Experience Cylinder, an immersive interactive platform, The Sea Stallion's voyage: a case study. AMBIENT 2011.
References Texts • 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 DCG P.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, free http://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, henning@ruc.dk