Parsing with Context Free Grammars Outline • Why should you care? • Parsing • Top-Down Parsing • Bottom-Up Parsing • Bottom-Up Space (an example) • Top - Down Space (an example) • Top - Down Space (an exercise) • Conclusion (Top - Down Parse versus Bottom - up Parse) Slide 1 Why should you care? • Grammar checkers • Question answering • Information extraction • Machine translation Slide 1 Outline • Why should you care? • Parsing • Top-Down Parsing • Bottom-Up Parsing • Bottom-Up Space (an example) • Top Down Space (an example) • Top Down Space (an exercise) • Conclusion (Top Down Parse versus Bottom up Parse) Slide 1 Parsing • Parsing with CFGs refers to the task of assigning correct trees to input strings • Correct here means a tree that covers all and only the elements of the input and has an S at the top • It doesn’t actually mean that the system can select the correct tree from among the possible trees Slide 1 Parsing • As with everything of interest, parsing involves a search that involves the making of choices. Parsing a string with a CFG: Finding a derivation of the string consistent with the grammar.The derivation gives us a PARSE TREE Slide 1 Outline • Why should you care? • Parsing • Top-Down Parsing • Bottom-Up Parsing • Bottom-Up Space (an example) • Top Down Space (an example) • Top Down Space (an exercise) • Conclusion (Top Down Parse versus Bottom up Parse) Slide 1 Top-Down Parsing • Since we are trying to find trees rooted with an S (Sentences) start with the rules that give us an S. • Then work your way down from there to the words. Slide 1 Top Down Space Slide 1 Outline • Why should you care? • Parsing • Top-Down Parsing • Bottom-Up Parsing • Top Down Space (an example) • Top Down Space (an exercise) • Conclusion (Top Down Parse versus Bottom up Parse) Slide 1 Bottom-Up Parsing • Of course, we also want trees that cover the input words. So start with trees that link up with the words in the right way. • Then work your way up from there. Slide 1 Bottom-Up Space (an example) Slide 1 Outline • Why should you care? • Parsing • Top-Down Parsing • Bottom-Up Parsing • Bottom-Up Space (an example) • Top Down Space (an example) • Top Down Space (an exercise) • Conclusion (Top Down Parse versus Bottom up Parse) Slide 1 Top Down Space Example (Does this flight …..) Slide 1 Example … (cont’d) Slide 1 Example (cont’d) flight flight Slide 1 Example (cont’d) flight flight Slide 1 TOP-DOWN, DEPTH-FIRST, LEFT-TO-RIGHT Slide 1 Outline • Why should you care? • Parsing • Top-Down Parsing • Bottom-Up Parsing • Bottom-Up Space (an example) • Top Down Space (an example) • Top Down Space (an exercise) • Conclusion (Top Down Parse versus Bottom up Parse) Slide 1 Top Down Space (an exercise) Using Top Down Space draw the parse tree for the following sentence: 1- Book that flight. 2- John hit the ball. Slide 1 Top Down Space (result parse tree no.1) Slide 1 Top Down Space (result parse tree no.2) Slide 1 Avoiding Repeated Work Parsing is hard, and slow. It’s wasteful to redo stuff over and over and over. Consider an attempt to top-down parse the following as an NP A flight from Indianapolis to Houston on TWA Slide 1 Step by step parsing…1 flight Slide 1 Parsing step …2 flight flight Slide 1 Step by step parsing…3 Slide 1 The parse tree. s Slide 1 Top Down Space (an exercise) Using Top Down Space draw the parse tree for the following sentence: I shot an elephant in my pajamas. Slide 1 Top Down Space (result parse tree ) NP NP Pro I V Det shot PP NP Nom P an elephant in poss Nom my pajamas Slide 1 Top Down Space (result parse tree) Slide 1 Outline • Why should you care? • Parsing • Top-Down Parsing • Bottom-Up Parsing • Bottom-Up Space (an example) • Top Down Space (an example) • Top Down Space (an exercise) • Conclusion (Top Down Parse versus Bottom up Parse) Slide 1 TOP-DOWN AND BOTTOM-UP SEARCH STRATEGIES The search has to be guided by the INPUT and the GRAMMAR TOP-DOWN search: the parse tree has to be rooted in the start symbol S EXPECTATION-DRIVEN parsing BOTTOM-UP search: the parse tree must be an analysis of the input DATA-DRIVEN parsing Slide 1 TOP-DOWN vs BOTTOM-UP TOP-DOWN: Only search among grammatical answers BUT: suggests hypotheses that may not be consistent with data Problem: left-recursion BOTTOM-UP: Only forms hypotheses consistent with data BUT: may suggest hypotheses that make no sense globally Slide 1