Carlos Varela Rensselaer Polytechnic Institute November 21, 2017

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.
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.
© Patrick Blackburn, Johan Bos & Kristina Striegnitz Lecture 6: More Lists Theory –Define append/3, a predicate for concatenating two lists, and illustrate.
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.
May 2006CLINT-LN Parsing1 Computational Linguistics Introduction Approaches to Parsing.
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.
Basic Concepts of Algebra
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!
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.
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.
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, CTM 9.2, 9.4, ) Constraint Satisfaction Problems, Natural Language Parsing (Definite Clause Grammars) Carlos.
C. Varela1 Logic Programming (PLP 11) Predicate Calculus, Horn Clauses, Clocksin-Mellish Procedure Carlos Varela Rennselaer Polytechnic Institute November.
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.
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.
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.
GCSE COMPUTER SCIENCE Practical Programming using Python Lesson 4 - Selection.
Carlos Varela Rennselaer Polytechnic Institute November 18, 2016
CSC 594 Topics in AI – Natural Language Processing
GCSE COMPUTER SCIENCE Practical Programming using Python
By P. S. Suryateja Asst. Professor, CSE Vishnu Institute of Technology
Algorithms and Problem Solving
Grammars and Parsing.
Functional Programming: Lists, Pattern Matching, Recursive Programming (CTM Sections , 3.2, , 4.7.2) Carlos Varela RPI September 12,
Example 1 Factor ax2 + bx + c
Programming Languages Translator
Carlos Varela Rennselaer Polytechnic Institute November 11, 2016
Basic Parsing with Context Free Grammars Chapter 13
Natural Language Processing
Lecture 11: Tree Search © J. Christopher Beck 2008.
Unit 2 Smarter Programming.
Do Now Pg 52 #18-21.
Carlos Varela Rensselaer Polytechnic Institute November 17, 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
CSCI 5832 Natural Language Processing
Carlos Varela Rensselaer Polytechnic Institute November 10, 2017
C H A P T E R N I N E Logic Programming.
Algorithms and Problem Solving
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.
Chapter 10 7th Grade Math.
Exercise: Dice rolls Write a method diceRoll that accepts an integer parameter representing a number of 6-sided dice to roll, and output all possible arrangements.
Carlos Varela Rennselaer Polytechnic Institute November 15, 2016
Carlos Varela Rennselaer Polytechnic Institute August 30, 2007
Presentation transcript:

Carlos Varela Rensselaer Polytechnic Institute November 21, 2017 Logic Programming (PLP 11, CTM 9.2, 9.4, 12.1-12.2) Constraint Satisfaction Problems, Natural Language Parsing (Definite Clause Grammars) Carlos Varela Rensselaer Polytechnic Institute November 21, 2017 C. Varela

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)

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)

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)

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 [0 1 2 3 4 5 6 7 8 9] C. Varela

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. Varela

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. Varela

Propagate and Search The generate and test programming pattern can be very inefficient (e.g., Palindrome program explores 10000 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. Varela

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. Varela

Propagate and Search Example Find two digits that add to 10, multiply to more than 24: D1::0#9 D2::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. Varela

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. Varela

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. Varela

Natural Language Parsing (Example from "Learn Prolog Now 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. Varela

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. Varela

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. Varela

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. Varela

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. Varela

Exercises How would you translate DCG rules into Prolog rules? PLP Exercise 11.8 (pg 571). PLP Exercise 11.14 (pg 572). CTM Exercise 12.6.2 (pg 774). C. Varela