/
Syntactic Syntactic

Syntactic - PowerPoint Presentation

natalia-silvester
natalia-silvester . @natalia-silvester
Follow
419 views
Uploaded On 2016-08-17

Syntactic - PPT Presentation

Parsing with CFGs CMSC 723 Computational Linguistics I Session 7 Jimmy Lin The iSchool University of Maryland Wednesday October 14 2009 Todays Agenda Words structure meaning ID: 449929

cky parsing top search parsing cky search top grammar earley bottom input trees rule chart table shared rules states

Share:

Link:

Embed:

Download Presentation from below link

Download Presentation The PPT/PDF document "Syntactic" is the property of its rightful owner. Permission is granted to download and print the materials on this web site for personal, non-commercial use only, and to display it on your personal computer provided you do not modify the materials and that you retain all copyright notices contained in the materials. By downloading content from our website, you accept the terms of this agreement.


Presentation Transcript

Slide1

Syntactic Parsing with CFGs

CMSC 723: Computational Linguistics I ― Session #7

Jimmy LinThe iSchoolUniversity of MarylandWednesday, October 14, 2009Slide2

Today’s AgendaWords… structure… meaning…Last week: formal grammarsContext-free grammars

Grammars for EnglishTreebanksDependency grammarsToday: parsing with CFGsTop-down and bottom-up parsing

CKY parsingEarley parsingSlide3

ParsingProblem setup:Input: string and a CFGOutput: parse tree assigning proper structure to input string

“Proper structure”Tree that covers all and only words in the inputTree is rooted at an SDerivations obey rules of the grammar

Usually, more than one parse tree…Unfortunately, parsing algorithms don’t help in selecting the correct tree from among all the possible treesSlide4

Parsing AlgorithmsParsing is (surprise) a search problemTwo basic (= bad) algorithms:Top-down searchBottom-up searchTwo “real” algorithms:

CKY parsingEarley parsingSimplifying assumptions:Morphological analysis is doneAll the words are knownSlide5

Top-Down SearchObservation: trees must be rooted with an S nodeParsing strategy:Start at top with an S nodeApply rules to build out trees

Work down toward leavesSlide6

Top-Down SearchSlide7

Top-Down SearchSlide8

Top-Down SearchSlide9

Bottom-Up SearchObservation: trees must cover all input wordsParsing strategy:Start at the bottom with input words

Build structure based on grammarWork up towards the root SSlide10

Bottom-Up SearchSlide11

Bottom-Up SearchSlide12

Bottom-Up SearchSlide13

Bottom-Up SearchSlide14

Bottom-Up SearchSlide15

Top-Down vs. Bottom-UpTop-down searchOnly searches valid treesBut, considers trees that

are not consistent with any of the wordsBottom-up searchOnly builds trees consistent with the inputBut,

considers trees that don’t lead anywhereSlide16

Parsing as SearchSearch involves controlling choices in the search space:Which node to focus on in building structure

Which grammar rule to applyGeneral strategy: backtrackingMake a choice, if it works out then fineIf not,

then back up and make a different choiceRemember DFS/BFS for NDFSA recognition?Slide17

Backtracking isn’t enough!AmbiguityShared sub-problemsSlide18

Ambiguity

Or consider: I saw the man on the hill with the telescope.Slide19

Shared Sub-ProblemsObservation: ambiguous parses still share sub-treesWe don’t want to redo work that’s already been doneUnfortunately, naïve backtracking leads to duplicate workSlide20

Shared Sub-Problems: ExampleExample: “A flight from Indianapolis to Houston on TWA”Assume a top-down parse making choices among the various nominal rules:

Nominal → NounNominal → Nominal PPStatically choosing the rules in this order leads to

lots of extra work...Slide21

Shared Sub-Problems: ExampleSlide22

Efficient ParsingDynamic programming to the rescue!Intuition: store partial results in tables, thereby:Avoiding repeated work on shared sub-problemsEfficiently storing ambiguous structures with shared sub-parts

Two algorithms:CKY: roughly, bottom-upEarley: roughly, top-downSlide23

CKY Parsing: CNFCKY parsing requires that the grammar consist of ε-free, binary rules = Chomsky Normal FormAll rules of the form:

What does the tree look like?What if my CFG isn’t in CNF?

A → B C D → wSlide24

CKY Parsing with Arbitrary CFGsProblem: my grammar has rules like VP → NP PP PPCan’t apply CKY!Solution: rewrite grammar into CNF

Introduce new intermediate non-terminals into the grammarWhat does this mean?= weak equivalenceThe rewritten grammar accepts (and rejects) the same set of strings as the original grammar…

But the resulting derivations (trees) are differentA  B C DA  X DX

B C

(Where X is a symbol that doesn’t occur anywhere else in the grammar)Slide25

Sample L1 GrammarSlide26

L1 Grammar: CNF ConversionSlide27

CKY Parsing: IntuitionConsider the rule D → wTerminal (word) forms a constituentTrivial to applyConsider the rule A →

B CIf there is an A somewhere in the input then there must be a B followed by a C in the inputFirst, precisely define span [ i, j

] If A spans from i to j in the input then there must be some k such that i<k<jEasy to apply: we just need to try different values for k

A

B

C

i

j

kSlide28

CKY Parsing: TableAny constituent can conceivably span [ i, j ] for all 0≤i<

j≤N, where N = length of input stringWe need an N

× N table to keep track of all spans…But we only need half of the tableSemantics of table: cell [ i, j ] contains A iff A spans i to j in the input stringOf course, must be allowed by the grammar!Slide29

CKY Parsing: Table-FillingSo let’s fill this table…And look at the cell [ 0, N ]: which means?

But how?Slide30

CKY Parsing: Table-FillingIn order for A to span [ i, j ]:A

 B C is a rule in the grammar, andThere must be a B in [ i, k ] and a C in [

k, j ] for some i<k<jOperationally: To apply rule A  B C, look for a B in [ i, k ] and a C in [ k, j ]In the table: look left in the row and down in the columnSlide31

CKY Parsing: Rule Application

note: mistake in book (Figure 13.11, p 441), should be [0,n]Slide32

CKY Parsing: Cell OrderingCKY = exercise in filling the table representing spansNeed to establish a systematic order for considering each cellFor each cell [

i, j ] consider all possible values for k and try applying each ruleWhat constraints do we have on the ordering of the cells?Slide33

CKY Parsing: Canonical OrderingStandard CKY algorithm:Fill the table a column at a time, from left to right, bottom to top Whenever

we’re filling a cell, the parts needed are already in the table (to the left and below)Nice property: processes input left to right, word at a timeSlide34

CKY Parsing: Ordering IllustratedSlide35

CKY AlgorithmSlide36

CKY Parsing: Recognize or ParseIs this really a parser?Recognizer to parser: add backpointers!Slide37

CKY: Example

Filling column 5

?

?

?

?Slide38

CKY: Example

?

?

?Slide39

CKY: Example

?

?Slide40

CKY: Example

?Slide41

CKY: ExampleSlide42

CKY: Algorithmic ComplexityWhat’s the asymptotic complexity of CKY?Slide43

CKY: AnalysisSince it’s bottom up, CKY populates the table with a lot of “phantom constituents”Spans that are constituents, but cannot really occur in the context in which they are suggestedConversion of grammar to CNF adds additional non-terminal nodesLeads to weak equivalence

wrt original grammarAdditional terminal nodes not (linguistically) meaningful: but can be cleaned up with post processing

Is there a parsing algorithm for arbitrary CFGs that combines dynamic programming and top-down control?Slide44

Earley ParsingDynamic programming algorithm (surprise)Allows arbitrary CFGsTop-down controlBut, compare with naïve top-down searchFills a chart in a single sweep over the input

Chart is an array of length N + 1, where N = number of wordsChart entries represent states:

Completed constituents and their locationsIn-progress constituentsPredicted constituentsSlide45

Chart Entries: StatesCharts are populated with statesEach state contains three items of information:A grammar ruleInformation about progress made in completing the sub-tree represented by the rule

Span of the sub-treeSlide46

Chart Entries: State ExamplesS  • VP [0,0]A VP is predicted at the start of the sentenceNP

 Det • Nominal [1,2]An NP is in progress; the Det goes from 1 to 2

VP  V NP • [0,3]A VP has been found starting at 0 and ending at 3Slide47

Earley in a nutshellStart by predicting SStep through chart:New predicted states are created from current states

New incomplete states are created by advancing existing states as new constituents are discoveredStates are completed when rules are satisfied

Termination: look for S  α • [ 0, N ]Slide48

Earley AlgorithmSlide49

Earley AlgorithmSlide50

Earley ExampleInput: Book that flightDesired end state: S  α

• [0,3]Meaning: S spanning from 0 to 3, completed ruleSlide51

Earley: Chart[0]

Note that given a grammar, these entries are the same for all inputs; they can be

pre-loaded…Slide52

Earley: Chart[1]Slide53

Earley: Chart[2] and Chart[3]Slide54

Earley: Recovering the Parse

As with CKY, add backpointers

…Slide55

Earley: EfficiencyFor such a simple example, there seems to be a lot of useless stuff…Why?Slide56

Back to AmbiguityDid we solve it?No: both CKY and Earley return multiple parse trees…Plus: compact encoding with shared sub-trees

Plus: work deriving shared sub-trees is reusedMinus: neither algorithm tells us which parse is correctSlide57

AmbiguityWhy don’t humans usually encounter ambiguity?How can we improve our models?Slide58

What we covered today..Parsing is (surprise) a search problemTwo important issues:AmbiguityShared sub-problems

Two basic (= bad) algorithms:Top-down searchBottom-up searchTwo “real” algorithms:CKY parsingEarley

parsing