LING/C SC 581: Advanced Computational Linguistics Lecture Notes Jan 13 th.

Slides:



Advertisements
Similar presentations
A question from last class: construct the predictive parsing table for this grammar: S->i E t S e S | i E t S | a E -> B.
Advertisements

Compiler Principles Fall Compiler Principles Lecture 4: Parsing part 3 Roman Manevich Ben-Gurion University.
Bottom up Parsing Bottom up parsing trys to transform the input string into the start symbol. Moves through a sequence of sentential forms (sequence of.
C O N T E X T - F R E E LANGUAGES ( use a grammar to describe a language) 1.
CFGs and PDAs Sipser 2 (pages ). Long long ago…
LING/C SC 581: Advanced Computational Linguistics Lecture Notes Jan 15 th.
Pushdown Automata Consists of –Pushdown stack (can have terminals and nonterminals) –Finite state automaton control Can do one of three actions (based.
Mooly Sagiv and Roman Manevich School of Computer Science
CFGs and PDAs Sipser 2 (pages ). Last time…
Cse321, Programming Languages and Compilers 1 6/12/2015 Lecture #10, Feb. 14, 2007 Modified sets of item construction Rules for building LR parse tables.
6/12/2015Prof. Hilfinger CS164 Lecture 111 Bottom-Up Parsing Lecture (From slides by G. Necula & R. Bodik)
Amirkabir University of Technology Computer Engineering Faculty AILAB Efficient Parsing Ahmad Abdollahzadeh Barfouroush Aban 1381 Natural Language Processing.
CS Summer 2005 Top-down and Bottom-up Parsing - a whirlwind tour June 20, 2005 Slide acknowledgment: Radu Rugina, CS 412.
Lecture #8, Feb. 7, 2007 Shift-reduce parsing,
Prof. Fateman CS 164 Lecture 91 Bottom-Up Parsing Lecture 9.
LR(k) Grammar David Rodriguez-Velazquez CS6800-Summer I, 2009 Dr. Elise De Doncker.
Table-driven parsing Parsing performed by a finite state machine. Parsing algorithm is language-independent. FSM driven by table (s) generated automatically.
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.
2/20/2008Prof. Hilfinger CS164 Lecture 121 Earley’s Algorithm: General Context-Free Parsing Lecture 12 P. N. Hilfinger.
Bottom-up parsing Goal of parser : build a derivation
Parsing IV Bottom-up Parsing Copyright 2003, Keith D. Cooper, Ken Kennedy & Linda Torczon, all rights reserved. Students enrolled in Comp 412 at Rice University.
11/22/1999 JHU CS /Jan Hajic 1 Introduction to Natural Language Processing ( ) Shift-Reduce Parsing in Detail Dr. Jan Hajič CS Dept., Johns.
Syntax and Semantics Structure of programming languages.
1 Natural Language Processing Lecture 11 Efficient Parsing Reading: James Allen NLU (Chapter 6)
Parsing Jaruloj Chongstitvatana Department of Mathematics and Computer Science Chulalongkorn University.
10. Parsing with Context-free Grammars -Speech and Language Processing- 발표자 : 정영임 발표일 :
LANGUAGE TRANSLATORS: WEEK 17 scom.hud.ac.uk/scomtlm/cis2380/ See Appel’s book chapter 3 for support reading Last Week: Top-down, Table driven parsers.
1 Compiler Construction Syntax Analysis Top-down parsing.
Review 1.Lexical Analysis 2.Syntax Analysis 3.Semantic Analysis 4.Code Generation 5.Code Optimization.
CS 153 A little bit about LR Parsing. Background We’ve seen three ways to write parsers:  By hand, typically recursive descent  Using parsing combinators.
Chapter 3-3 Chang Chi-Chung Bottom-Up Parsing LR methods (Left-to-right, Rightmost derivation)  LR(0), SLR, Canonical LR = LR(1), LALR 
Syntax and Semantics Structure of programming languages.
LING 438/538 Computational Linguistics Sandiway Fong Lecture 25: 11/21.
Pushdown Automata Chapters Generators vs. Recognizers For Regular Languages: –regular expressions are generators –FAs are recognizers For Context-free.
Basic Parsing Algorithms: Earley Parser and Left Corner Parsing
111 Chapter 6 LR Parsing Techniques Prof Chung. 1.
CS 4705 Lecture 10 The Earley Algorithm. Review Top-Down vs. Bottom-Up Parsers –Both generate too many useless trees –Combine the two to avoid over-generation:
1Computer Sciences Department. Book: INTRODUCTION TO THE THEORY OF COMPUTATION, SECOND EDITION, by: MICHAEL SIPSER Reference 3Computer Sciences Department.
PZ03A Programming Language design and Implementation -4th Edition Copyright©Prentice Hall, PZ03A - Pushdown automata Programming Language Design.
Top-Down Parsing CS 671 January 29, CS 671 – Spring Where Are We? Source code: if (b==0) a = “Hi”; Token Stream: if (b == 0) a = “Hi”; Abstract.
CS3230R. What is a parser? What is an LR parser? A bottom-up parser that efficiently handles deterministic context-free languages in guaranteed linear.
GRAMMARS & PARSING. Parser Construction Most of the work involved in constructing a parser is carried out automatically by a program, referred to as a.
Bernd Fischer RW713: Compiler and Software Language Engineering.
Bottom Up Parsing CS 671 January 31, CS 671 – Spring Where Are We? Finished Top-Down Parsing Starting Bottom-Up Parsing Lexical Analysis.
CS412/413 Introduction to Compilers and Translators Spring ’99 Lecture 6: LR grammars and automatic parser generators.
Compilers: Bottom-up/6 1 Compiler Structures Objective – –describe bottom-up (LR) parsing using shift- reduce and parse tables – –explain how LR.
1 Chapter 6 Bottom-Up Parsing. 2 Bottom-up Parsing A bottom-up parsing corresponds to the construction of a parse tree for an input tokens beginning at.
Formal grammars A formal grammar is a system for defining the syntax of a language by specifying sequences of symbols or sentences that are considered.
CMSC 330: Organization of Programming Languages Pushdown Automata Parsing.
CS 154 Formal Languages and Computability March 22 Class Meeting Department of Computer Science San Jose State University Spring 2016 Instructor: Ron Mak.
COMPILER CONSTRUCTION
Syntax and Semantics Structure of programming languages.
Programming Languages Translator
UNIT - 3 SYNTAX ANALYSIS - II
Table-driven parsing Parsing performed by a finite state machine.
CS 404 Introduction to Compiler Design
Fall Compiler Principles Lecture 4: Parsing part 3
4 (c) parsing.
LING/C SC 581: Advanced Computational Linguistics
Subject Name:COMPILER DESIGN Subject Code:10CS63
Lexical and Syntax Analysis
Top-Down Parsing CS 671 January 29, 2008.
Compilers Principles, Techniques, & Tools Taught by Jing Zhang
Parsing and More Parsing
Kanat Bolazar February 16, 2010
CSA2050 Introduction to Computational Linguistics
Parsing Bottom-Up LR Table Construction.
Parsing Bottom-Up LR Table Construction.
LING/C SC 581: Advanced Computational Linguistics
Parsing CSCI 432 Computer Science Theory
Presentation transcript:

LING/C SC 581: Advanced Computational Linguistics Lecture Notes Jan 13 th

Course Webpage for lecture slides and Panopto recordings: – Meeting information new server!

Course Dates: no class on – Feb 10 th : (out of town) – Mar 16 th : Spring Break Date: – May 4 th : last day of classes = Wednesday

Course Objectives Follow-on course to LING/C SC/PSYC 438/538 Computational Linguistics: – continue with J&M: 25 chapters, a lot of material not covered in 438/538 And gain more extensive experience – dealing with natural language software packages – Installation, input data formatting – operation – project exercises – useful “real-world” computational experience – abilities gained will be of value to employers

Computational Facilities Use your own laptop/desktop Platforms Windows is maybe possible but you really should run some variant of Unix… – Linux (separate bootable partition or via virtualization software) de facto standard for advanced/research software (free!) – Cygwin on Windows Linux-like environment for Windows making it possible to port software running on POSIX systems (such as Linux, BSD, and Unix systems) to Windows. – Mac OS X Not quite Linux, some porting issues, especially with C programs, can use Virtual Box under OS X

Grading Completion of all homework tasks will result in a satisfactory grade (A) Tasks should be completed before the next class. – me your work – Also be prepared to come up and present your work (if called upon).

Parsing methods (538) From 538 (last semester), we covered a few different methods: – top-down, left-to-right Prolog default search strategy – problem: left recursion – solution: rewrite grammar into a non-left recursive grammar – solution: can keep left recursive parses

Parsing methods (538) CKY algorithm – rewrite grammar into Chomsky Normal Form (CNF) – binary branching syntax rules plus unary POS rules – use a 2D table – Example: 0 w 1 1 w 2 2 w 3 3 (0..3 are position markers) w1w1 w2w2 w3w3 [0,1][0,2][0,3] [1,2][1,3] [2,3]

Bottom-Up Parsing LR(0) parsing – An example of bottom-up tabular parsing – Similar to the top-down Earley algorithm described in the textbook in that it uses the idea of dotted rules – finite state automata revisited…

Tabular Parsing e.g. LR(k) (Knuth, 1960) – invented for efficient parsing of programming languages – disadvantage: a potentially huge number of states can be generated when the number of rules in the grammar is large – can be applied to natural languages (Tomita 1985) – build a Finite State Automaton (FSA) from the grammar rules, then add a stack tables encode the grammar (FSA) – grammar rules are compiled – no longer interpret the grammar rules directly Parser = Table + Push-down Stack – table entries contain instruction(s) that tell what to do at a given state … possibly factoring in lookahead – stack data structure deals with maintaining the history of computation and recursion

Tabular Parsing Shift-Reduce Parsing – example LR(0) – left to right – bottom-up – (0) no lookahead (input word) Three possible machine actions – Shift: read an input word » i.e. advance current input word pointer to the next word – Reduce: complete a nonterminal » i.e. complete parsing a grammar rule – Accept: complete the parse » i.e. start symbol (e.g. S) derives the terminal string

Tabular Parsing LR(0) Parsing – L(G) = LR(0) i.e. the language generated by grammar G is LR(0) if there is a unique instruction per state (or no instruction = error state) LR(0) is a proper subset of context-free languages – note human language tends to be ambiguous there are likely to be multiple or conflicting actions per state if we are using Prolog, we can let Prolog’s computation rule handle it – via Prolog backtracking deterministic!

Tabular Parsing Dotted rule notation – “dot” used to track the progress of a parse through a phrase structure rule – examples vp --> v. np means we’ve seen v and predict np np -->. d np means we’re predicting a d (followed by np) vp --> vp pp. means we’ve completed a vp state – a set of dotted rules encodes the state of the parse – set of dotted rules = name of the state kernel vp --> v. np vp --> v. completion (of predict NP) np -->. d n np -->. n np -->. np cp

Tabular Parsing compute possible states by advancing the dot – example: – (Assume d is next in the input) vp --> v. np vp --> v.(eliminated) np --> d. n np -->. n(eliminated) np -->. np cp

Tabular Parsing Dotted rules – example State 0: s -->. np vp np -->.d n np -->.n np -->.np pp – possible actions shift d and go to new state shift n and go to new state Creating new states s -->. np vp np -->.d n np -->.n np -->.np pp np --> d. n np --> n. State 0 State 2 State 1 shift d shift n

Tabular Parsing State 1: Shift N, goto State 3 s -->. np vp np -->.d n np -->.n np -->.np pp np --> d. n np --> n. State 0 State 2 State 1 shift d shift n np --> d n. shift n State 3

Tabular Parsing Shift – take input word, and – put it on the stack Input Stack state 3 s -->. np vp np -->.d n np -->.n np -->.np pp np --> d. n np --> n. State 0 State 2 State 1 shift d shift n np --> d n. shift n State 3 [ D a ] [ N man][ V hit ] … [ N man][ V hit ] …[ V hit ] … [ D a ][ N man] [ D a ] (Powerpoint animation)

Tabular Parsing State 2: Reduce action np --> n. s -->. np vp np -->.d n np -->.n np -->.np pp np --> d. n np --> n. State 0 State 2 State 1 shift d shift n State 3 np --> d n.

Tabular Parsing Reduce NP -> N. – pop [ N milk] off the stack, and – replace with [ NP [ N milk]] on stack [ V is ] … [ N milk] Input Stack State 2 [ NP milk]

Tabular Parsing State 3: Reduce np --> d n. s -->. np vp np -->.d n np -->.n np -->.np pp np --> d. n np --> n. State 0 State 2 State 1 shift d shift n State 3 np --> d n.

Tabular Parsing Reduce NP -> D N. – pop [ N man] and [ D a] off the stack – replace with [ NP [ D a][ N man]] [ V hit ] … [ N man] [ D a ] Input Stack State 3 [ NP [ D a ][ N man]]

Tabular Parsing State 0: Transition NP s -->. np vp np -->.d n np -->.n np -->.np pp np --> d. n np --> n. State 0 State 2 State 1 shift d shift n State 3 np --> d n. s --> np. vp np --> np. pp vp -->. v np vp -->. v vp -->. vp pp pp -->. p np np State 4

Tabular Parsing for both states 2 and 3 – NP -> N.(reduce NP -> N) – NP -> D N.(reduce NP -> D N) after Reduce NP operation – goto state 4 notes: – states are unique – grammar is finite – procedure generating states must terminate since the number of possible dotted rules is finite – no left recursion problem (bottom-up means input driven)

Tabular Parsing StateActionGoto 0Shift d Shift n Reduce np --> n4 3Reduce np --> d n4 4……

Tabular Parsing Observations table is sparse example State 0, Input: [ V..] parse fails immediately in a given state, input may be irrelevant example State 2 (there is no shift operation) there may be action conflicts example State 1: shift D, shift N(only if word is ambiguous…) more interesting cases shift-reduce and reduce-reduce conflicts

Tabular Parsing finishing up – an extra initial rule is usually added to the grammar – SS --> S. $ SS = start symbol $ = end of sentence marker – input: milk is good for you $ – accept action discard $ from input return element at the top of stack as the parse tree

LR Parsing in Prolog Recap – finite state machine technology + a stack each state represents a set of dotted rules – Example –s -->. np vp –np -->.d n –np -->.n –np -->.np pp we transition, i.e. move, from state to state by advancing the “dot” over the possible terminal and nonterminal symbols

LR State Machine State 0 ss .s $ s .np vp np .np pp np .n np .d n State 0 ss .s $ s .np vp np .np pp np .n np .d n State 1 ss  s.$ State 1 ss  s.$ State 13 ss  s $. State 13 ss  s $. $ s State 4 s  np.vp np  np.pp vp .v np vp .v vp .vp pp pp .p np State 4 s  np.vp np  np.pp vp .v np vp .v vp .vp pp pp .p np State 2 np  d.n State 2 np  d.n State 12 np  d n. State 12 np  d n. State 3 np  n. State 3 np  n. n d n np State 5 np  np pp. State 5 np  np pp. pp State 6 pp  p.np np .np pp np .n np .d n State 6 pp  p.np np .np pp np .n np .d n State 7 vp  v.np vp  v. np .np pp np .n np .d n State 7 vp  v.np vp  v. np .np pp np .n np .d n p v n d d n State 8 s  np vp. vp  vp.pp pp .p np State 8 s  np vp. vp  vp.pp pp .p np vp State 9 vp  vp pp. State 9 vp  vp pp. pp State 10 vp  v np. np  np. pp pp .p np State 10 vp  v np. np  np. pp pp .p np np State 11 pp  p np. np  np. pp pp .p np State 11 pp  p np. np  np. pp pp .p np np p pp p p [animation]

Build Actions two main actions – Shift move a word from the input onto the stack Example: –np -->.d n – Reduce build a new constituent Example: –np --> d n.

Lookahead LR(1) – a shift/reduce tabular parser – using one (terminal) lookahead symbol decide on whether to take a reduce action depending on state x next input symbol Example – select the valid reduce operation consulting the next word – cf. LR(0): select an action based on just the current state

Lookahead potential advantage – the input symbol may partition the action space – resulting in fewer conflicts provided the current input symbol can help to choose between possible actions potential disadvantages – larger finite state machine more possible dotted rule/lookahead combinations than just dotted rule combinations – might not help much depends on grammar – more complex (off-line) computation building the LR machine gets more complicated

Lookahead formally – X --> α.Yβ, L L = lookahead set L = set of possible terminals that can follow X α,β (possibly empty) strings of terminal/non-terminals example – State 0 ss-->.s $ [[]] s-->.np vp [$] np-->.d n [p,v] np-->.n [p,v] np-->.np pp [p,v]

Lookahead central idea for propagating lookahead in state machine – if dotted rule is complete, – lookahead informs parser about what the next terminal symbol should be – example NP --> D N., L reduce by NP rule provided current input symbol is in set L

LR Parsing in fact – LR-parsers are generally acknowledged to be the fastest parsers especially when combined with the chart technique (table: dynamic programming) – reference (Tomita, 1985) – textbook Earley’s algorithm uses chart but follows the dotted-rule configurations dynamically at parse-time instead of ahead of time (so slower than LR)