Clase 10 - Chart Parser 2

  • November 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Clase 10 - Chart Parser 2 as PDF for free.

More details

  • Words: 1,298
  • Pages: 30
Computational Linguistics ´ Damir Cavar [email protected] Indiana University Linguistics Department February 21, 2006

´ © 2006 by Damir Cavar, Indiana University

Chart Parsing

• Motivation – Problems with backtracking (our brute-force) parsers: ∗ Repetitive parsing of same token(list)s ∗ Repetitive parsing of paths that turned out to be unsuccessful ∗ Unknown words and partial structures lead to a failure ´ © 2006 by Damir Cavar, Indiana University

1

Chart Parsing

• Motivation – Chart parser (e. g. Earley parser): ∗ Avoid parsing of same token(list)s by memorization in chart ∗ Memorize parses for partial structures · If a spanning analysis is impossible, the chart contains the partial analyses ´ © 2006 by Damir Cavar, Indiana University

2

Chart Parsing

• Motivation – Chart parser (e. g. Earley parser): ∗ Compact representation for ambiguous structures (multiple parses)

´ © 2006 by Damir Cavar, Indiana University

3

Chart Parsing • Chart – Edges ∗ Directed graph: start point, end point, analysis ∗ Input: John kissed Mary ∗ Final chart: (0, (1, (2, (0,

1, 2, 3, 3,

N, [ John • ]) (0, 1, NP, [ N • ]) V, [ kissed • ]) (2, 3, NP, [ N • ]) N, [ Mary • ]) (1, 3, VP, [ V NP • ]) S, [ NP VP • ])

´ © 2006 by Damir Cavar, Indiana University

4

Chart Parsing

• Strategies – Bottom-up – Top-down • Active strategies (Agenda) – Depth-first – Breath-first ´ © 2006 by Damir Cavar, Indiana University

5

Chart Parsing

• Bottom-up strategy – Initialization (scan, tagging) ∗ Add edges with lexical rules for each token (incrementally) – Rule invocation (prediction) – Fundamental rule (completion)

´ © 2006 by Damir Cavar, Indiana University

6

Chart Parsing

• Bottom-up strategy – Rule Invocation: For every inactive edge on chart: ∗ Find rules that have its LHS on their left periphery in RHS. ∗ Create new edges and add to chart.

´ © 2006 by Damir Cavar, Indiana University

7

Chart Parsing

• Bottom-up rule invocation example: – Inactive edge: ∗ edge(0, 1, N → John •) – Rule: ∗ NP → N – New edge: ∗ edge(0, 0, NP → • N) ´ © 2006 by Damir Cavar, Indiana University

8

Chart Parsing

• Fundamental Rule – For every active edge find expected inactive edge: ∗ edge(0, 1, N → John •) ∗ edge(0, 0, NP → • N) – Merge edges and add resulting edge to chart: ∗ edge(0, 1, NP → N •)

´ © 2006 by Damir Cavar, Indiana University

9

Chart Parsing

• Top-down strategy – Initialization ∗ Add edges with rules with goal symbol on LHS (incrementally) – Rule invocation (prediction) – Fundamental rule (completion)

´ © 2006 by Damir Cavar, Indiana University

10

Chart Parsing • Top-down strategy – Rule Invocation: For every active edge on chart: ∗ Find rules that have its left peripheral symbol from the expected RHS on their LHS. The left peripheral symbol from the expected RHS is the first symbol following the DOT. ∗ Create new edges and add to chart. ´ © 2006 by Damir Cavar, Indiana University

11

Chart Parsing

• Top-down rule invocation example: – Active edge: ∗ edge(0, 0, S → • NP VP) – Rule: ∗ NP → N – New edge: ∗ edge(0, 0, NP → • N) ´ © 2006 by Damir Cavar, Indiana University

12

Chart Parsing

• Top-down rule invocation depth-first: – Active edge: ∗ edge(0, 0, S → • NP VP) – Rules: NP → N; N → John – New edges: ∗ edge(0, 0, NP → • N) ∗ edge(0, 0, N → • John) ´ © 2006 by Damir Cavar, Indiana University

13

Chart Parsing

• Top-down after rule invocation and fundamental rule: – New edges: ∗ edge(0, 1, S → NP • VP) ∗ edge(0, 1, NP → N •) ∗ edge(0, 1, N → John •)

´ © 2006 by Damir Cavar, Indiana University

14

Chart Parsing

• Top-down rule invocation breadth-first: – Active edge: ∗ edge(0, 0, S → • NP VP) – Rules: NP → N; VP → V NP – New edges: ∗ edge(0, 0, NP → • N) ∗ edge(0, 0, VP → • V NP) ´ © 2006 by Damir Cavar, Indiana University

15

Chart Parsing

• Fundamental Rule – For every active edge find expected inactive edge: ∗ edge(0, 0, NP → • N) ∗ edge(0, 1, N → John •) – Merge edges and add resulting edge to chart: ∗ edge(0, 1, NP → N •)

´ © 2006 by Damir Cavar, Indiana University

16

Chart Parsing

• Fundamental Rule – For every active edge find expected inactive edge: ∗ edge(0, 0, S → • NP VP) ∗ edge(0, 1, NP → N •) – Merge edges and add resulting edge to chart: ∗ edge(0, 1, S → NP • VP)

´ © 2006 by Damir Cavar, Indiana University

17

Chart Parsing

• Rule Invocation – Dependent of parsing strategy. • Fundamental Rule – Independent of parsing strategy.

´ © 2006 by Damir Cavar, Indiana University

18

Chart Parsing

• Differences between top-down and bottom-up parsing: – TD: Disambiguates by position. ∗ Calls from Alaska are expensive. – BU: Lexically driven. – TD: Has to handle recursion.

´ © 2006 by Damir Cavar, Indiana University

19

Chart Parser Implementation Hacer entre todos el ejercicio para Chart parser que esta en LABORATORIO 3. El archivo se llama "ejercicio_chart_parser.pdf". Los alumnos deben traer las 3 hojitas impresas a la clase

• Necessary components: – – – – –

Chart Initialization Rule Invocation Fundamental Rule Program Flow-Control

´ © 2006 by Damir Cavar, Indiana University

20

Chart Parser Implementation

• Chart: – Storage for edges – Edges: ∗ start point ∗ end point ∗ rule ∗ dot position ´ © 2006 by Damir Cavar, Indiana University

21

Chart Parser Implementation • Edge: – List of elements: edge = [ 0, 1, 1, "N", "John" ] ∗ integer for start point ∗ integer for end point ∗ integer for dot position ∗ string for rule left-hand side ∗ string for rule right-hand side ´ © 2006 by Damir Cavar, Indiana University

22

Chart Parser Implementation

• Chart: – Storage for edges – List of edges: ∗ chart = [ ] or chart = [ [ 0, 1, 1, "N", "John" ], [ 1, 2, 1, "V", "kissed" ], [ 2, 3, 1, "N", "Mary" ] ] ´ © 2006 by Damir Cavar, Indiana University

23

Chart Parser Implementation

• Lists: Edge & Chart • List operations: – – – – –

Appending: mylist.append("hello") Index: mylist[2] Slice: mylist[2:4] Deletion: del mylist[2] Change: mylist[2] = "test"

´ © 2006 by Damir Cavar, Indiana University

24

Chart Parser Implementation

• List operations: – – – – –

Check: if "hello" in mylist: Loop 1: for i in mylist: Loop 2: for i in mylist[2:]: Length: length = len(mylist): Loop 3: for i in range(len(mylist)):

´ © 2006 by Damir Cavar, Indiana University

25

Chart Parser Implementation

• Functions: – – – –

Initialize Rule Invocation Fundamental Rule Parsing Loop

´ © 2006 by Damir Cavar, Indiana University

26

Chart Parser Implementation

• Define functions: – – – –

Initialize: def initialize(): Rule Invocation: def ruleInvocation(): Fundamental Rule: def fundamentalRule(): Parsing Loop: def parse():

´ © 2006 by Damir Cavar, Indiana University

27

Chart Parser Implementation

• Main part: – Program initialization: if __name__ == "__main__": parse(["John", "kissed", "Mary"])

´ © 2006 by Damir Cavar, Indiana University

28

Chart Parser Implementation

• Using PSGParser: – Class PSG ∗ Class method: PSG("grammar-file") ∗ Class data structure: lhs = [ ] ∗ Class data structure: rhs = [ ] ∗ Access: PSG.rhs or PSG.lhs

´ © 2006 by Damir Cavar, Indiana University

29

Related Documents

Clase 10 - Chart Parser 2
November 2019 11
Clase 10 - Chart Parser
November 2019 11
Clase 10
May 2020 8
Clase 10
July 2020 6
Clase 10
November 2019 18