CFGS – TAKE 2 David Kauchak CS30 – Spring 2015. Admin Today’s mentor hours moved to 6-8pm Assignment 4 graded Assignment 5 - how’s it going? - part A.

Slides:



Advertisements
Similar presentations
So far... A language is a set of strings over an alphabet. We have defined languages by: (i) regular expressions (ii) finite state automata Both (i) and.
Advertisements

Syntactic analysis using Context Free Grammars. Analysis of language Morphological analysis – Chairs, Part Of Speech (POS) tagging – The/DT man/NN left/VBD.
FSG, RegEx, and CFG Chapter 2 Of Sag’s Syntactic Theory.
About Grammars CS 130 Theory of Computation HMU Textbook: Sec 7.1, 6.3, 5.4.
Chapter Chapter Summary Languages and Grammars Finite-State Machines with Output Finite-State Machines with No Output Language Recognition Turing.
LING 438/538 Computational Linguistics Sandiway Fong Lecture 7: 9/12.
CS5371 Theory of Computation
CSC 3130: Automata theory and formal languages Andrej Bogdanov The Chinese University of Hong Kong Context-free.
Foundations of (Theoretical) Computer Science Chapter 2 Lecture Notes (Section 2.1: Context-Free Grammars) David Martin With some.
CS 330 Programming Languages 09 / 13 / 2007 Instructor: Michael Eckmann.
1 Grammars. 2 Grammars express languages Example: the English language.
Introduction to Syntax, with Part-of-Speech Tagging Owen Rambow September 17 & 19.
Chapter 3: Formal Translation Models
Specifying Languages CS 480/680 – Comparative Languages.
Context-Free Grammar CSCI-GA.2590 – Lecture 3 Ralph Grishman NYU.
Constituency Tests Phrase Structure Rules
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.
PARSING David Kauchak CS457 – Fall 2011 some slides adapted from Ray Mooney.
Compiler Construction 1. Objectives Given a context-free grammar, G, and the grammar- independent functions for a recursive-descent parser, complete the.
1 Introduction to Parsing Lecture 5. 2 Outline Regular languages revisited Parser overview Context-free grammars (CFG’s) Derivations.
Lecture 21: Languages and Grammars. Natural Language vs. Formal Language.
Lecture 16 Oct 18 Context-Free Languages (CFL) - basic definitions Examples.
111 Computability, etc. Recap. Present homework. Grammar and machine equivalences. Turing history Homework: Equivalence assignments. Presentation proposals,
CS 2104 Prog. Lang. Concepts Dr. Abhik Roychoudhury School of Computing Introduction.
04/30/13 Last class: summary, goggles, ices Discrete Structures (CS 173) Derek Hoiem, University of Illinois 1 Image: wordpress.com/2011/11/22/lig.
Context-free Grammars Example : S   Shortened notation : S  aSaS   | aSa | bSb S  bSb Which strings can be generated from S ? [Section 6.1]
CSCI 2670 Introduction to Theory of Computing September 21, 2004.
GRAMMARS David Kauchak CS159 – Fall 2014 some slides adapted from Ray Mooney.
Design contex-free grammars that generate: L 1 = { u v : u ∈ {a,b}*, v ∈ {a, c}*, and |u| ≤ |v| ≤ 3 |u| }. L 2 = { a p b q c p a r b 2r : p, q, r ≥ 0 }
A sentence (S) is composed of a noun phrase (NP) and a verb phrase (VP). A noun phrase may be composed of a determiner (D/DET) and a noun (N). A noun phrase.
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.
Languages & Grammars. Grammars  A set of rules which govern the structure of a language Fritz Fritz The dog The dog ate ate left left.
So far... A language is a set of strings over an alphabet. We have defined languages by: (i) regular expressions (ii) finite state automata Both (i) and.
PARSING David Kauchak CS159 – Spring 2011 some slides adapted from Ray Mooney.
Context Free Grammars Reading: Chap 9, Jurafsky & Martin This slide set was adapted from J. Martin, U. Colorado Instructor: Rada Mihalcea.
CS 461 – Sept. 19 Last word on finite automata… –Scanning tokens in a compiler –How do we implement a “state” ? Chapter 2 introduces the 2 nd model of.
Context Free Grammars.
For Wednesday Read chapter 23 Homework: –Chapter 22, exercises 1,4, 7, and 14.
Parsing with Context-Free Grammars for ASR Julia Hirschberg CS 4706 Slides with contributions from Owen Rambow, Kathy McKeown, Dan Jurafsky and James Martin.
Introduction to Parsing
CPE 480 Natural Language Processing Lecture 4: Syntax Adapted from Owen Rambow’s slides for CSc Fall 2006.
CS 182 Sections slides created by Eva Mok modified by JGM March
PARSING 2 David Kauchak CS159 – Spring 2011 some slides adapted from Ray Mooney.
1 Context Free Grammars October Syntactic Grammaticality Doesn’t depend on Having heard the sentence before The sentence being true –I saw a unicorn.
Context Free Grammars CFGs –Add recursion to regular expressions Nested constructions –Notation expression  identifier | number | - expression | ( expression.
1 A well-parenthesized string is a string with the same number of (‘s as )’s which has the property that every prefix of the string has at least as many.
CS 208: Computing Theory Assoc. Prof. Dr. Brahim Hnich Faculty of Computer Sciences Izmir University of Economics.
Re-enter Chomsky More about grammars. 2 Parse trees S  A B A  aA | a B  bB | b Consider L = { a m b n | m, n > 0 } (one/more a ’s followed by one/more.
GRAMMARS David Kauchak CS457 – Spring 2011 some slides adapted from Ray Mooney.
CSC312 Automata Theory Lecture # 26 Chapter # 12 by Cohen Context Free Grammars.
CST229 Week 7 Questions or concerns? Hand back Test#1 & Homework #4 – Test1 Average (45/50) Reading: Chapters 12&13 Chapter 12 – Grammar – production rules.
Formal Languages and Grammars
Mathematical Foundations of Computer Science Chapter 3: Regular Languages and Regular Grammars.
Transparency No. 1 Formal Language and Automata Theory Homework 5.
1 A well-parenthesized string is a string with the same number of (‘s as )’s which has the property that every prefix of the string has at least as many.
PARSING David Kauchak CS159 – Fall Admin Assignment 3 Quiz #1  High: 36  Average: 33 (92%)  Median: 33.5 (93%)
CSE 311 Foundations of Computing I Lecture 19 Recursive Definitions: Context-Free Grammars and Languages Spring
CSE 311 Foundations of Computing I Lecture 20 Context-Free Grammars and Languages Autumn 2012 CSE
Unit 2 How often do you exercise?. Section A Period 1.
Context Free Grammars & Parsing CPSC 388 Fall 2001 Ellen Walker Hiram College.
Lecture 17: Theory of Automata:2014 Context Free Grammars.
Natural Language Processing Vasile Rus
Grammars.
CSE322 LEFT & RIGHT LINEAR REGULAR GRAMMAR
Context-Free Grammars (CFG’s)
CS21 Decidability and Tractability
CSCI 5832 Natural Language Processing
David Kauchak CS159 – Spring 2019
David Kauchak CS159 – Spring 2019
CSCI 432 Computer Science Theory
Presentation transcript:

CFGS – TAKE 2 David Kauchak CS30 – Spring 2015

Admin Today’s mentor hours moved to 6-8pm Assignment 4 graded Assignment 5 - how’s it going? - part A due tonight at 11:59pm - part B due Friday at 6pm

Course feedback Thanks!

Course feedback

Favorite thing about the course Learning Python. It's pretty dope.

Things to be improved Sometimes a lot of the lecture material is covered too quickly. I would appreciate a slightly more comprehensive pace, and easier first examples. Honestly, it's a little slow. But I don't really know how to improve that given that I know literally nothing about coding and need to be walked through things. Maybe focusing more time on reviewing the concepts that we have already learned just to make sure that the idea is really solidified it so that we can use it in a program.

Things to be improved Also I would really enjoy more mentor sessions, on Monday, for example. Or even on Friday. It would be helpful to have a tutor/ mentor session on Sunday nights so that if we run into questions/ issues on homework over the weekend, there is somewhere to get help before Tuesday, aka halfway through the week.

Things to be improved I was talking to a friend about how it'd be really nice to have a buddy to share how I code a function. I thought by watching another person code in a way that is different/similar to yours, you can understand the logic/style better and faster.

Things to be improved We haven't done that many assignments, but one of them had some grading I didn't understand. I feel like that was an anomaly though.

Things to be improved More high-five breaks!

Other thoughts I would really like to do Turing Machines in this class I think they're fun & have interesting connections/applications to computation/ the human mind

Comments in the future…

Grammars Language view: A grammar is a set of structural rules that govern the composition of sentences, phrases and words. Computational view: A grammar (often called a “formal grammar”) is a set of rules that describe what strings are valid in a formal language.

CFG production rules S  NP VP left hand side (single symbol) right hand side (one or more symbols)

CFG example S  A B C A  I B  really B  really, B C  like cs Grammars “generate” or “derive” strings: S

CFG example S  A B C A  I B  really B  really, B C  like cs Grammars “generate” or “derive” strings: S We can apply a rule by substituting the symbol on the left hand side with the symbols on the right

CFG example S  A B C A  I B  really B  really, B C  like cs Grammars “generate” or “derive” strings: A B C We can apply a rule by substituting the symbol on the left hand side with the symbols on the right

CFG example S  A B C A  I B  really B  really, B C  like cs Grammars “generate” or “derive” strings: A B C We can apply a rule by substituting the symbol on the left hand side with the symbols on the right

CFG example S  A B C A  I B  really B  really, B C  like cs Grammars “generate” or “derive” strings: A really C We can apply a rule by substituting the symbol on the left hand side with the symbols on the right

CFG example S  A B C A  I B  really B  really, B C  like cs Grammars “generate” or “derive” strings: A really C We can apply a rule by substituting the symbol on the left hand side with the symbols on the right

CFG example S  A B C A  I B  really B  really, B C  like cs Grammars “generate” or “derive” strings: A really like cs We can apply a rule by substituting the symbol on the left hand side with the symbols on the right

CFG example S  A B C A  I B  really B  really, B C  like cs Grammars “generate” or “derive” strings: A really like cs We can apply a rule by substituting the symbol on the left hand side with the symbols on the right

CFG example S  A B C A  I B  really B  really, B C  like cs Grammars “generate” or “derive” strings: I really like cs We can apply a rule by substituting the symbol on the left hand side with the symbols on the right

CFG example S  A B C A  I B  really B  really, B C  like cs Grammars “generate” or “derive” strings: I really like cs We can apply a rule by substituting the symbol on the left hand side with the symbols on the right No more rules apply, so we’re done!

CFG example S  A B C A  I B  really B  really, B C  like cs Grammars “generate” or “derive” strings: I really like cs We can apply a rule by substituting the symbol on the left hand side with the symbols on the right

CFG example S  A B C A  I B  really B  really, B C  like cs Grammars “generate” or “derive” strings: A really, B C We can apply a rule by substituting the symbol on the left hand side with the symbols on the right

CFG example S  A B C A  I B  really B  really, B C  like cs Grammars “generate” or “derive” strings: A really, really, B C We can apply a rule by substituting the symbol on the left hand side with the symbols on the right

CFG example S  A B C A  I B  really B  really, B C  like cs I really, really, … like cs Grammars describe a language, i.e. the strings (aka sentences) that are part of that language

What language does this represent? S  aS S  E E  bE E  b

What language does this represent? S  aS S  E E  bE E  b S Two options

What language does this represent? S  aS S  E E  bE E  b aS S

What language does this represent? S  aS S  E E  bE E  b aaS aSaS

What language does this represent? S  aS S  E E  bE E  b aaaS aaS - Can do this as many times as we want - Keeps adding more a’s to the front

What language does this represent? S  aS S  E E  bE E  b aaaE aaaS Eventually, apply second rule

What language does this represent? S  aS S  E E  bE E  b aaaE Two options

What language does this represent? S  aS S  E E  bE E  b aaaE aaabE

What language does this represent? S  aS S  E E  bE E  b aaabE aaabbE

What language does this represent? S  aS S  E E  bE E  b aaabbE aaabbbE

What language does this represent? S  aS S  E E  bE E  b aaabbE aaabb…bE - Can do this as many times as we want - Keeps adding more b’s to the end

What language does this represent? S  aS S  E E  bE E  b aaabb…bE aaabb…bb Eventually, apply second rule

What language does this represent? S  aS S  E E  bE E  b aaabb…bE aaabb…bb Grammar represents all strings with zero or more a’s followed by one or more b’s

Notational convenience S  aS S  E E  bE E  b S  aS | E E  bE | b

Often many ways to write the same language S  aS | E E  bE | b S  aS | E E  Eb | b S  aS | aaS | E E  Eb | b

What languages do these represent? S  aSb S  ab S  aEa | bEb E  Ea | Eb | a | b S  aaS | abS | baS | bbS | ε nothing

What languages do these represent? S  aSb S  ab S  aaS | abS | baS | bbS | ε all strings of a’s and b’s that start and end with the same letter strings of a’s followed by an equal number of b’s all strings of a’s and b’s with even length S  aEa | bEb E  Ea | Eb | a | b

Writing CFGs Write a CFG to represent the language containing all strings that start with a. S  aT T  Ta | Tb | ε

Writing CFGs Write a CFG to represent the language containing all strings with exactly two bs. S  TbTbT T  Ta | ε

CFG: Another example Many possible CFGs for English, here is an example (fragment): S  NP VP VP  V NP NP  DetP N | DetP AdjP N AdjP  Adj | Adv AdjP N  boy | girl V  sees | likes Adj  big | small Adv  very DetP  a | the

Derivations in a CFG S  NP VP VP  V NP NP  DetP N | DetP AdjP N AdjP  Adj | Adv AdjP N  boy | girl V  sees | likes Adj  big | small Adv  very DetP  a | the S What can we do?

Derivations in a CFG S  NP VP VP  V NP NP  DetP N | DetP AdjP N AdjP  Adj | Adv AdjP N  boy | girl V  sees | likes Adj  big | small Adv  very DetP  a | the S

Derivations in a CFG S  NP VP VP  V NP NP  DetP N | DetP AdjP N AdjP  Adj | Adv AdjP N  boy | girl V  sees | likes Adj  big | small Adv  very DetP  a | the NP VP What can we do?

Derivations in a CFG S  NP VP VP  V NP NP  DetP N | DetP AdjP N AdjP  Adj | Adv AdjP N  boy | girl V  sees | likes Adj  big | small Adv  very DetP  a | the NP VP

Derivations in a CFG S  NP VP VP  V NP NP  DetP N | DetP AdjP N AdjP  Adj | Adv AdjP N  boy | girl V  sees | likes Adj  big | small Adv  very DetP  a | the DetP N VP

Derivations in a CFG S  NP VP VP  V NP NP  DetP N | DetP AdjP N AdjP  Adj | Adv AdjP N  boy | girl V  sees | likes Adj  big | small Adv  very DetP  a | the DetP N VP

Derivations in a CFG S  NP VP VP  V NP NP  DetP N | DetP AdjP N AdjP  Adj | Adv AdjP N  boy | girl V  sees | likes Adj  big | small Adv  very DetP  a | the the boy VP

Derivations in a CFG S  NP VP VP  V NP NP  DetP N | DetP AdjP N AdjP  Adj | Adv AdjP N  boy | girl V  sees | likes Adj  big | small Adv  very DetP  a | the the boy likes NP

Derivations in a CFG S  NP VP VP  V NP NP  DetP N | DetP AdjP N AdjP  Adj | Adv AdjP N  boy | girl V  sees | likes Adj  big | small Adv  very DetP  a | the the boy likes a girl

Derivations in a CFG: Order of Derivation Irrelevant S  NP VP VP  V NP NP  DetP N | DetP AdjP N AdjP  Adj | Adv AdjP N  boy | girl V  sees | likes Adj  big | small Adv  very DetP  a | the NP VP DetP N VPNP V NP the boy likes a girl

Derivations of CFGs Derivation history shows a tree: the boy likes a girl boythelikes DetP NP girl a NP DetP S VP N N V

Another CFG example S  NP VP VP  V | V ADV NP  ART PreNP PreNP  N | ADJ PreNP ADV  furiously | soothingly | intentionally ADJ  colorless | green | smelly ART  the | a V  sleeps | eats | swims | sprints N  idea | bagel | milk | cow What can we generate?

One last example S  N S  ( S ) S  S + S | S - S S  S * S | S / S N  0 | 1 | 2 | … | 9 N  N N What language does this CFG represent?

One last example S  N S  ( S ) S  S + S | S - S S  S * S | S / S N  0 | 1 | 2 | … | 9 N  N N All arithmetic expressions!

Parsing Given a CFG and a sentence, determine the possible parse tree(s) S -> NP VP NP -> N NP -> PRP NP -> N PP VP -> V NP VP -> V NP PP PP -> IN N PRP -> I V -> eat N -> sushi N -> tuna IN -> with I eat sushi with tuna What parse trees are possible for this sentence? How did you do it? What if the grammar is much larger?

Parsing I eat sushi with tuna PRP NP VNINN PP NP VP S I eat sushi with tuna PRP NP VNINN PP NP VP S S -> NP VP NP -> PRP NP -> N PP NP -> N VP -> V NP VP -> V NP PP PP -> IN N PRP -> I V -> eat N -> sushi N -> tuna IN -> with What is the difference between these parses?

CFGs implemented

Midterm Average: 26.3 (82.5%) Median: 27.5 (86%) Quartiles: - Q1: 30 (97.5%) - Q2: 27.5 (86%) - Q3: 25 (78%)