Vorlesung 7: Ein effizienter CYK Parser

Similar documents
October 19, 2004 Chapter Parsing

Parsing. Earley Parsing. Laura Kallmeyer. Winter 2017/18. Heinrich-Heine-Universität Düsseldorf 1 / 39

LL(k) Parsing. Predictive Parsers. LL(k) Parser Structure. Sample Parse Table. LL(1) Parsing Algorithm. Push RHS in Reverse Order 10/17/2012

Ling/CSE 472: Introduction to Computational Linguistics. 5/4/17 Parsing

The CKY Parsing Algorithm and PCFGs. COMP-550 Oct 12, 2017

The CKY Parsing Algorithm and PCFGs. COMP-599 Oct 12, 2016

Homework & NLTK. CS 181: Natural Language Processing Lecture 9: Context Free Grammars. Motivation. Formal Def of CFG. Uses of CFG.

Chapter 4. Lexical and Syntax Analysis. Topics. Compilation. Language Implementation. Issues in Lexical and Syntax Analysis.

Computational Linguistics

Ling 571: Deep Processing for Natural Language Processing

Derivations vs Parses. Example. Parse Tree. Ambiguity. Different Parse Trees. Context Free Grammars 9/18/2012

Homework & Announcements

Natural Language Processing

MidTerm Papers Solved MCQS with Reference (1 to 22 lectures)

The Parsing Problem (cont d) Recursive-Descent Parsing. Recursive-Descent Parsing (cont d) ICOM 4036 Programming Languages. The Complexity of Parsing

Downloaded from Page 1. LR Parsing

Parsing Algorithms. Parsing: continued. Top Down Parsing. Predictive Parser. David Notkin Autumn 2008

Section A. A grammar that produces more than one parse tree for some sentences is said to be ambiguous.

Algorithms for NLP. Chart Parsing. Reading: James Allen, Natural Language Understanding. Section 3.4, pp

Dependency Parsing CMSC 723 / LING 723 / INST 725. Marine Carpuat. Fig credits: Joakim Nivre, Dan Jurafsky & James Martin

Revisit the example. Transformed DFA 10/1/16 A B C D E. Start

PART 3 - SYNTAX ANALYSIS. F. Wotawa TU Graz) Compiler Construction Summer term / 309

Elements of Language Processing and Learning lecture 3

MST & Shortest Path -Prim s -Djikstra s

2068 (I) Attempt all questions.

Chapter 3. Parsing #1

Gujarat Technological University Sankalchand Patel College of Engineering, Visnagar B.E. Semester VII (CE) July-Nov Compiler Design (170701)

Algorithms for NLP. Chart Parsing. Reading: James Allen, Natural Language Understanding. Section 3.4, pp

Andreas Daul Natalie Clarius

Parsing Chart Extensions 1

CS143 Handout 20 Summer 2011 July 15 th, 2011 CS143 Practice Midterm and Solution

Midterm 2 Solutions Many acceptable answers; one was the following: (defparameter g1

CSCE 314 TAMU Fall CSCE 314: Programming Languages Dr. Flemming Andersen. Functional Parsers

A language is a subset of the set of all strings over some alphabet. string: a sequence of symbols alphabet: a set of symbols

DEPARTMENT OF COMPUTER SCIENCE AND ENGINEERING

Syntax Analysis: Context-free Grammars, Pushdown Automata and Parsing Part - 4. Y.N. Srikant

Parsing III. CS434 Lecture 8 Spring 2005 Department of Computer Science University of Alabama Joel Jones

COP 3402 Systems Software Syntax Analysis (Parser)


CSE 3302 Programming Languages Lecture 2: Syntax

An Efficient Implementation of PATR for Categorial Unification Grammar

Solving systems of regular expression equations

컴파일러입문 제 6 장 구문분석

Earley Parsing in Action

Admin PARSING. Backoff models: absolute discounting. Backoff models: absolute discounting 3/4/11. What is (xy)?

Syntax-Directed Translation. Lecture 14

4. Lexical and Syntax Analysis

Syntax Analysis Part I

CSCE 314 Programming Languages. Functional Parsers

Lexical and Syntax Analysis. Top-Down Parsing

Compilation 2012 Context-Free Languages Parsers and Scanners. Jan Midtgaard Michael I. Schwartzbach Aarhus University

4. Lexical and Syntax Analysis

Chapter 4. Lexical and Syntax Analysis

Parsing #1. Leonidas Fegaras. CSE 5317/4305 L3: Parsing #1 1

VIVA QUESTIONS WITH ANSWERS

Parsing Techniques. CS152. Chris Pollett. Sep. 24, 2008.

Building a Parser III. CS164 3:30-5:00 TT 10 Evans. Prof. Bodik CS 164 Lecture 6 1

Chapter 10: Compiler I: Syntax Analysis

Roll No. :... Invigilator's Signature :. CS/B.Tech(CSE)/SEM-7/CS-701/ LANGUAGE PROCESSOR. Time Allotted : 3 Hours Full Marks : 70

Parsing a primer. Ralf Lämmel Software Languages Team University of Koblenz-Landau

LECTURE 3. Compiler Phases

Assignment 4 CSE 517: Natural Language Processing

Syntax Analysis, III Comp 412

First Midterm Exam CS164, Fall 2007 Oct 2, 2007

Exercise 1: Balanced Parentheses

CS2210: Compiler Construction Syntax Analysis Syntax Analysis

CSCE 314 Programming Languages

11-682: Introduction to IR, NLP, MT and Speech. Parsing with Unification Grammars. Reading: Jurafsky and Martin, Speech and Language Processing

LECTURE NOTES ON COMPILER DESIGN P a g e 2

Parsing II Top-down parsing. Comp 412

CMSC 330: Organization of Programming Languages

The analysis part breaks up the source program into constituent pieces and creates an intermediate representation of the source program.

Part 3. Syntax analysis. Syntax analysis 96

UNIVERSITY OF EDINBURGH COLLEGE OF SCIENCE AND ENGINEERING SCHOOL OF INFORMATICS INFR08008 INFORMATICS 2A: PROCESSING FORMAL AND NATURAL LANGUAGES

6.863J Natural Language Processing Lecture 7: parsing with hierarchical structures context-free parsing. Robert C. Berwick

Introduction to parsers

CYK parsing. I love automata theory I love love automata automata theory I love automata love automata theory I love automata theory

Context-Free Grammars

General Overview of Compiler

Topics in Parsing: Context and Markovization; Dependency Parsing. COMP-599 Oct 17, 2016

Compila(on (Semester A, 2013/14)

Lecture Notes on Shift-Reduce Parsing

syntax tree - * * * - * * * * * 2 1 * * 2 * (2 * 1) - (1 + 0)

Lecture 8: Context Free Grammars

Syntax Analysis, III Comp 412

Compiler I: Syntax Analysis

CS224n: Natural Language Processing with Deep Learning 1 Lecture Notes: Part IV Dependency Parsing 2 Winter 2019

Introduction to Syntax Analysis

Sardar Vallabhbhai Patel Institute of Technology (SVIT), Vasad M.C.A. Department COSMOS LECTURE SERIES ( ) (ODD) Code Optimization

Configuration Sets for CSX- Lite. Parser Action Table

Parsing. Roadmap. > Context-free grammars > Derivations and precedence > Top-down parsing > Left-recursion > Look-ahead > Table-driven parsing

CS1622. Today. A Recursive Descent Parser. Preliminaries. Lecture 9 Parsing (4)

PL Revision overview

Chapter 4: LR Parsing

CPS 506 Comparative Programming Languages. Syntax Specification

Intro to Bottom-up Parsing. Lecture 9

CSCE 314 Programming Languages. Monadic Parsing

Context-Free Grammars

CYK- and Earley s Approach to Parsing

CSE450 Translation of Programming Languages. Lecture 4: Syntax Analysis

Transcription:

Institut für Computerlinguistik, Uni Zürich: Effiziente Analyse unbeschränkter Texte Vorlesung 7: Ein effizienter CYK Parser Gerold Schneider Institute of Computational Linguistics, University of Zurich Department of Linguistics, University of Geneva gschneidifi.unizh.ch December 1, 2003 1

Contents 1. Dependency Grammar (DG) and Chomsky Normal orm (CN) 2. Bottom-up Chart Parsing 3. CYK Characteristics 4. The CYK algorithm 5. A Prolog CYK Parser 6. The implementation 7. Differences between CYK and Earley 8. Differences between CYK and Shift-Reduce 2

1 Dependency Grammar (DG) and Chomsky Normal orm (CN) In a binary CG, any two constituents A and B which are adjacent during parsing are candidates for the RHS of a rewrite rule. In DG and Bare Phrase Structure, one of these is isomorphic to the RHS, i.e. the head. B! AB; e:g: NN! DT NN (1) A! AB; e:g: V B! V B PP (2) All relations are between 1 mother and 1 daughter! binary rules No null dependents (empty elements) No cycles All rules are thus in Chomsky Normal orm (CN) 3

2 Bottom-up Chart Parsing Def.: [ rom; CAT; T o] is an edge of category CAT from sentence position rom to sentence position To. General idea: 1. Dynamic programming: fill in tables of partial solutions to sub-problems until they contain all the solutions needed to solve the problem. 2. Build lexical edges [n; T ag; n] for each word in the sentence 1::n::m and add them to the chart 3. Combine edges according to syntax rules in all permissible ways 4. Proceed step-wise from shorter to longer structures until [1; ;m] has been found 4

2.1 CYK Characteristics Effiziente Analyse unbeschränkter Texte: Ein effizienter CYK Parser Structure length is monotonically increasing: every result of a combination is longer than the combined elements This means that if we start at the shortest edges (the lexical items) and at every repeated step search for edges that are 1 word longer we never have to backtrack. for j = 2 to n # length of edge An edge can start anywhere, at the latest at n j. i for = 1 n j + 1 to # beginning of edge Binary non-empty rules mean that every edge 1::(i + j) can be separated in (i + j) 1 exactly ways, e.g. 1::4: 1 j 234 1234! j 12 34 4 123j for k = i + 1 to i + j 1 # separator position 5

2.2 The CYK algorithm, step 1: j=2 CYK Parsing: bottom-up parallel processing, passive chart j for = 2 N to # length of span i for = 1 N j + 1 to # begin of span k for i + 1 = i + j 1 to # separator position Z! XY if X 2 [i k];y 2 [k j] and Z =2 [i j] and then Z insert [i j] at i increases! A B B C C D D E E j = 2 A B C D E 6

2.3 The CYK algorithm, step 2: j=3 CYK Parsing: bottom-up parallel processing, passive chart j for = 2 N to # length of span i for = 1 N j + 1 to # begin of span k for i + 1 = i + j 1 to # separator position Z! XY if X 2 [i k];y 2 [k j] and j = 3 Z =2 [i j] and then Z insert [i j] at A C B D C E D A B B C C D D E E A B C D E 7

2.4 The CYK algorithm, step 2: j=3, possible Cell entries j N CYK Parsing: Building up the structure for = 2 to # length of span etc. A + (B(C)) = A(B(C))orB(A; C) A + (C(B)) = A(C(B))orC(A; B) C + (A(B)) = C(A(B))orA(B; C) C + (B(A)) = C(B(A))orB(A; C) + A C B D C E D j = 3 A B B C C D D E E A B C D E 8

2.5 The CYK algorithm, continued j N CYK Parsing: The analysis matrix for = 2 to # length of span etc. j = 3 A C B D C E D A B j = 2 B C C D D E E A B C D E 9

3 A Prolog CYK Parser chartdata-driven CYK implementation 1. Add all terminals to chart X i: k:[i k] Y j:[k j] : tried(x; Y Y Z Z [i! X; j] tried(x; Y 2. Loop: foreach chart entry foreach chart entry # adjacent if ) foreach assert to chart (for next Loop) else assert ) 3. If any rule was successful, prune and then Loop again, else terminate. loop 2 A C A D B D B E C E C D H loop 1 H H H H H H H H H H H A ΦB Φ B HΦ C C D D E E ΦΦΦΦΦ ΦΦΦΦΦ ΦΦΦΦΦ H H H H H A B C D E 10

3.1 Simplified CYK Parser nextlevel(l) :- chart( ID,[Pos,from-to,Score],[[,tag,Type]],unc), % foreach chart entry (by backtrack) Gto is from-1, chart( GID,[GPos,Gfrom-Gto,GScore],[[G,Gtag,GType]],uncG), % find adjacent chart entries bagof(_,sparse(id,[pos,from-to,score],[[,tag,type]],unc, GID,[GPos,Gfrom-Gto,GScore],[[G,Gtag,GType]],uncG),_), % parse (non-recursive, chart version) write( End of Level ), write(l), write( reduced items : ), perlevel(x), write(x), X > 0, % only recurse successful prune(l,x), L1 is L+1, retractall(perlevel(_)), assert(perlevel(0)), nextlevel(l1). 11

3.2 The CYK parsing version of the sparse predicate ail-driven, non-recursive. A simplified but still too complex version: sparse(id,[pos,from-to,score],[[,tag,type]],unc, GID,[GPos,Gfrom-Gto,GScore],[[G,Gtag,GType]],uncG) :- (tried(id,gid) ->!, fail; assert(tried(id,gid))), % already tried... % get various context info for the grammar rules: head(tag,gtag,l,type,transtag,[chunk,gchunk,,g,o,og],pos-gpos), % rule for LET reduction (l) (statschart(tag,,s,gtag,g,sg,type,prob,percent,dist,chunk,og) -> true ; (stats(tag,,s,gtag,g,sg,type,prob,percent,dist,chunk,og), assert(statschart(tag,,s,gtag,g,sg,type,prob,percent,dist,chunk,og)))), (Prob < 0.01 -> fail; true), %% early exclusion %% Build unc-struc:... asserta(chart(id,[[,tag,chunk,id,score],[g,gtag,gchunk,gid,gscore]], [Pos,GPos,Gfrom-to,PScore,DLen],[[,Transtag,Type,ID]],uncTRes,Level)), retract(perlevel(x)), X1 is X+1, assert(perlevel(x1)), (Prob > 0.98 ->!; true), %% early commitment fail. 12

4 Differences between CYK and Earley 1. No need for CN in Earley 2. Empty nodes are allowed 3. Also active edges are entered into the chart: very costly 4. CYK uses a scanner and completer much like Earley, but no predictor: Scanner: move one constituent to the right Completer: Rules are binary! always complete any two constituents Predictor: No top-down prediction. CYK is pure bottom-up Earley parsing can also be visualized/processed in a CYK matrix 13

5 Differences between CYK and Shift-Reduce see also last lecture 1. No need for CN in Shift-Reduce 2. No chart, although extensions possible: costly 3. CYK uses a shift and reduce much like Shift-Reduce, but in parallel Shift: move one constituent to the right Reduce: Rules are binary! always reduce any two constituents Try shift and reduce simultaneously 14