LING 438/538 Computational Linguistics Sandiway Fong Lecture 7: 9/12.

Slides:



Advertisements
Similar presentations
Lecture # 8 Chapter # 4: Syntax Analysis. Practice Context Free Grammars a) CFG generating alternating sequence of 0’s and 1’s b) CFG in which no consecutive.
Advertisements

LING 388: Language and Computers Sandiway Fong Lecture 9: 9/27.
About Grammars CS 130 Theory of Computation HMU Textbook: Sec 7.1, 6.3, 5.4.
LING 438/538 Computational Linguistics Sandiway Fong Lecture 16: 10/19.
LING 438/538 Computational Linguistics Sandiway Fong Lecture 8: 9/29.
LING 388: Language and Computers Sandiway Fong Lecture 9: 9/22.
LING/C SC/PSYC 438/538 Computational Linguistics Sandiway Fong Lecture 10: 9/27.
LING 364: Introduction to Formal Semantics Lecture 9 February 9th.
LING/C SC/PSYC 438/538 Computational Linguistics Sandiway Fong Lecture 12: 10/4.
LING 438/538 Computational Linguistics Sandiway Fong Lecture 9: 9/21.
LING 388: Language and Computers Sandiway Fong Lecture 21: 11/7.
LING 388: Language and Computers Sandiway Fong Lecture 12: 10/5.
LING/C SC/PSYC 438/538 Computational Linguistics Sandiway Fong Lecture 8: 9/18.
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 438/538 Computational Linguistics Sandiway Fong Lecture 22: 11/15.
LING/C SC/PSYC 438/538 Computational Linguistics Sandiway Fong Lecture 9: 9/25.
LING/C SC/PSYC 438/538 Computational Linguistics Sandiway Fong Lecture 6: 9/6.
LING 388 Language and Computers Lecture 4 9/11/03 Sandiway FONG.
LING 438/538 Computational Linguistics Sandiway Fong Lecture 11: 10/3.
LING 388: Language and Computers Sandiway Fong Lecture 6: 9/13.
LING 388: Language and Computers Sandiway Fong Lecture 11: 10/3.
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 Sandiway Fong Lecture 28: 12/5.
LING 438/538 Computational Linguistics Sandiway Fong Lecture 12: 10/5.
LING 388: Language and Computers Sandiway Fong Lecture 17: 10/25.
LING 388 Language and Computers Lecture 11 10/7/03 Sandiway FONG.
LING/C SC/PSYC 438/538 Midterm 10/11. Instructions It is recommended that you attempt all questions –Submit your answers in one file by to
LING 388: Language and Computers Sandiway Fong Lecture 10: 9/26.
LING 438/538 Computational Linguistics Sandiway Fong Lecture 5: 9/5.
LING 388 Language and Computers Lecture 9 9/30/03 Sandiway FONG.
Chapter 3: Formal Translation Models
How to Convert a Context-Free Grammar to Greibach Normal Form
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.
LING 388: Language and Computers Sandiway Fong 10/4 Lecture 12.
Context Free Grammars Reading: Chap 12-13, Jurafsky & Martin This slide set was adapted from J. Martin, U. Colorado Instructor: Paul Tarau, based on Rada.
Problem of the DAY Create a regular context-free grammar that generates L= {w  {a,b}* : the number of a’s in w is not divisible by 3} Hint: start by designing.
LING 388: Language and Computers Sandiway Fong Lecture 7.
LING/C SC/PSYC 438/538 Lecture 14 Sandiway Fong. Administrivia Midterm – This Wednesday – A bit like doing a homework in real time – Bring your laptop.
Lecture Two: Formal Languages Formal Languages, Lecture 2, slide 1 Amjad Ali.
Lecture # 19. Example Consider the following CFG ∑ = {a, b} Consider the following CFG ∑ = {a, b} 1. S  aSa | bSb | a | b | Λ The above CFG generates.
Grammars CPSC 5135.
Lecture # 9 Chap 4: Ambiguous Grammar. 2 Chomsky Hierarchy: Language Classification A grammar G is said to be – Regular if it is right linear where each.
1 Computability Five lectures. Slides available from my web page There is some formality, but it is gentle,
LING 388: Language and Computers Sandiway Fong Lecture 6: 9/15.
LING/C SC/PSYC 438/538 Lecture 12 10/4 Sandiway Fong.
Context Free Grammars.
CPS 506 Comparative Programming Languages Syntax Specification.
LING 388: Language and Computers Sandiway Fong 9/27 Lecture 10.
LING/C SC/PSYC 438/538 Lecture 13 Sandiway Fong. Administrivia Reading Homework – Chapter 3 of JM: Words and Transducers.
LING/C SC/PSYC 438/538 Lecture 15 Sandiway Fong. Did you install SWI Prolog?
Three Basic Concepts Languages Grammars Automata.
CSC312 Automata Theory Lecture # 26 Chapter # 12 by Cohen Context Free Grammars.
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.
Mathematical Foundations of Computer Science Chapter 3: Regular Languages and Regular Grammars.
LING/C SC/PSYC 438/538 Lecture 19 Sandiway Fong 1.
LING/C SC/PSYC 438/538 Lecture 17 Sandiway Fong. Last Time Talked about: – 1. Declarative (logical) reading of grammar rules – 2. Prolog query: s(String,[]).
Lecture 17: Theory of Automata:2014 Context Free Grammars.
Chapter 1 INTRODUCTION TO THE THEORY OF COMPUTATION.
Describing Syntax and Semantics Chapter 3: Describing Syntax and Semantics Lectures # 6.
Theory of Computation Lecture #
LING/C SC/PSYC 438/538 Lecture 17 Sandiway Fong.
Chapter 7 Regular Grammars
LING/C SC/PSYC 438/538 Lecture 21 Sandiway Fong.
LING/C SC/PSYC 438/538 Lecture 20 Sandiway Fong.
Lecture 7: Definite Clause Grammars
Presentation transcript:

LING 438/538 Computational Linguistics Sandiway Fong Lecture 7: 9/12

2 Administrivia no class (this) Thursday today –homework 2 we will go through the questions in class usual rules apply... –cite your sources (if you use them) –due next Tuesday –in my mailbox by midnight

3 Last Time the definite clause grammar (DCG) system –uses the same computation rule and query format as regular Prolog programs –grammar rules get translated automatically into an equivalent Prolog program s-->[a],b. s(L1,L3):-'C'(L1, a, L2),b(L2,L3). –difference list pairs: –L1 - L3 “s spans the list L1 minus L3” –L1 - L2, L2 - L3. ?- s(List,[]). (grammar rule query)

4 Last Time the definite clause grammar (DCG) system –uses the same computation rule and query format as regular Prolog programs –grammar rules get translated automatically into an equivalent Prolog program s-->[a],b. s(L1,L3):-'C'(L1, a, L2),b(L2,L3). other concepts –difference list pairs: L1 - L3, L1 - L2, L2 - L3. –adding an extra argument to compute a syntax tree

5 Last Time Prolog grammar –s --> [b], a, [’!’]. –a --> [a]. (base case) –a --> [a], a. (right recursive case) s b‘!’‘!’ a a a a s(b,a(a,a(a)),’!’) extra argument to hold a parse tree modified Prolog grammar –a(a(a)) --> [a]. –a(a(a,A)) --> [a], a(A). –s(s(b,A,’!’)) --> [b], a(A), [’!’]. query –?- s(Parse,List,[]).

6 Today’s Topic Regular Grammars (Type-3)

7 Chomsky Hierarchy Regular Grammars FSA Regular Expressions DCG = Type-0 Type-3 Type-2 Type-1 from lecture 5

8 Regular Grammars Regular or Chomsky hierarchy type-3 grammars –are a class of formal grammars with a restricted RHS LHS → RHS“LHS rewrites/expands to RHS” format –x --> y, [t].x --> [t]. (left recursive) or –x --> [t], y.x --> [t]. (right recursive) –where x and y are non-terminals and –t represents a terminal. i.e. all rules contain only a single non-terminal, and (possibly) a single terminal) on the right hand side Note: –can ’ t have both left and right recursive rules at the same time

9 Regular Grammars example (from previous lecture) –s --> [a],b. –b --> [a],b. –b --> [b],c. –b --> [b]. –c --> [b],c. –c --> [b]. query –?- s(L,[]). regular –grammar only contains right recursive rules –or a rule containing a single terminal symbol –right recursive regular grammar

10 Is sheeptalk regular? regular grammar format x --> y, [t]. x --> [t]. (left recursive) or x --> [t],y. x --> [t]. (right recursive) DCG Regular Grammar Rules ( ba! baa! baaa! baaaa! …) –s --> [b], x. –x --> [a], y. –y --> [‘!’]. –y --> [a], y. (note: not y --> y, [a]. ) Note: –can ’ t have both left and right recursive rules at the same time –otherwise, we can write a grammar for some non-regular languages like a n b n DCG Rules ( ba! baa! baaa! baaaa! …) –s --> [b], a, [‘!’]. –a --> [a]. –a --> a, [a].

11 Homework Exercise 1 Question 1 (4pts) 438/538 –convert the following grammar to generate a parse s --> [a],b. b --> [a],b. b --> [b],c. b --> [b]. c --> [b],c. c --> [b]. –new query ?- s(Tree,List,[]). –submit both your grammar and example parses rule restrictions –limit the generative capacity or power of regular grammars strictly speaking, –allowing an extra argument permits regular grammars to have more power –but using the extra argument to compute parses only doesn’t

12 Homework Exercise 2 –a regular grammar for object relative clauses example – the man that I saw grammar –dp --> [the], np. –np --> [man], relc. –relc --> [that], s. –s --> [i], vp. –% object relative sentence –vp --> [saw]. query ?- dp([the,man,that,i,saw],[]). Yes

13 Homework Exercise 2 438/538 Question 1: (2pts) –add regular grammar rules to handle additional examples –the man that you saw –the man that you met Question 2 (2pts) –modify your grammar to generate parses query ?- dp(Tree,[the,man,that,i,saw],[]).

14 Homework Exercise 2 Question 4 (2pts) –modify your grammar to allow the option of dropping the relative pronoun that, –e.g. the man that I saw the man I saw –submit both your grammar and the output –Note: make sure your grammar is still regular Question 3 (3pts) –modify your grammar to accept recursive embeddings of the form the man that I saw that you heard the man that you heard that I saw –submit both your grammar and the output –Note: make sure your grammar is still regular

15 Grammars as Generators regular sheeptalk –s --> [b], x. –x --> [a], y. –y --> [‘!’]. –y --> [a], y. query ?- s(X,[]). X = [b,a,!] ? ; X = [b,a,a,!] ? ; X = [b,a,a,a,!] ? ; a DCG can be used not only to do recognition (yes/no) and return parse structures but can also be used to generate strings of the language generated by the grammar

16 Homework Exercise 3 438/538 this grammar will go into an infinite loop when used as a generator –s --> [a],b. –b --> [a],b. –b --> [b],c. –b --> [b]. –c --> [b],c. –c --> [b]. query ?- s(L,[]). i.e. give me strings generated by the grammar (one at a time) { ab, aab, abb, aaab, aabb, abbb, aaaab, …} –will give a memory error

17 Homework Exercise 3 Question 1 (3pts) –re-arrange example grammar so it doesn ’ t go into an infinite loop immediately –but instead will generate strings from the language one at a time query –?- s(L,[]). L = string1; L = string2; L = string3; and so on… submit both the grammar and the run for the above query (438 optional/538 mandatory) Question 2 (4pts) –is it possible to re-arrange the example grammar to enumerate all the strings of the language? –explain your answer

18 Homework Exercise 4 beyond regular grammars –a n b n = {ab, aabb, aaabbb,... } –is not regular however, a grammar with both left and right recursive rules can accept it –a --> [a], b. –b --> [b]. –b --> a, [b]. examples –this grammar accepts –aabb aaaabbbb –and rejects –aab aaaabbbbb B A b a A B A b a

19 Homework Exercise 4 438/538 Optional (5pts) –write a grammar using left and right recursive regular rules for the non-regular language –ww R where w  {a,b} +, i.e. any non-empty sequence of a’s and b’s, and w R is w in reverse order examples –aabbaa w = aab w R = baa –aaaa w = aa w R = aa –*aaaaa –*abab submit both your grammar and the output

20 Summary Homework 2 –Exercise 1: 4pts –Exercise 2: 9pts –Exercise 3: 3pts + 4pts (optional 438) –Exercise 4: 5pts (optional 438/538)