LING 388: Language and Computers Sandiway Fong Lecture 8.

Slides:



Advertisements
Similar presentations
Artificial Intelligence: Natural Language and Prolog
Advertisements

LING 388: Language and Computers
CSA2050: DCG I1 CSA2050 Introduction to Computational Linguistics Lecture 8 Definite Clause Grammars.
LING 388: Language and Computers Sandiway Fong Lecture 5: 9/5.
LING 388: Language and Computers Sandiway Fong Lecture 5: 9/8.
CSA4050: Advanced Topics in NLP Semantics IV Partial Execution Proper Noun Adjective.
Grammars, constituency and order A grammar describes the legal strings of a language in terms of constituency and order. For example, a grammar for a fragment.
May 2006CLINT-LN Parsing1 Computational Linguistics Introduction Approaches to Parsing.
LING 388: Language and Computers Sandiway Fong Lecture 2.
LING 388: Language and Computers Sandiway Fong Lecture 2: 8/24.
LING 388: Language and Computers Sandiway Fong Lecture 2: 8/25.
For Monday Read Chapter 23, sections 3-4 Homework –Chapter 23, exercises 1, 6, 14, 19 –Do them in order. Do NOT read ahead.
LING 438/538 Computational Linguistics Sandiway Fong Lecture 3: 8/29.
LING 438/538 Computational Linguistics Sandiway Fong Lecture 7: 9/12.
LING 388 Language and Computers Lecture 2 9/04/03 Sandiway FONG.
LING 438/538 Computational Linguistics Sandiway Fong Lecture 9: 9/21.
LING 364: Introduction to Formal Semantics
LING/C SC/PSYC 438/538 Computational Linguistics Sandiway Fong Lecture 7: 9/11.
LING 388 Language and Computers Lecture 8 9/25/03 Sandiway FONG.
LING/C SC/PSYC 438/538 Computational Linguistics Sandiway Fong Lecture 6: 9/6.
LING 388: Language and Computers Sandiway Fong Lecture 4: 8/31.
LING 388: Language and Computers Sandiway Fong Lecture 3: 8/29.
© Patrick Blackburn, Johan Bos & Kristina Striegnitz Lecture 7: Definite Clause Grammars Theory –Introduce context free grammars and some related concepts.
LING 438/538 Computational Linguistics Sandiway Fong Lecture 6: 9/7.
LING 388 Language and Computers Take-Home Final Examination 12/9/03 Sandiway FONG.
LING 388 Language and Computers Lecture 18 10/30/03 Sandiway FONG.
LING 388: Language and Computers Sandiway Fong Lecture 17: 10/25.
LING 438/538 Computational Linguistics Sandiway Fong Lecture 5: 9/5.
LING 364: Introduction to Formal Semantics Lecture 5 January 26th.
LING 388: Language and Computers Sandiway Fong Lecture 13: 10/10.
LING 388 Language and Computers Lecture 12 10/9/03 Sandiway FONG.
LING 388 Language and Computers Lecture 6 9/18/03 Sandiway FONG.
Context-Free Grammar CSCI-GA.2590 – Lecture 3 Ralph Grishman NYU.
LING 388: Language and Computers Sandiway Fong 10/4 Lecture 12.
LING/C SC/PSYC 438/538 Lecture 19 Sandiway Fong 1.
LING 388: Language and Computers Sandiway Fong Lecture 11.
LING 388: Language and Computers Sandiway Fong Lecture 17.
October 2008csa3180: Setence Parsing Algorithms 1 1 CSA350: NLP Algorithms Sentence Parsing I The Parsing Problem Parsing as Search Top Down/Bottom Up.
LING 388: Language and Computers Sandiway Fong Lecture 4.
For Friday Finish chapter 23 Homework: –Chapter 22, exercise 9.
LING 388: Language and Computers Sandiway Fong Lecture 7.
CSI 3120, Grammars, page 1 Language description methods Major topics in this part of the course: –Syntax and semantics –Grammars –Axiomatic semantics (next.
LING 388: Language and Computers Sandiway Fong Lecture 3.
LING 388: Language and Computers Sandiway Fong Lecture 18.
3-1 Chapter 3: Describing Syntax and Semantics Introduction Terminology Formal Methods of Describing Syntax Attribute Grammars – Static Semantics Describing.
30/09/04 AIPP Lecture 3: Recursion, Structures, and Lists1 Recursion, Structures, and Lists Artificial Intelligence Programming in Prolog Lecturer: Tim.
LING 388: Language and Computers Sandiway Fong Lecture 10.
October 2005csa3180: Parsing Algorithms 11 CSA350: NLP Algorithms Sentence Parsing I The Parsing Problem Parsing as Search Top Down/Bottom Up Parsing Strategies.
LING 388: Language and Computers Sandiway Fong Lecture 13.
For Wednesday Read chapter 23 Homework: –Chapter 22, exercises 1,4, 7, and 14.
LING 388: Language and Computers Sandiway Fong Lecture 12.
1 Chart Parsing Allen ’ s Chapter 3 J & M ’ s Chapter 10.
1 Definite Clause Grammars for Language Analysis – A Survey of the Formalism and a Comparison with Augmented Transition Networks 인공지능 연구실 Hee keun Heo.
NLP. Introduction to NLP Motivation –A lot of the work is repeated –Caching intermediate results improves the complexity Dynamic programming –Building.
November 2004csa3050: Sentence Parsing II1 CSA350: NLP Algorithms Sentence Parsing 2 Top Down Bottom-Up Left Corner BUP Implementation in Prolog.
Introduction to Prolog. Outline What is Prolog? Prolog basics Prolog Demo Syntax: –Atoms and Variables –Complex Terms –Facts & Queries –Rules Examples.
csa3050: Parsing Algorithms 11 CSA350: NLP Algorithms Parsing Algorithms 1 Top Down Bottom-Up Left Corner.
LING/C SC/PSYC 438/538 Lecture 15 Sandiway Fong. Did you install SWI Prolog?
LING/C SC/PSYC 438/538 Lecture 20 Sandiway Fong 1.
LING 388: Language and Computers Sandiway Fong Lecture 16.
Parsing and Code Generation Set 24. Parser Construction Most of the work involved in constructing a parser is carried out automatically by a program,
LING/C SC/PSYC 438/538 Lecture 16 Sandiway Fong. SWI Prolog Grammar rules are translated when the program is loaded into Prolog rules. Solves the mystery.
GRAMMARS & PARSING. Parser Construction Most of the work involved in constructing a parser is carried out automatically by a program, referred to as a.
NLP. Introduction to NLP #include int main() { int n, reverse = 0; printf("Enter a number to reverse\n"); scanf("%d",&n); while (n != 0) { reverse =
PARSING David Kauchak CS159 – Fall Admin Assignment 3 Quiz #1  High: 36  Average: 33 (92%)  Median: 33.5 (93%)
LING/C SC/PSYC 438/538 Lecture 21 Sandiway Fong.
LING/C SC/PSYC 438/538 Lecture 17 Sandiway Fong.
LING 581: Advanced Computational Linguistics
LING/C SC/PSYC 438/538 Lecture 20 Sandiway Fong.
Lecture 7: Definite Clause Grammars
Presentation transcript:

LING 388: Language and Computers Sandiway Fong Lecture 8

Adminstrivia Review of grammar rules One worked exercise Homework 3 – submit by next Wednesday midnight to TA Ben Martin

Last Time Grammars – what is a grammar? informally – set of “rewrite” rules to parse or “diagram” a sentence derivation – top-down (from the sentence symbol), bottom-up (from the words) Definite Clause Grammar (DCG) System – built-in Prolog support for writing grammars – --> is the rewrite symbol – [book], [took] terminals are enclosed in brackets – sentence, vp, np terminals and non-terminal symbols begin with lowercase letters Sentence → NP VP VP → Verb NP Verb → took NP → the man NP → the book sentence --> np, vp. vp --> verb, np. verb --> [took]. np --> [the], [man]. np --> [the], [book].

Last Time example grammar (from last time) – sentence --> np, vp. – vp --> verb, np. – verb --> [took]. – np --> [the], [man]. – np --> [the], [book]. query format ?- sentence(S,[]). S = sentence (as a list) [] = empty list i.e. call the start symbol as a predicate and supply two arguments, a list and an empty list Prolog translates grammar into underlying Prolog rules you can see the rules using the command ?- listing. Prolog translates grammar into underlying Prolog rules you can see the rules using the command ?- listing.

Prolog Summary (so far) Use a text editor to write your programs (extension:.pl) Prolog interpreter – /opt/local/bin/swipl (on Mac) Definite clause grammar rules – LHS --> RHS. – Non-terminal symbols (begin with lowercase letter), terminal symbols (same but in [..]) Load in grammar at the prompt: – ?- [filename].(no extension needed) Submit Prolog query at the prompt: – ?- nonterminal(List,[]). – List: [word1,word2,..,wordn]head-tail notation: [Head|Tail] Top-down, left-to-right derivation Variables begin with an uppercase letter

variables A,B,C are all going to be lists 'C'(C, man, B) is true when man is the head of C and B is the tail of C i.e. C = [man|B] ?- listing. Prolog translates DCG rules into ordinary Prolog rules example –sentence --> np, vp. –vp --> verb, np. –verb --> [took]. –np --> det, [man]. –np --> det, [book]. –det --> [the]. –det --> [a]. listing vp(A, B) :- verb(A, C), np(C, B). np(A, B) :- det(A, C), 'C'(C, man, B). np(A, B) :- det(A, C), 'C'(C, book, B). verb([took|A], A). det([the|A], A). det([a|A], A). sentence(A, B) :- np(A, C), vp(C, B).

Prolog Grammar Rules The computation rule for DCG rules – each time we look for a matching rule, we pattern- match against the database from the 1st rule on down example –sentence --> np, vp. –vp --> verb, np. –verb --> [took]. –np --> det, [man]. –np --> det, [book]. –det --> [the]. –det --> [a]. listing. –vp(A, B) :- – verb(A, C), – np(C, B). –np(A, B) :- – det(A, C), – 'C'(C, man, B). –np(A, B) :- – det(A, C), – 'C'(C, book, B). –verb([took|A], A). –det([the|A], A). –det([a|A], A). –sentence(A, B) :- – np(A, C), – vp(C, B).

Prolog Grammar Rules derivation ?- sentence([the,man,took,the,book],[]). Call: (7) sentence([the, man, took, the, book], []) ? creep Call: (8) np([the, man, took, the, book], _G353) ? creep Call: (9) det([the, man, took, the, book], _G353) ? creep Exit: (9) det([the, man, took, the, book], [man, took, the, book]) ? creep Call: (9) 'C'([man, took, the, book], man, _G357) ? creep Exit: (9) 'C'([man, took, the, book], man, [took, the, book]) ? creep Exit: (8) np([the, man, took, the, book], [took, the, book]) ? creep Call: (8) vp([took, the, book], []) ? creep Call: (9) verb([took, the, book], _G353) ? creep Exit: (9) verb([took, the, book], [the, book]) ? creep Call: (9) np([the, book], []) ? creep Call: (10) det([the, book], _G353) ? creep Exit: (10) det([the, book], [book]) ? creep Call: (10) 'C'([book], man, []) ? creep Fail: (10) 'C'([book], man, []) ? creep Redo: (10) det([the, book], _G353) ? creep Fail: (10) det([the, book], _G353) ? creep Redo: (9) np([the, book], []) ? creep Call: (10) det([the, book], _G353) ? creep Exit: (10) det([the, book], [book]) ? creep Call: (10) 'C'([book], book, []) ? creep Exit: (10) 'C'([book], book, []) ? creep Exit: (9) np([the, book], []) ? creep Exit: (8) vp([took, the, book], []) ? creep Exit: (7) sentence([the, man, took, the, book], []) ? creep Yes listing. –vp(A, B) :- – verb(A, C), – np(C, B). –np(A, B) :- – det(A, C), – 'C'(C, man, B). –np(A, B) :- – det(A, C), – 'C'(C, book, B). –verb([took|A], A). –det([the|A], A). –det([a|A], A). –sentence(A, B) :- – np(A, C), – vp(C, B).

Worked Exercise Let's write grammar rules to handle: – I saw the boy with a telescope (ambiguous: 2 derivations) – the boy with a telescope saw me (unambiguous: 1 derivation)

Worked Exercise Step 1: decide on the parses you want your grammar to produce Unsure? Use a parser… you already know one

Worked Exercise Step 2: write the rules – Remember: terminal and nonterminal symbols should begin with a lowercase letter 1.s --> np, vp. 2.np --> dt, nn. 3.np --> prp. 4.…

Worked Exercise Step 3: test and debug your grammar – ?- s([i,saw,the,boy,with,a,telescope],[]). – true ; – false – two possible derivations – ?- s([the,boy,with,a,telescope,saw,me],[]). – true ; – False – only one possible derivation

Prolog Terms LISP s-exp notation: Prolog term notation (introduced back in lecture 4) Simple terms – atoms: s, np, vp, dt … – numbers: 1, 45.3 … – variables: List, Sentence … Complex terms: general template: – functor(argument 1,..,argument n ) – functor/n (n= arity) – functor must be an atom – arguments can be simple terms or (recursive) complex terms Examples: –nn(boy) –dt(the) –np(nn(boy),dt(the))

Exercise 1 Part 1: Construct Prolog term representations for the two Stanford parses: – exclude the ROOT node

Exercise 2 Writing a program to analyse/construct complex terms

Exercise 2 using functor and arg – Term = np(nn(boy),dt(the)) – What do the following Prolog queries do?

Homework 3 Question 1: what does this do? Question 2: what does this do? Question 3: give a Prolog query that picks out the word telescope from the compound term

Exercise 3 Univ predicate: Try these Prolog queries: –?- Term =.. [np,DT,NN]. –?- Term =.. [dt,the]. What does this do?

Homework 3 Question 4: Given devise a query using =.. that builds the complex term NP: Question 5: devise a query using =.. that builds the complex term PP: