1 / 78

Chart Parsing and Augmenting Grammars

Chart Parsing and Augmenting Grammars. CSE-391: Artificial Intelligence University of Pennsylvania Matt Huenerfauth March 2005. Homework 6. Due Friday, April 1, 2005. (Two weeks.) You will write/modify some grammar rules. You will enact some parsing algorithms by hand.

meganhunt
Download Presentation

Chart Parsing and Augmenting Grammars

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Chart Parsing and Augmenting Grammars CSE-391: Artificial IntelligenceUniversity of Pennsylvania Matt Huenerfauth March 2005

  2. Homework 6 • Due Friday, April 1, 2005. (Two weeks.) • You will write/modify some grammar rules. • You will enact some parsing algorithms by hand. • You will use the chart-parsing Python code from the textbook (we’ll learn about chart parsing today).

  3. Last time: Our grammar S  NP VP VP  V VP  V NP NP  pronoun NP  noun V  verb NP  det adj noun V  aux verb NP  det noun • NON-TERMINAL vs. terminal…

  4. Last time: Two Parsing Approaches • Top Down Parsing • Start with the top-level rule for S. • Blindly try all possible rules to build the sub pieces of the original S rule. Recurse. • When you back up, forget structures you built. • Bottom Up Parsing • Start by considering the part of speech of all the words. Build all the possible ‘local’ pieces of structure, and slowly build larger pieces.

  5. Last time: Top-down parse[The, old, can, can, hold, the, water] S → NP VP Consider NP… NP → pronoun? pronoun? fail NP → noun? noun? fail NP → det adj noun? det? the adj?old noun? Can Succeed. Succeed. What about the VP?

  6. Last time: Top-down parse[can, hold, the, water] Consider VP… V → verb? verb? fail V → aux verb? aux? can verb? hold succeed succeed fail[the, water]

  7. Bottom Up Parsing • To illustrate bottom-up parsing, we will draw a chart diagram. • For a sentence with k words, we will start with k+1 nodes in the diagram. • We put edges between adjacent nodes labeled with input words & part of speech. the old can can hold the water auxverbnoun auxverbnoun det adj noun det noun verb verb noun

  8. Drawing an edge… • As we apply grammar rules to build a parse, we draw more edges: • An edge has a starting and a stopping point. This represents what input words it covers. • An edge has a label. In the bottom-up algorithm, it looks like this: VP  V NP • This means we just found a V and a NP, and we have combined them to build VP. • We’ll see an example of this on the next slide.

  9. NP det noun NP det noun V aux verb V aux verb NP det adj noun VP V NP VP V NP VP V NP VP VP NP S NP VP NP noun NP noun NP noun NP noun NP noun V verb V verb V verb V verb Bottom Up Parsing the old can can hold the water auxverbnoun auxverbnoun det adj noun det noun verb verb noun

  10. NP det noun V aux verb NP det adj noun VP VP NP S NP VP Bottom Up Parsing the old can can hold the water auxverbnoun auxverbnoun det adj noun det noun verb verb noun

  11. Three Parsing Algorithms • Top Down Parsing • Tries lots of rules, does a lot of backtracking. • Has to re-build structures that it forgets about. • Feels a lot like uninformed search. • Bottom Up Parsing • Starts with the small pieces of structure, but it builds everything it can. Don’t need all of it. • Most of it not used in the final complete parse. • Top-Down Chart Parsing

  12. (Top Down) Chart Parsing • Advantages: • Only build those pieces of structure that we actually need to parse the entire sentence. • Remember pieces of structure that we build in a chart so that if we have to backtrack, we don’t have to build those sub-structures all over again.

  13. Add one more rule… • The first thing we do is add one more rule to our grammar. Our goal will be to produce a parse of the whole sentence that produces an S’: S’  S • So, this will be the first rule we’ll try to process with the algorithm…

  14. the can can fall det auxverbnoun auxverbnoun verbnoun A New Kind of Edge • Instead of just drawing edges in our chart diagram for complete structures that we find, now we’ll also add edges that represent incomplete structures that we want to find… • For example, an edge labeled: VP  V • NP could be used to represent a point in the algorithm where we really want to build a VP, and we have already found a V but have not yet found a NP to complete it. • Why would we want such a thing? We’ll see…

  15. How to Start Our goal is to build an edge covering the whole sentence labeled S’. So, we first add an edge that covers no words at the start of the sentence. Since we haven’t found any S yet in order to fulfill the S’ rule, then we have to put the dot in front of the S. So, now our mission is to find an S in this sentence so that we can produce an S’. In other words, when we add edges to the chart that contain dots, then we know we are looking for the thing to the rightof the dot. the can can fall det auxverbnoun auxverbnoun verbnoun S’•S

  16. The Algorithm • When we add an edge to the diagram, we give it a blue label. After we “process” the edge, then the label turns black. We will process edges in the order they are added to the diagram. • Process edges like a “queue” (breadth-first feel). Could also use “stack” but this is less traditional. We really want all parses, not just one. • How to we “process” an edge? It depends on where the dot is. • Before a NON-TERMINAL? • Before a terminal? • At the end?

  17. PREDICT future rules… • If the dot is before a NON-TERMINAL. • We look up all the rules in the grammar that can produce that NON-TERMINAL. • We add all of these rules to the diagram as edges which cover no words. • We put a dot in front of the first item after the arrow. • Remember: All new edges have blue labels.

  18. Dot before NON-TERMINAL:“Predict” the can can fall det auxverbnoun auxverbnoun verbnoun S’ • S (1)

  19. Dot before NON-TERMINAL:“Predict” the can can fall det auxverbnoun auxverbnoun verbnoun S’ • SS • NP VP (1)(2)

  20. Dot before NON-TERMINAL:“Predict” the can can fall det auxverbnoun auxverbnoun verbnoun S’ • SS • NP VP (1)(2)

  21. Dot before NON-TERMINAL:“Predict” the can can fall det auxverbnoun auxverbnoun verbnoun S’ • SS • NP VPNP  •proNP  •nounNP  •det nounNP  •det adj noun (1) (2) (3) (4) (5) (6)

  22. Dot before NON-TERMINAL:“Predict” the can can fall det auxverbnoun auxverbnoun verbnoun S’ • SS • NP VPNP  • proNP  •nounNP  •det nounNP  •det adj noun (1) (2) (3) (4) (5) (6)

  23. SCAN input words… • When the dot is before a terminal… • Check the next word of input to see if any of its parts of speech matches the terminal symbol. • If there is a match, then we:spread the rule to the right and we move the dot to the right as well.

  24. Dot before terminal: “Scan” the can can fall det auxverbnoun auxverbnoun verbnoun S’ • SS • NP VPNP  •proNP  •nounNP  •det nounNP  •det adj noun (1) (2) (3) (4) (5) (6)

  25. Dot before terminal: “Scan” the can can fall det auxverbnoun auxverbnoun verbnoun S’ • SS • NP VPNP  • proNP  •nounNP  •det nounNP  •det adj noun (1) (2) (3) (4) (5) (6)

  26. Dot before terminal: “Scan” the can can fall det auxverbnoun auxverbnoun verbnoun S’ • SS • NP VPNP  • proNP  • nounNP  •det nounNP  •det adj noun (1) (2) (3) (4) (5) (6)

  27. Dot before terminal: “Scan” (7) NP  det •noun the can can fall det auxverbnoun auxverbnoun verbnoun S’ • SS • NP VPNP  • proNP  • nounNP  •det nounNP  •det adj noun (1) (2) (3) (4) (5) (6)

  28. Dot before terminal: “Scan” (7) NP  det •noun the can can fall det auxverbnoun auxverbnoun verbnoun S’ • SS • NP VPNP  • proNP  • nounNP  • det nounNP  •det adj noun (1) (2) (3) (4) (5) (6)

  29. Dot before terminal: “Scan” (7) (8) NP  det •noun NP  det •adj noun the can can fall det auxverbnoun auxverbnoun verbnoun S’ • SS • NP VPNP  • proNP  • nounNP  • det nounNP  •det adj noun (1) (2) (3) (4) (5) (6)

  30. Dot before terminal: “Scan” (7) (8) NP  det •noun NP  det •adj noun the can can fall det auxverbnoun auxverbnoun verbnoun S’ • SS • NP VPNP  • proNP  • nounNP  • det nounNP  • det adj noun (1) (2) (3) (4) (5) (6)

  31. Dot before terminal: “Scan” (9) NP  det noun • (7) (8) NP  det •noun NP  det •adj noun the can can fall det auxverbnoun auxverbnoun verbnoun S’ • SS • NP VPNP  • proNP  • nounNP  • det nounNP  • det adj noun (1) (2) (3) (4) (5) (6)

  32. Dot before terminal: “Scan” (9) NP  det noun • (7) (8) NP  det • noun NP  det •adj noun the can can fall det auxverbnoun auxverbnoun verbnoun S’ • SS • NP VPNP  • proNP  • nounNP  • det nounNP  • det adj noun (1) (2) (3) (4) (5) (6)

  33. Dot before terminal: “Scan” (9) NP  det noun • (7) (8) NP  det • noun NP  det • adj noun the can can fall det auxverbnoun auxverbnoun verbnoun S’ • SS • NP VPNP  • proNP  • nounNP  • det nounNP  • det adj noun (1) (2) (3) (4) (5) (6)

  34. Edge Extension • When the dot is at the end of the label… • Assume current edge is labeled: X  … • • Look at all of the edges that ended where the current edge began. • If any of these preceding edges have a label of the form: …  … • X … • Then spread this preceding edge across the width of the current edge, and label it:…  … X • … (move the dot to the right)

  35. Dot at end: “Edge Extension” (9) NP  det noun • (7) (8) NP  det • noun NP  det • adj noun the can can fall det auxverbnoun auxverbnoun verbnoun S’ • SS • NP VPNP  • proNP  • nounNP  • det nounNP  • det adj noun (1) (2) (3) (4) (5) (6)

  36. Dot at end: “Edge Extension” (9) NP  det noun • (7) (8) NP  det • noun NP  det • adj noun the can can fall det auxverbnoun auxverbnoun verbnoun S’ • SS • NP VPNP  • proNP  • nounNP  • det nounNP  • det adj noun (1) (2) (3) (4) (5) (6)

  37. Dot at end: “Edge Extension” NP  det noun •S  NP • VP (9) (10) (7) (8) NP  det • noun NP  det • adj noun the can can fall det auxverbnoun auxverbnoun verbnoun S’ • SS • NP VPNP  • proNP  • nounNP  • det nounNP  • det adj noun (1) (2) (3) (4) (5) (6)

  38. Dot at end: “Edge Extension” NP  det noun •S  NP • VP (9) (10) (7) (8) NP  det • noun NP  det • adj noun the can can fall det auxverbnoun auxverbnoun verbnoun S’ • SS • NP VPNP  • proNP  • nounNP  • det nounNP  • det adj noun (1) (2) (3) (4) (5) (6)

  39. Dot at end: “Edge Extension” NP  det noun •S  NP • VP (9) (10) (7) (8) NP  det • noun NP  det • adj noun the can can fall det auxverbnoun auxverbnoun verbnoun S’ • SS • NP VPNP  • proNP  • nounNP  • det nounNP  • det adj noun (1) (2) (3) (4) (5) (6)

  40. Remember… • Process one edge at a time in the order they were added to the diagram. (queue) • If the dot is just before: • a NON-TERMINAL:Then “predict.” (grab rules from the grammar) • a terminal:Then “scan.” (compare to POS of next word) • the end of the label:Then “edge extend.” (check preceding edges) • Don’t add an edge with same exact label and same exact span as a previous one.

  41. NP  det noun •S  NP • VP (9) (10) (7) (8) NP  det • noun NP  det • adj noun the can can fall det auxverbnoun auxverbnoun verbnoun S’ • SS • NP VPNP  • proNP  • nounNP  • det nounNP  • det adj noun (1) (2) (3) (4) (5) (6)

  42. NP  det noun •S  NP • VP (9) (10) (7) (8) NP  det • noun NP  det • adj noun the can can fall det auxverbnoun auxverbnoun verbnoun S’ • SS • NP VPNP  • proNP  • nounNP  • det nounNP  • det adj noun (11)(12) VP  • VVP  • V NP (1) (2) (3) (4) (5) (6)

  43. NP  det noun •S  NP • VP (9) (10) (7) (8) NP  det • noun NP  det • adj noun the can can fall det auxverbnoun auxverbnoun verbnoun S’ • SS • NP VPNP  • proNP  • nounNP  • det nounNP  • det adj noun (11)(12) VP  • VVP  • V NP (1) (2) (3) (4) (5) (6)

  44. NP  det noun •S  NP • VP (9) (10) (7) (8) NP  det • noun NP  det • adj noun the can can fall det auxverbnoun auxverbnoun verbnoun S’ • SS • NP VPNP  • proNP  • nounNP  • det nounNP  • det adj noun (11)(12)(13) (14) VP  • VVP  • V NPV  •verbV  •aux verb (1) (2) (3) (4) (5) (6)

  45. NP  det noun •S  NP • VP (9) (10) (7) (8) NP  det • noun NP  det • adj noun the can can fall det auxverbnoun auxverbnoun verbnoun S’ • SS • NP VPNP  • proNP  • nounNP  • det nounNP  • det adj noun (11)(12)(13) (14) VP  • VVP  • V NPV  •verbV  •aux verb (1) (2) (3) (4) (5) (6)

  46. NP  det noun •S  NP • VP (9) (10) (7) (8) NP  det • noun NP  det • adj noun the can can fall det auxverbnoun auxverbnoun verbnoun S’ • SS • NP VPNP  • proNP  • nounNP  • det nounNP  • det adj noun (11)(12)(13) (14) VP  • VVP  • V NPV  •verbV  •aux verb (1) (2) (3) (4) (5) (6)

  47. NP  det noun •S  NP • VP (9) (10) (7) (8) NP  det • noun V  verb • (15) NP  det • adj noun the can can fall det auxverbnoun auxverbnoun verbnoun S’ • SS • NP VPNP  • proNP  • nounNP  • det nounNP  • det adj noun (11)(12)(13) (14) VP  • VVP  • V NPV  •verbV  •aux verb (1) (2) (3) (4) (5) (6)

  48. NP  det noun •S  NP • VP (9) (10) (7) (8) NP  det • noun V  verb • (15) NP  det • adj noun the can can fall det auxverbnoun auxverbnoun verbnoun S’ • SS • NP VPNP  • proNP  • nounNP  • det nounNP  • det adj noun (11)(12)(13) (14) VP  • VVP  • V NPV  • verbV  •aux verb (1) (2) (3) (4) (5) (6)

  49. NP  det noun •S  NP • VP (9) (10) (7) (8) NP  det • noun V  verb •V  aux • verb (15)(16) NP  det • adj noun the can can fall det auxverbnoun auxverbnoun verbnoun S’ • SS • NP VPNP  • proNP  • nounNP  • det nounNP  • det adj noun (11)(12)(13) (14) VP  • VVP  • V NPV  • verbV  •aux verb (1) (2) (3) (4) (5) (6)

  50. NP  det noun •S  NP • VP (9) (10) (7) (8) NP  det • noun V  verb •V  aux • verb (15)(16) NP  det • adj noun the can can fall det auxverbnoun auxverbnoun verbnoun S’ • SS • NP VPNP  • proNP  • nounNP  • det nounNP  • det adj noun (11)(12)(13) (14) VP  • VVP  • V NPV  • verbV  • aux verb (1) (2) (3) (4) (5) (6)

More Related