C. Varela1 Logic Programming (PLP 11, CTM 9.2, 9.4, 12.1-12.2) Constraint Satisfaction Problems, Natural Language Parsing (Definite Clause Grammars) Carlos.

Slides:



Advertisements
Similar presentations
Artificial Intelligence: Natural Language and Prolog
Advertisements

Spreadsheet Vocabulary
Prolog programming....Dr.Yasser Nada. Chapter 8 Parsing in Prolog Taif University Fall 2010 Dr. Yasser Ahmed nada prolog programming....Dr.Yasser Nada.
Building a Conceptual Understanding of Algebra with Algebra Tiles
C. Varela; Adapted w/permission from S. Haridi and P. Van Roy1 Declarative Programming Techniques Accumulators, Difference Lists (VRH ) Carlos Varela.
CSA2050: DCG I1 CSA2050 Introduction to Computational Linguistics Lecture 8 Definite Clause Grammars.
© Patrick Blackburn, Johan Bos & Kristina Striegnitz Lecture 6: More Lists Theory –Define append/3, a predicate for concatenating two lists, and illustrate.
CPSC Compiler Tutorial 4 Midterm Review. Deterministic Finite Automata (DFA) Q: finite set of states Σ: finite set of “letters” (input alphabet)
Cs7120 (Prasad)L21-DCG1 Definite Clause Grammars
CSA4050: Advanced Topics in NLP Semantics IV Partial Execution Proper Noun Adjective.
Translator Architecture Code Generator ParserTokenizer string of characters (source code) string of tokens abstract program string of integers (object.
How to Think about Prolog - 1 Mike’s Prolog Tutorial 29 Sept 2011.
Methods of Proof Chapter 7, second half.. Proof methods Proof methods divide into (roughly) two kinds: Application of inference rules: Legitimate (sound)
May 2006CLINT-LN Parsing1 Computational Linguistics Introduction Approaches to Parsing.
1 Grammars and Parsing Allen ’ s Chapters 3, Jurafski & Martin ’ s Chapters 8-9.
Recursion Lecture 18: Nov 18.
C. Varela; Adapted w/permission from S. Haridi and P. Van Roy1 Declarative Computation Model Defining practical programming languages Carlos Varela RPI.
Carlos Varela Rennselaer Polytechnic Institute September 10, 2007
Parsing SLP Chapter 13. 7/2/2015 Speech and Language Processing - Jurafsky and Martin 2 Outline  Parsing with CFGs  Bottom-up, top-down  CKY parsing.
LING 388: Language and Computers Sandiway Fong Lecture 13: 10/10.
LING 388: Language and Computers Sandiway Fong 10/4 Lecture 12.
Children of technology How to attract students’ attention, being ‘’Children of technology’’?
Grammars and Parsing. Sentence  Noun Verb Noun Noun  boys Noun  girls Noun  dogs Verb  like Verb  see Grammars Grammar: set of rules for generating.
Basic Concepts of Algebra
Logic Programming Lecture 6: Parsing, Difference Lists and Definite Clause Grammars.
LING 388: Language and Computers Sandiway Fong Lecture 7.
Signed Rationals. Place Value Let’s look at position after the decimal to help us do some rounding!
CS 403: Programming Languages Lecture 19 Fall 2003 Department of Computer Science University of Alabama Joel Jones.
Games. Adversaries Consider the process of reasoning when an adversary is trying to defeat our efforts In game playing situations one searches down the.
7 th grade Mathematics - 5 Order of Operation 7 th grade Mathematics - 5 Order of Operation.
Syntax Why is the structure of language (syntax) important? How do we represent syntax? What does an example grammar for English look like? What strategies.
CSE 425: Syntax II Context Free Grammars and BNF In context free grammars (CFGs), structures are independent of the other structures surrounding them Backus-Naur.
Everyday Math Unit 6 Vocabulary Miss Beasley. 6.1 and 6.2 Reciprocals- pairs of numbers whose product is 1. – Example: 2 is the reciprocal of ½ Division.
Semantic Construction lecture 2. Semantic Construction Is there a systematic way of constructing semantic representation from a sentence of English? This.
MCAS Math Terms. Add The process of finding the total number of items when two or more groups of items are joined; the opposite operation of subtraction.
Sentence Parsing Parsing 3 Dynamic Programming. Jan 2009 Speech and Language Processing - Jurafsky and Martin 2 Acknowledgement  Lecture based on  Jurafsky.
Solving Problems by searching Well defined problems A probem is well defined if it is easy to automatically asses the validity (utility) of any proposed.
November 2004csa3050: Sentence Parsing II1 CSA350: NLP Algorithms Sentence Parsing 2 Top Down Bottom-Up Left Corner BUP Implementation in Prolog.
C. Varela1 Logic Programming (PLP 11) Predicate Calculus, Horn Clauses, Clocksin-Mellish Procedure Carlos Varela Rennselaer Polytechnic Institute November.
csa3050: Parsing Algorithms 11 CSA350: NLP Algorithms Parsing Algorithms 1 Top Down Bottom-Up Left Corner.
Curry A Tasty dish? Haskell Curry!. Curried Functions Currying is a functional programming technique that takes a function of N arguments and produces.
Lesson 2 Contents Example 1Solve a Two-Step Equation Example 2Solve Two-Step Equations Example 3Solve Two-Step Equations Example 4Equations with Negative.
LING/C SC/PSYC 438/538 Lecture 15 Sandiway Fong. Did you install SWI Prolog?
C. Varela1 Logic Programming (PLP 11, CTM 9.1) Terms, Resolution, Unification, Search, Backtracking (Prolog) Relational Computation Model (Oz) Carlos Varela.
Copyright © Curt Hill Other Trees Applications of the Tree Structure.
C. Varela1 Logic Programming (CTM ) Constraint Programming: Constraints and Computation Spaces Carlos Varela Rennselaer Polytechnic Institute.
Chapter 2 Syntax and meaning of prolog programs Part 1.
Logic Programming Lecture 6: Parsing and Definite Clause Grammars.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. C H A P T E R N I N E Logic Programming.
C. Varela1 Logic Programming (PLP 11, CTM 9.3) Prolog Imperative Control Flow: Backtracking, Cut, Fail, Not Lists, Append Carlos Varela Rennselaer Polytechnic.
Warm Up 8/6/14 Write each sentence as an expression: 1.Multiply n by 4, and then add 3 to your answer. 2.Add 3 to n, and then multiply your answer by 4.
Carlos Varela Rennselaer Polytechnic Institute November 18, 2016
CSC 594 Topics in AI – Natural Language Processing
Programming Languages Translator
Carlos Varela Rennselaer Polytechnic Institute November 11, 2016
Natural Language Processing
Carlos Varela Rensselaer Polytechnic Institute November 17, 2017
Carlos Varela Rensselaer Polytechnic Institute November 21, 2017
Carlos Varela Rensselaer Polytechnic Institute December 5, 2017
Carlos Varela Rensselaer Polytechnic Institute November 14, 2017
Carlos Varela Rennselaer Polytechnic Institute December 6, 2016
Carlos Varela Rensselaer Polytechnic Institute December 8, 2017
Carlos Varela Rensselaer Polytechnic Institute November 10, 2017
Chapter 2 Syntax and meaning of prolog programs
This is the side of a rectangle with 16 blocks total
Lecture 18 Bottom-Up Parsing or Shift-Reduce Parsing
Curry A Tasty dish? Haskell Curry!.
Exercise Solve for x, telling what property was used to solve the equation. x − 3 = 7 x = 10; Addition Property of Equality.
Carlos Varela Rennselaer Polytechnic Institute November 15, 2016
Carlos Varela Rennselaer Polytechnic Institute August 30, 2007
Presentation transcript:

C. Varela1 Logic Programming (PLP 11, CTM 9.2, 9.4, ) Constraint Satisfaction Problems, Natural Language Parsing (Definite Clause Grammars) Carlos Varela Rennselaer Polytechnic Institute November 20, 2015

Constraint Satisfaction Example* Given six Italian words: –astante, astoria, baratto, cobalto, pistola, statale. They are to be arranged, crossword puzzle fashion, in the following grid: C. Varela, *Example from Learn Prolog Now! by Blackburn et al. (Exercise 2.4)2

Constraint Satisfaction Example(2)* The following knowledge base represents a lexicon containing these words: word(astante, a,s,t,a,n,t,e). word(astoria, a,s,t,o,r,i,a). word(baratto, b,a,r,a,t,t,o). word(cobalto, c,o,b,a,l,t,o). word(pistola, p,i,s,t,o,l,a). word(statale, s,t,a,t,a,l,e). Write a predicate crossword/6 that tells us how to fill in the puzzle. The first three arguments should be the vertical words from left to right, and the last three arguments the horizontal words from top to bottom. C. Varela, *Example from Learn Prolog Now! by Blackburn et al. (Exercise 2.4)3

Constraint Satisfaction Example(3)* Try solving it yourself before looking at this solution! crossword(V1,V2,V3,H1,H2,H3) :- word(V1,_,H1V1,_,H2V1,_,H3V1,_), word(V2,_,H1V2,_,H2V2,_,H3V2,_), word(V3,_,H1V3,_,H2V3,_,H3V3,_), word(H1,_,H1V1,_,H1V2,_,H1V3,_), word(H2,_,H2V1,_,H2V2,_,H2V3,_), word(H3,_,H3V1,_,H3V2,_,H3V3,_). C. Varela, *Example from Learn Prolog Now! by Blackburn et al. (Exercise 2.4)4

Generate and Test Example We can use the relational computation model to generate all digits: fun {Digit} choice 0 [] 1 [] 2 [] 3 [] 4 [] 5 [] 6 [] 7 [] 8 [] 9 end end {Browse {Search.base.all Digit}} % displays [ ] C. Varela5

Finding digit pairs that add to 10 Using generate and test to do combinatorial search: fun {PairAdd10} D1 D2 in D1 = {Digit} % generate D2 = {Digit} % generate D1+D2 = 10 % test D1#D2 end {Browse {Search.base.all PairAdd10}} % displays [1#9 2#8 3#7 4#6 5#5 6#4 7#3 8#2 9#1] C. Varela6

Finding palindromes Find all four-digit palindromes that are products of two- digit numbers: fun {Palindrome} X in X = (10*{Digit}+{Digit})*(10*{Digit}+{Digit}) % generate (X>=1000) = true % test (X div 1000) mod 10 = (X div 1) mod 10 % test (X div 100) mod 10 = (X div 10) mod 10 % test X end {Browse {Search.base.all Palindrome}} % 118 solutions C. Varela7

Propagate and Search The generate and test programming pattern can be very inefficient (e.g., Palindrome program explores possibilities). An alternative is to use a propagate and search technique. Propagate and search filters possibilities during the generation process, to prevent combinatorial explosion when possible. C. Varela8

Propagate and Search Propagate and search approach is based on three key ideas: Keep partial information, e.g., “in any solution, X is greater than 100”. Use local deduction, e.g., combining “X is less than Y” and “X is greater than 100”, we can deduce “Y is greater than 101” (assuming Y is an integer.) Do controlled search. When no more deductions can be done, then search. Divide original CSP problem P into two new problems: (P ^ C) and (P ^  C) and where C is a new constraint. The solution to P is the union of the two new sub- problems. Choice of C can significantly affect search space. C. Varela9

Propagate and Search Example Find two digits that add to 10, multiply to more than 24: D1::0#9D2::0#9% initial constraints {Browse D1}{Browse D2}% partial results D1+D2 =: 10 % reduces search space from 100 to 81 possibilities % D1 and D2 cannot be 0. D1*D2 >=: 24 % reduces search space to 9 possibilities % D1 and D2 must be between 4 and 6. D1 <: D2 % reduces search space to 4 possibilities % D1 must be 4 or 5 and D2 must be 5 or 6. % It does not find unique solution D1=4 and D2=6 C. Varela10

Propagate and Search Example(2) Find a rectangle whose perimeter is 20, whose area is greater than or equal to 24, and width less than height: fun {Rectangle} W H in W::0#9 H::0#9 W+H =: 10 W*H >=: 24 W <: H {FD.distribute naive rect(W H)} rect(W H) end {Browse {Search.base.all Rectangle}} % displays [rect(4 6)] C. Varela11

Finding palindromes (revisited) Find all four-digit palindromes that are products of two- digit numbers: fun {Palindrome} A B C X Y in A::1000#9999 B::0#99 C::0#99 A =: B*C X::1#9 Y::0#9 A =: X*1000+Y*100+Y*10+X {FD.distribute ff [X Y]} A end {Browse {Search.base.all Palindrome}} % 36 solutions C. Varela12

C. Varela13 Natural Language Parsing (Example from "Learn Prolog Now!” Online Tutorial) word(article,a). word(article,every). word(noun,criminal). word(noun,'big kahuna burger'). word(verb,eats). word(verb,likes). sentence(Word1,Word2,Word3,Word4,Word5) :- word(article,Word1), word(noun,Word2), word(verb,Word3), word(article,Word4), word(noun,Word5).

C. Varela14 Parsing natural language Definite Clause Grammars (DCG) are useful for natural language parsing. Prolog can load DCG rules and convert them automatically to Prolog parsing rules.

C. Varela15 DCG Syntax --> DCG operator, e.g., sentence-->subject,verb,object. Each goal is assumed to refer to the head of a DCG rule. {prolog_code} Include Prolog code in generated parser, e.g., subject-->modifier,noun,{write(‘subject’)}. [terminal_symbol] Terminal symbols of the grammar, e.g., noun-->[cat].

C. Varela16 Natural Language Parsing (example rewritten using DCG) sentence --> article, noun, verb, article, noun. article --> [a] | [every]. noun --> [criminal] | ['big kahuna burger']. verb --> [eats] | [likes].

C. Varela17 Natural Language Parsing (2) sentence(V) --> subject, verb(V), subject. subject --> article, noun. article --> [a] | [every]. noun --> [criminal] | ['big kahuna burger']. verb(eats) --> [eats]. verb(likes) --> [likes].

C. Varela18 Exercises 83.How would you translate DCG rules into Prolog rules? 84.PLP Exercise 11.8 (pg 571). 85.PLP Exercise (pg 572). 86.CTM Exercise (pg 774).