Remembering subresults (Part I): Well-formed substring tables

Similar documents
Parsing with CFGs L445 / L545 / B659. Dept. of Linguistics, Indiana University Spring Parsing with CFGs. Direction of processing

Parsing with CFGs. Direction of processing. Top-down. Bottom-up. Left-corner parsing. Chart parsing CYK. Earley 1 / 46.

CSCI Compiler Construction

Introduction to Computational Linguistics

CMPT-825 Natural Language Processing. Why are parsing algorithms important?

Parsing. Based on presentations from Chris Manning s course on Statistical Parsing (Stanford)

Parsing with Context-Free Grammars

Review. Earley Algorithm Chapter Left Recursion. Left-Recursion. Rule Ordering. Rule Ordering

CKY & Earley Parsing. Ling 571 Deep Processing Techniques for NLP January 13, 2016

In this chapter, we explore the parsing problem, which encompasses several questions, including:

Parsing. Unger s Parser. Introduction (1) Unger s parser [Grune and Jacobs, 2008] is a CFG parser that is

Statistical Machine Translation

Maschinelle Sprachverarbeitung

Advanced Natural Language Processing Syntactic Parsing

RNA Secondary Structure Prediction

Maschinelle Sprachverarbeitung

Parsing. Probabilistic CFG (PCFG) Laura Kallmeyer. Winter 2017/18. Heinrich-Heine-Universität Düsseldorf 1 / 22

A* Search. 1 Dijkstra Shortest Path

Parsing with Context-Free Grammars

Parsing. Unger s Parser. Laura Kallmeyer. Winter 2016/17. Heinrich-Heine-Universität Düsseldorf 1 / 21

Grammar formalisms Tree Adjoining Grammar: Formal Properties, Parsing. Part I. Formal Properties of TAG. Outline: Formal Properties of TAG

Simplification of CFG and Normal Forms. Wen-Guey Tzeng Computer Science Department National Chiao Tung University

Simplification of CFG and Normal Forms. Wen-Guey Tzeng Computer Science Department National Chiao Tung University

Even More on Dynamic Programming

FORMAL LANGUAGES, AUTOMATA AND COMPUTATION

Natural Language Processing 1. lecture 7: constituent parsing. Ivan Titov. Institute for Logic, Language and Computation

CSCI 1010 Models of Computa3on. Lecture 17 Parsing Context-Free Languages

Context-Free Parsing: CKY & Earley Algorithms and Probabilistic Parsing

Grammars and Context Free Languages

Probabilistic Context-free Grammars

Parsing. Left-Corner Parsing. Laura Kallmeyer. Winter 2017/18. Heinrich-Heine-Universität Düsseldorf 1 / 17

Probabilistic Context-Free Grammars. Michael Collins, Columbia University

Computational Linguistics II: Parsing

CYK Algorithm for Parsing General Context-Free Grammars

Properties of Context-Free Languages

Attendee information. Seven Lectures on Statistical Parsing. Phrase structure grammars = context-free grammars. Assessment.

LECTURER: BURCU CAN Spring

Decidable and undecidable languages

Grammars and Context Free Languages

Context Free Grammars: Introduction. Context Free Grammars: Simplifying CFGs

Parsing beyond context-free grammar: Parsing Multiple Context-Free Grammars

CS311 Computational Structures. NP-completeness. Lecture 18. Andrew P. Black Andrew Tolmach. Thursday, 2 December 2010

Context-Free Parsing: CKY & Earley Algorithms and Probabilistic Parsing

Lecture 12 Simplification of Context-Free Grammars and Normal Forms

Finite Automata Theory and Formal Languages TMV027/DIT321 LP4 2018

Natural Language Processing. Lecture 13: More on CFG Parsing

NPDA, CFG equivalence

CPS 220 Theory of Computation

straight segment and the symbol b representing a corner, the strings ababaab, babaaba and abaabab represent the same shape. In order to learn a model,

Decision problem of substrings in Context Free Languages.

Chapter 14 (Partially) Unsupervised Parsing

CS20a: summary (Oct 24, 2002)

Address for Correspondence

Probabilistic Context Free Grammars

Context- Free Parsing with CKY. October 16, 2014

Context-Free Parsing: CKY & Earley Algorithms and Probabilistic Parsing

A parsing technique for TRG languages

DT2118 Speech and Speaker Recognition

Introduction to Natural Language Processing

Computability Theory

Formal Languages, Grammars and Automata Lecture 5

Syntax Analysis Part I

Foundations of Informatics: a Bridging Course

Syntax Analysis Part I

CS626: NLP, Speech and the Web. Pushpak Bhattacharyya CSE Dept., IIT Bombay Lecture 14: Parsing Algorithms 30 th August, 2012

Parsing. Weighted Deductive Parsing. Laura Kallmeyer. Winter 2017/18. Heinrich-Heine-Universität Düsseldorf 1 / 26

Chap. 7 Properties of Context-free Languages

Aspects of Tree-Based Statistical Machine Translation

Harvard CS 121 and CSCI E-207 Lecture 12: General Context-Free Recognition

Formal Languages and Automata

Handout 8: Computation & Hierarchical parsing II. Compute initial state set S 0 Compute initial state set S 0

To make a grammar probabilistic, we need to assign a probability to each context-free rewrite

CISC4090: Theory of Computation

Grammar and Feature Unification

MA/CSSE 474 Theory of Computation

Natural Language Processing : Probabilistic Context Free Grammars. Updated 5/09

Top-Down Parsing and Intro to Bottom-Up Parsing

Theory of Computation p.1/?? Theory of Computation p.2/?? We develop examples of languages that are decidable

Computing if a token can follow

Context Free Grammars

Natural Language Processing CS Lecture 06. Razvan C. Bunescu School of Electrical Engineering and Computer Science

Syntax Analysis Part I. Position of a Parser in the Compiler Model. The Parser. Chapter 4

Context Free Grammars: Introduction

Probabilistic Context Free Grammars. Many slides from Michael Collins and Chris Manning

{Probabilistic Stochastic} Context-Free Grammars (PCFGs)

Aspects of Tree-Based Statistical Machine Translation

Testing Emptiness of a CFL. Testing Finiteness of a CFL. Testing Membership in a CFL. CYK Algorithm

Probabilistic Context Free Grammars. Many slides from Michael Collins

CS5371 Theory of Computation. Lecture 18: Complexity III (Two Classes: P and NP)

Follow sets. LL(1) Parsing Table

Syntax-Based Decoding

PCFGs 2 L645 / B659. Dept. of Linguistics, Indiana University Fall PCFGs 2. Questions. Calculating P(w 1m ) Inside Probabilities

Decoding and Inference with Syntactic Translation Models

CS5371 Theory of Computation. Lecture 12: Computability III (Decidable Languages relating to DFA, NFA, and CFG)

CS 6120/CS4120: Natural Language Processing

Sharpening the empirical claims of generative syntax through formalization

Sharpening the empirical claims of generative syntax through formalization

Probabilistic Context-Free Grammar

CS5371 Theory of Computation. Lecture 7: Automata Theory V (CFG, CFL, CNF)

h>p://lara.epfl.ch Compiler Construc/on 2011 CYK Algorithm and Chomsky Normal Form

Transcription:

Remembering subresults (Part I): Well-formed substring tables Detmar Meurers: Intro to Computational Linguistics I OSU, LING 684.01, 1. February 2005

Problem: Inefficiency of recomputing subresults Two example sentences and their potential analysis: (1) He [gave [the young cat] [to Bill]]. (2) He [gave [the young cat] [some milk]]. The corresponding grammar rules: vp ---> [v_ditrans, np, pp_to]. vp ---> [v_ditrans, np, np]. 2/44

Solution: Memoization Store intermediate results: a) completely analyzed constituents: well-formed substring table or (passive) chart b) partial and complete analyses: (active) chart All intermediate results need to be stored for completeness. All possible solutions are explored in parallel. 3/44

CFG Parsing: The Cocke Younger Kasami Algorithm Grammar has to be in Chomsky Normal Form (CNF), only RHS with a single terminal: A a RHS with two non-terminals: A BC no ǫ rules (A ǫ) A representation of the string showing positions and word indices: 0 w 1 1 w 2 2 w 3 3 w 4 4 w 5 5 w 6 6 For example: 0 the 1 young 2 boy 3 saw 4 the 5 dragon 6 4/44

The well-formed substring table (= passive chart) The well-formed substring table, henceforth (passive) chart, for a string of length n is an n n matrix. The field (i,j) of the chart encodes the set of all categories of constituents that start at position i and end at position j, i.e. chart(i,j) = {A A w i+1...w j } The matrix is triangular since no constituent ends before it starts. 5/44

Coverage Represented in the Chart An input sentence with 6 words: 0 w 1 1 w 2 2 w 3 3 w 4 4 w 5 5 w 6 6 Coverage represented in the chart: from: to: 6 0 0 1 0 2 0 3 0 4 0 5 0 6 1 1 2 1 3 1 4 1 5 1 6 2 2 3 2 4 2 5 2 6 3 3 4 3 5 3 6 4 4 5 4 6 5 5 6 6/44

Example for Coverage Represented in Chart Example sentence: 0 the 1 young 2 boy 3 saw 4 the 5 dragon 6 Coverage represented in chart: 6 0 the the young the young boy the young boy saw the young boy saw the the young boy saw the dragon 1 young young boy young boy saw young boy saw the young boy saw the dragon 2 boy boy saw boy saw the boy saw the dragon 3 saw saw the saw the dragon 4 the the dragon 5 dragon 7/44

An Example for a Filled-in Chart Input sentence: 0 the 1 young 2 boy 3 saw 4 the 5 dragon 6 Chart: 6 0 {Det} {} {} {} {} {S} 1 {Adj} {N} {} {} {} 2 {N} {} {} {} 3 {V, N} {} {VP} 4 {Det} {} 5 {N} S VP N Det Adj N V Det N 0 6 Grammar: S VP VP Vt Det N N Adj N Vt saw Det the Det a N dragon N boy N saw Adj young 8/44

Filling in the Chart It is important to fill in the chart systematically. We build all constituents that end at a certain point before we build constituents that end at a later point. 6 0 1 3 6 10 15 21 1 2 5 9 14 20 2 4 8 13 19 3 7 12 18 4 11 17 5 16 for j := 1 to length(string) lexical chart fill(j 1, j) for i := j 2 down to 0 syntactic chart fill(i, j) 9/44

lexical chart fill(j-1,j) Idea: Lexical lookup. Fill the field (j 1, j) in the chart with the preterminal category dominating word j. Realized as: chart(j 1, j) := {X X word j P} 10/44

syntactic chart fill(i,j) Idea: Perform all reduction step using syntactic rules such that the reduced symbol covers the string from i to j. Realized as: chart(i, j) = A A BC P, i < k < j, B chart(i,k), C chart(k,j) Explicit loops over every possible value of k and every context free rule: chart(i,j) := {}. for k := i + 1 to j 1 for every A BC P if B chart(i,k) and C chart(k,j) then chart(i, j) := chart(i,j) {A}. 11/44

The Complete CYK Algorithm Input: start category S and input string n := length(string) for j := 1 to n chart(j 1, j) := {X X word j P} for i := j 2 down to 0 chart(i,j) := {} for k := i + 1 to j 1 for every A BC P if B chart(i, k) and C chart(k,j) then chart(i,j) := chart(i, j) {A} Output: if S chart(0,n) then accept else reject 12/44

Lexical Entry: the ( j = 1, field chart(0,1)) 0 d 1 2 3 4 D 0 13/44

Lexical Entry: cat ( j = 2, field chart(1,2)) 0 d 2 3 4 D N 0 14/44

j = 2 i = 0 k = 1 0 d np 2 3 4 D N 0 15/44

Lexical Entry: chases ( j = 3, field chart(2,3)) 0 d np 2 v 3 4 D N V 0 16/44

j = 3 i = 1 k = 2 0 d np 2 v 3 4 D N V 0 17/44

j = 3 i = 0 k = 1 0 d np 2 v 3 4 D N V 0 18/44

j = 3 i = 0 k = 2 0 d np 2 v 3 4 D N V 0 19/44

Lexical Entry: the ( j = 4, field chart(3,4)) 0 d np 2 v 3 d 4 D N V D 0 20/44

j = 4 i = 2 k = 3 0 d np 2 v 4 3 d D N V D 0 21/44

j = 4 i = 1 k = 2 0 d np 2 v 3 d 4 D N V D 0 22/44

j = 4 i = 1 k = 3 0 d np 2 v 4 3 d D N V D 0 23/44

j = 4 i = 0 k = 1 0 d np 2 v 3 d 4 D N V D 0 24/44

j = 4 i = 0 k = 2 0 d np 2 v 3 d 4 D N V D 0 25/44

j = 4 i = 0 k = 3 0 d np 2 v 4 3 d D N V D 0 26/44

Lexical Entry: dog ( j = 5, field chart(4,5)) 0 d np 2 v 3 d 4 n D N V D N 0 27/44

j = 5 i = 3 k = 4 0 d np 2 v 3 d np 4 n D N V D N 0 28/44

j = 5 i = 2 k = 3 0 d np 2 v vp 3 d np 4 n VP D N V D N 0 29/44

j = 5 i = 2 k = 4 0 d np 2 v vp 3 d np 4 n VP D N V D N 0 30/44

j = 5 i = 1 k = 2 0 d np 2 v vp 3 d np 4 n VP D N V D N 0 31/44

j = 5 i = 1 k = 3 0 d np 2 v vp 3 d np 4 n VP D N V D N 0 32/44

j = 5 i = 1 k = 4 0 d np 2 v vp 3 d np 4 n VP D N V D N 0 33/44

j = 5 i = 0 k = 1 0 d np 2 v vp 3 d np 4 n VP D N V D N 0 34/44

j = 5 i = 0 k = 2 0 d np s S 2 v vp 3 d np 4 n VP D N V D N 0 35/44

j = 5 i = 0 k = 3 0 d np s S 2 v vp VP 3 d np D N V D N 4 n 0 1 2 4 3 5 36/44

j = 5 i = 0 k = 4 0 d np s S 2 v vp 3 d np 4 n VP D N V D N 0 37/44

Dynamic knowledge bases in PROLOG Declaration of a dynamic predicate: dynamic/1 declaration, e.g: :- dynamic chart/3. to store facts of the form chart(from,to,category): Add a fact to the database: assert/1, e.g.: assert(chart(1,3,np)). Special versions asserta/1/assertz/1 ensure adding facts first/last. Removing a fact from the database: retract/1, e.g.: retract(chart(1,_,np)). To remove all matching facts from the database use retractall/1 38/44

The CYK algorithm in PROLOG (parser/cky/cky.pl) :- dynamic chart/3. % chart(from,to,category) :- op(1100,xfx, ---> ). % Operator for grammar rules % recognize(+wordlist,?startsymbol): top-level of CYK recognizer recognize(string,cat) :- retractall(chart(_,_,_)), length(string,n), fill_chart(string,0,n), chart(0,n,cat). % initialize chart % determine length of string % call parser to fill the chart % check whether parse successful 39/44

% fill_chart(+wordlist,+current minus one,+last) % J-LOOP from 1 to n fill_chart([],n,n). fill_chart([w Ws],JminOne,N) :- J is JminOne + 1, lexical_chart_fill(w,jminone,j), % I is J - 2, syntactic_chart_fill(i,j), % fill_chart(ws,j,n). 40/44

% lexical_chart_fill(+word,+jminone,+j) % fill diagonal with preterminals lexical_chart_fill(w,jminone,j) :- (Cat ---> [W]), add_to_chart(jminone,j,cat), fail ; true. 41/44

% syntactic_chart_fill(+i,+j) % I-LOOP from J-2 downto 0 syntactic_chart_fill(-1,_) :-!. syntactic_chart_fill(i,j) :- K is I+1, build_phrases_from_to(i,k,j), % IminOne is I-1, syntactic_chart_fill(iminone,j). 42/44

% build_phrases_from_to(+i,+current-k,+j) % K-LOOP from I+1 to J-1 build_phrases_from_to(_,j,j) :-!. build_phrases_from_to(i,k,j) :- chart(i,k,b), chart(k,j,c), (A ---> [B,C]), add_to_chart(i,j,a), fail ; KplusOne is K+1, build_phrases_from_to(i,kplusone,j). 43/44

% add_to_chart(+cat,+from,+to): add if not yet there add_to_chart(from,to,cat) :- chart(from,to,cat),!. add_to_chart(from,to,cat) :- assertz(chart(from,to,cat). 44/44