+ All Categories
Home > Documents > Dependency Parsing - UMIACSusers.umiacs.umd.edu/~jbg/teaching/CMSC_723/14b_shift.pdf · Dependency...

Dependency Parsing - UMIACSusers.umiacs.umd.edu/~jbg/teaching/CMSC_723/14b_shift.pdf · Dependency...

Date post: 02-Oct-2020
Category:
Upload: others
View: 4 times
Download: 0 times
Share this document with a friend
46
Dependency Parsing Computational Linguistics: Jordan Boyd-Graber University of Maryland SHIFT-REDUCE Adapted from material by Jimmy Lin and Jason Eisner Computational Linguistics: Jordan Boyd-Graber | UMD Dependency Parsing | 1 / 13
Transcript
Page 1: Dependency Parsing - UMIACSusers.umiacs.umd.edu/~jbg/teaching/CMSC_723/14b_shift.pdf · Dependency Parsing Computational Linguistics: Jordan Boyd-Graber University of Maryland SHIFT-REDUCE

Dependency Parsing

Computational Linguistics: Jordan Boyd-GraberUniversity of MarylandSHIFT-REDUCE

Adapted from material by Jimmy Lin and Jason Eisner

Computational Linguistics: Jordan Boyd-Graber | UMD Dependency Parsing | 1 / 13

Page 2: Dependency Parsing - UMIACSusers.umiacs.umd.edu/~jbg/teaching/CMSC_723/14b_shift.pdf · Dependency Parsing Computational Linguistics: Jordan Boyd-Graber University of Maryland SHIFT-REDUCE

Shift-Reduce Parsing

� Alternative to arc-factored models

� Cognitively plausible

� Better at short-range dependencies

Computational Linguistics: Jordan Boyd-Graber | UMD Dependency Parsing | 2 / 13

Page 3: Dependency Parsing - UMIACSusers.umiacs.umd.edu/~jbg/teaching/CMSC_723/14b_shift.pdf · Dependency Parsing Computational Linguistics: Jordan Boyd-Graber University of Maryland SHIFT-REDUCE

Example

Computational Linguistics: Jordan Boyd-Graber | UMD Dependency Parsing | 3 / 13

Page 4: Dependency Parsing - UMIACSusers.umiacs.umd.edu/~jbg/teaching/CMSC_723/14b_shift.pdf · Dependency Parsing Computational Linguistics: Jordan Boyd-Graber University of Maryland SHIFT-REDUCE

Example

Computational Linguistics: Jordan Boyd-Graber | UMD Dependency Parsing | 3 / 13

Page 5: Dependency Parsing - UMIACSusers.umiacs.umd.edu/~jbg/teaching/CMSC_723/14b_shift.pdf · Dependency Parsing Computational Linguistics: Jordan Boyd-Graber University of Maryland SHIFT-REDUCE

Example

Computational Linguistics: Jordan Boyd-Graber | UMD Dependency Parsing | 3 / 13

Page 6: Dependency Parsing - UMIACSusers.umiacs.umd.edu/~jbg/teaching/CMSC_723/14b_shift.pdf · Dependency Parsing Computational Linguistics: Jordan Boyd-Graber University of Maryland SHIFT-REDUCE

Example

Computational Linguistics: Jordan Boyd-Graber | UMD Dependency Parsing | 3 / 13

Page 7: Dependency Parsing - UMIACSusers.umiacs.umd.edu/~jbg/teaching/CMSC_723/14b_shift.pdf · Dependency Parsing Computational Linguistics: Jordan Boyd-Graber University of Maryland SHIFT-REDUCE

Example

Computational Linguistics: Jordan Boyd-Graber | UMD Dependency Parsing | 3 / 13

Page 8: Dependency Parsing - UMIACSusers.umiacs.umd.edu/~jbg/teaching/CMSC_723/14b_shift.pdf · Dependency Parsing Computational Linguistics: Jordan Boyd-Graber University of Maryland SHIFT-REDUCE

Example

Computational Linguistics: Jordan Boyd-Graber | UMD Dependency Parsing | 3 / 13

Page 9: Dependency Parsing - UMIACSusers.umiacs.umd.edu/~jbg/teaching/CMSC_723/14b_shift.pdf · Dependency Parsing Computational Linguistics: Jordan Boyd-Graber University of Maryland SHIFT-REDUCE

Example

Computational Linguistics: Jordan Boyd-Graber | UMD Dependency Parsing | 3 / 13

Page 10: Dependency Parsing - UMIACSusers.umiacs.umd.edu/~jbg/teaching/CMSC_723/14b_shift.pdf · Dependency Parsing Computational Linguistics: Jordan Boyd-Graber University of Maryland SHIFT-REDUCE

Example

Computational Linguistics: Jordan Boyd-Graber | UMD Dependency Parsing | 3 / 13

Page 11: Dependency Parsing - UMIACSusers.umiacs.umd.edu/~jbg/teaching/CMSC_723/14b_shift.pdf · Dependency Parsing Computational Linguistics: Jordan Boyd-Graber University of Maryland SHIFT-REDUCE

Example

Computational Linguistics: Jordan Boyd-Graber | UMD Dependency Parsing | 3 / 13

Page 12: Dependency Parsing - UMIACSusers.umiacs.umd.edu/~jbg/teaching/CMSC_723/14b_shift.pdf · Dependency Parsing Computational Linguistics: Jordan Boyd-Graber University of Maryland SHIFT-REDUCE

Example

Computational Linguistics: Jordan Boyd-Graber | UMD Dependency Parsing | 3 / 13

Page 13: Dependency Parsing - UMIACSusers.umiacs.umd.edu/~jbg/teaching/CMSC_723/14b_shift.pdf · Dependency Parsing Computational Linguistics: Jordan Boyd-Graber University of Maryland SHIFT-REDUCE

Components

� Process a sentence word by word from a buffer

� You can temporarily place store words on a stack� As you process you can either:

� Shift: Move a word from the buffer to the stack� Left: The top of the stack is the child of the buffer’s next word� Right: The buffer’s next word is the child of the top of the stack

Computational Linguistics: Jordan Boyd-Graber | UMD Dependency Parsing | 4 / 13

Page 14: Dependency Parsing - UMIACSusers.umiacs.umd.edu/~jbg/teaching/CMSC_723/14b_shift.pdf · Dependency Parsing Computational Linguistics: Jordan Boyd-Graber University of Maryland SHIFT-REDUCE

Components

� Process a sentence word by word from a buffer

� You can temporarily place store words on a stack� As you process you can either:� Shift: Move a word from the buffer to the stack

� Left: The top of the stack is the child of the buffer’s next word� Right: The buffer’s next word is the child of the top of the stack

Computational Linguistics: Jordan Boyd-Graber | UMD Dependency Parsing | 4 / 13

Page 15: Dependency Parsing - UMIACSusers.umiacs.umd.edu/~jbg/teaching/CMSC_723/14b_shift.pdf · Dependency Parsing Computational Linguistics: Jordan Boyd-Graber University of Maryland SHIFT-REDUCE

Components

� Process a sentence word by word from a buffer

� You can temporarily place store words on a stack� As you process you can either:� Shift: Move a word from the buffer to the stack� Left: The top of the stack is the child of the buffer’s next word

� Right: The buffer’s next word is the child of the top of the stack

Computational Linguistics: Jordan Boyd-Graber | UMD Dependency Parsing | 4 / 13

Page 16: Dependency Parsing - UMIACSusers.umiacs.umd.edu/~jbg/teaching/CMSC_723/14b_shift.pdf · Dependency Parsing Computational Linguistics: Jordan Boyd-Graber University of Maryland SHIFT-REDUCE

Components

� Process a sentence word by word from a buffer

� You can temporarily place store words on a stack� As you process you can either:� Shift: Move a word from the buffer to the stack� Left: The top of the stack is the child of the buffer’s next word� Right: The buffer’s next word is the child of the top of the stack

Computational Linguistics: Jordan Boyd-Graber | UMD Dependency Parsing | 4 / 13

Page 17: Dependency Parsing - UMIACSusers.umiacs.umd.edu/~jbg/teaching/CMSC_723/14b_shift.pdf · Dependency Parsing Computational Linguistics: Jordan Boyd-Graber University of Maryland SHIFT-REDUCE

Initial and Final Conditions

� Initially the stack has root, the buffer has the sentence’s words, andthere are no edges

� At the end, the buffer must be empty

Computational Linguistics: Jordan Boyd-Graber | UMD Dependency Parsing | 5 / 13

Page 18: Dependency Parsing - UMIACSusers.umiacs.umd.edu/~jbg/teaching/CMSC_723/14b_shift.pdf · Dependency Parsing Computational Linguistics: Jordan Boyd-Graber University of Maryland SHIFT-REDUCE

Action: Left

� Add an edge (wj ,wi)

� wi is the top of the stack

� wj is the first word of the buffer

� Pop the stack

� Stack and buffer must be non-empty; wi cannot be the root

Computational Linguistics: Jordan Boyd-Graber | UMD Dependency Parsing | 6 / 13

Page 19: Dependency Parsing - UMIACSusers.umiacs.umd.edu/~jbg/teaching/CMSC_723/14b_shift.pdf · Dependency Parsing Computational Linguistics: Jordan Boyd-Graber University of Maryland SHIFT-REDUCE

Action: Left

� Add an edge (wj ,wi)

� wi is the top of the stack

� wj is the first word of the buffer

� Pop the stack

� Stack and buffer must be non-empty; wi cannot be the root

Computational Linguistics: Jordan Boyd-Graber | UMD Dependency Parsing | 6 / 13

Page 20: Dependency Parsing - UMIACSusers.umiacs.umd.edu/~jbg/teaching/CMSC_723/14b_shift.pdf · Dependency Parsing Computational Linguistics: Jordan Boyd-Graber University of Maryland SHIFT-REDUCE

Action: Right

� Add an edge (wi ,wj)

� wi is the top of the stack

� wj is the first word in the buffer

� Pop the stack

� Replace wj by wi at the head of buffer

� Stack and buffer must be non-empty

Computational Linguistics: Jordan Boyd-Graber | UMD Dependency Parsing | 7 / 13

Page 21: Dependency Parsing - UMIACSusers.umiacs.umd.edu/~jbg/teaching/CMSC_723/14b_shift.pdf · Dependency Parsing Computational Linguistics: Jordan Boyd-Graber University of Maryland SHIFT-REDUCE

Action: Right

� Add an edge (wi ,wj)

� wi is the top of the stack

� wj is the first word in the buffer

� Pop the stack

� Replace wj by wi at the head of buffer

� Stack and buffer must be non-empty

Computational Linguistics: Jordan Boyd-Graber | UMD Dependency Parsing | 7 / 13

Page 22: Dependency Parsing - UMIACSusers.umiacs.umd.edu/~jbg/teaching/CMSC_723/14b_shift.pdf · Dependency Parsing Computational Linguistics: Jordan Boyd-Graber University of Maryland SHIFT-REDUCE

Shift

� Removes wi from the buffer

� Places it on the stack

� Buffer must be non-empty

Computational Linguistics: Jordan Boyd-Graber | UMD Dependency Parsing | 8 / 13

Page 23: Dependency Parsing - UMIACSusers.umiacs.umd.edu/~jbg/teaching/CMSC_723/14b_shift.pdf · Dependency Parsing Computational Linguistics: Jordan Boyd-Graber University of Maryland SHIFT-REDUCE

Shift

� Removes wi from the buffer

� Places it on the stack

� Buffer must be non-empty

Computational Linguistics: Jordan Boyd-Graber | UMD Dependency Parsing | 8 / 13

Page 24: Dependency Parsing - UMIACSusers.umiacs.umd.edu/~jbg/teaching/CMSC_723/14b_shift.pdf · Dependency Parsing Computational Linguistics: Jordan Boyd-Graber University of Maryland SHIFT-REDUCE

Shift Reduce Example

Stack

[root ]

Buffer

[economic, news, had, little, effect,on, financial, markets, .]

Next transition: 1. Shift

Computational Linguistics: Jordan Boyd-Graber | UMD Dependency Parsing | 9 / 13

Page 25: Dependency Parsing - UMIACSusers.umiacs.umd.edu/~jbg/teaching/CMSC_723/14b_shift.pdf · Dependency Parsing Computational Linguistics: Jordan Boyd-Graber University of Maryland SHIFT-REDUCE

Shift Reduce Example

Stack

[root , economic ]

Buffer

[news, had, little, effect, on, financial,markets, .]

Next transition: 2. Left

Computational Linguistics: Jordan Boyd-Graber | UMD Dependency Parsing | 9 / 13

Page 26: Dependency Parsing - UMIACSusers.umiacs.umd.edu/~jbg/teaching/CMSC_723/14b_shift.pdf · Dependency Parsing Computational Linguistics: Jordan Boyd-Graber University of Maryland SHIFT-REDUCE

Shift Reduce Example

Stack

[root ]

Buffer

[news, had, little, effect, on, financial,markets, .]

Next transition: 3. Shift

Computational Linguistics: Jordan Boyd-Graber | UMD Dependency Parsing | 9 / 13

Page 27: Dependency Parsing - UMIACSusers.umiacs.umd.edu/~jbg/teaching/CMSC_723/14b_shift.pdf · Dependency Parsing Computational Linguistics: Jordan Boyd-Graber University of Maryland SHIFT-REDUCE

Shift Reduce Example

Stack

[root , news ]

Buffer

[had, little, effect, on, financial,markets, .]

Next transition: 4. Left

Computational Linguistics: Jordan Boyd-Graber | UMD Dependency Parsing | 9 / 13

Page 28: Dependency Parsing - UMIACSusers.umiacs.umd.edu/~jbg/teaching/CMSC_723/14b_shift.pdf · Dependency Parsing Computational Linguistics: Jordan Boyd-Graber University of Maryland SHIFT-REDUCE

Shift Reduce Example

Stack

[root ]

Buffer

[had, little, effect, on, financial,markets, .]

Next transition: 5. Shift

Computational Linguistics: Jordan Boyd-Graber | UMD Dependency Parsing | 9 / 13

Page 29: Dependency Parsing - UMIACSusers.umiacs.umd.edu/~jbg/teaching/CMSC_723/14b_shift.pdf · Dependency Parsing Computational Linguistics: Jordan Boyd-Graber University of Maryland SHIFT-REDUCE

Shift Reduce Example

Stack

[root , had ]

Buffer

[little, effect, on, financial, markets, .]

Next transition: 6. Shift

Computational Linguistics: Jordan Boyd-Graber | UMD Dependency Parsing | 9 / 13

Page 30: Dependency Parsing - UMIACSusers.umiacs.umd.edu/~jbg/teaching/CMSC_723/14b_shift.pdf · Dependency Parsing Computational Linguistics: Jordan Boyd-Graber University of Maryland SHIFT-REDUCE

Shift Reduce Example

Stack

[root , had , little ]

Buffer

[effect, on, financial, markets, .]

Next transition: 7. Left

Computational Linguistics: Jordan Boyd-Graber | UMD Dependency Parsing | 9 / 13

Page 31: Dependency Parsing - UMIACSusers.umiacs.umd.edu/~jbg/teaching/CMSC_723/14b_shift.pdf · Dependency Parsing Computational Linguistics: Jordan Boyd-Graber University of Maryland SHIFT-REDUCE

Shift Reduce Example

Stack

[root , had ]

Buffer

[effect, on, financial, markets, .]

Next transition: 8. Shift

Computational Linguistics: Jordan Boyd-Graber | UMD Dependency Parsing | 9 / 13

Page 32: Dependency Parsing - UMIACSusers.umiacs.umd.edu/~jbg/teaching/CMSC_723/14b_shift.pdf · Dependency Parsing Computational Linguistics: Jordan Boyd-Graber University of Maryland SHIFT-REDUCE

Shift Reduce Example

Stack

[root , had , effect ]

Buffer

[on, financial, markets, .]

Next transition: 9. Shift

Computational Linguistics: Jordan Boyd-Graber | UMD Dependency Parsing | 9 / 13

Page 33: Dependency Parsing - UMIACSusers.umiacs.umd.edu/~jbg/teaching/CMSC_723/14b_shift.pdf · Dependency Parsing Computational Linguistics: Jordan Boyd-Graber University of Maryland SHIFT-REDUCE

Shift Reduce Example

Stack

[root , had , effect , on ]

Buffer

[financial, markets, .]

Next transition: 10. Shift

Computational Linguistics: Jordan Boyd-Graber | UMD Dependency Parsing | 9 / 13

Page 34: Dependency Parsing - UMIACSusers.umiacs.umd.edu/~jbg/teaching/CMSC_723/14b_shift.pdf · Dependency Parsing Computational Linguistics: Jordan Boyd-Graber University of Maryland SHIFT-REDUCE

Shift Reduce Example

Stack

[root , had , effect , on , financial ]

Buffer

[markets, .]

Next transition: 11. Left

Computational Linguistics: Jordan Boyd-Graber | UMD Dependency Parsing | 9 / 13

Page 35: Dependency Parsing - UMIACSusers.umiacs.umd.edu/~jbg/teaching/CMSC_723/14b_shift.pdf · Dependency Parsing Computational Linguistics: Jordan Boyd-Graber University of Maryland SHIFT-REDUCE

Shift Reduce Example

Stack

[root , had , effect , on ]

Buffer

[markets, .]

Next transition: 12. Right

Computational Linguistics: Jordan Boyd-Graber | UMD Dependency Parsing | 9 / 13

Page 36: Dependency Parsing - UMIACSusers.umiacs.umd.edu/~jbg/teaching/CMSC_723/14b_shift.pdf · Dependency Parsing Computational Linguistics: Jordan Boyd-Graber University of Maryland SHIFT-REDUCE

Shift Reduce Example

Stack

[root , had , effect ]

Buffer

[on, .]

Next transition: 13. Right

Computational Linguistics: Jordan Boyd-Graber | UMD Dependency Parsing | 9 / 13

Page 37: Dependency Parsing - UMIACSusers.umiacs.umd.edu/~jbg/teaching/CMSC_723/14b_shift.pdf · Dependency Parsing Computational Linguistics: Jordan Boyd-Graber University of Maryland SHIFT-REDUCE

Shift Reduce Example

Stack

[root , had ]

Buffer

[effect, .]

Next transition: 14. Right

Computational Linguistics: Jordan Boyd-Graber | UMD Dependency Parsing | 9 / 13

Page 38: Dependency Parsing - UMIACSusers.umiacs.umd.edu/~jbg/teaching/CMSC_723/14b_shift.pdf · Dependency Parsing Computational Linguistics: Jordan Boyd-Graber University of Maryland SHIFT-REDUCE

Shift Reduce Example

Stack

[root ]

Buffer

[had, .]

Next transition: 15. Shift

Computational Linguistics: Jordan Boyd-Graber | UMD Dependency Parsing | 9 / 13

Page 39: Dependency Parsing - UMIACSusers.umiacs.umd.edu/~jbg/teaching/CMSC_723/14b_shift.pdf · Dependency Parsing Computational Linguistics: Jordan Boyd-Graber University of Maryland SHIFT-REDUCE

Shift Reduce Example

Stack

[root , had]

Buffer

[.]

Next transition: 16. Right

Computational Linguistics: Jordan Boyd-Graber | UMD Dependency Parsing | 9 / 13

Page 40: Dependency Parsing - UMIACSusers.umiacs.umd.edu/~jbg/teaching/CMSC_723/14b_shift.pdf · Dependency Parsing Computational Linguistics: Jordan Boyd-Graber University of Maryland SHIFT-REDUCE

Shift Reduce Example

Stack

[root ]

Buffer

[had]

Next transition: 17. Right

Computational Linguistics: Jordan Boyd-Graber | UMD Dependency Parsing | 9 / 13

Page 41: Dependency Parsing - UMIACSusers.umiacs.umd.edu/~jbg/teaching/CMSC_723/14b_shift.pdf · Dependency Parsing Computational Linguistics: Jordan Boyd-Graber University of Maryland SHIFT-REDUCE

Shift Reduce Example

Stack

[ ]

Buffer

[root]

Next transition: 18. Shift

Computational Linguistics: Jordan Boyd-Graber | UMD Dependency Parsing | 9 / 13

Page 42: Dependency Parsing - UMIACSusers.umiacs.umd.edu/~jbg/teaching/CMSC_723/14b_shift.pdf · Dependency Parsing Computational Linguistics: Jordan Boyd-Graber University of Maryland SHIFT-REDUCE

Shift Reduce Example

Stack

[root ]

Buffer

[]

Next transition:

Computational Linguistics: Jordan Boyd-Graber | UMD Dependency Parsing | 9 / 13

Page 43: Dependency Parsing - UMIACSusers.umiacs.umd.edu/~jbg/teaching/CMSC_723/14b_shift.pdf · Dependency Parsing Computational Linguistics: Jordan Boyd-Graber University of Maryland SHIFT-REDUCE

Transition Sequence Algorithm

� Start with root on stack, buffer with whole sentence

� If there’s nothing on the stack, you must shift

� If the top of the stack is the child of the top of the buffer, then make a leftedge

� If the top of the buffer is is a child of the top of the stack and the top ofthe buffer has no children that have yet to be added to the tree, thenmake a right

Computational Linguistics: Jordan Boyd-Graber | UMD Dependency Parsing | 10 / 13

Page 44: Dependency Parsing - UMIACSusers.umiacs.umd.edu/~jbg/teaching/CMSC_723/14b_shift.pdf · Dependency Parsing Computational Linguistics: Jordan Boyd-Graber University of Maryland SHIFT-REDUCE

How to apply to data

� Create oracle for all sentences

� Create three-way classifier for each possible actions� Features� The top of the stack� Top two words on buffer� The parts of speech of the words

Computational Linguistics: Jordan Boyd-Graber | UMD Dependency Parsing | 11 / 13

Page 45: Dependency Parsing - UMIACSusers.umiacs.umd.edu/~jbg/teaching/CMSC_723/14b_shift.pdf · Dependency Parsing Computational Linguistics: Jordan Boyd-Graber University of Maryland SHIFT-REDUCE

Complexity

� A word can only enter the stack once

� So complexity is O(2N)

Computational Linguistics: Jordan Boyd-Graber | UMD Dependency Parsing | 12 / 13

Page 46: Dependency Parsing - UMIACSusers.umiacs.umd.edu/~jbg/teaching/CMSC_723/14b_shift.pdf · Dependency Parsing Computational Linguistics: Jordan Boyd-Graber University of Maryland SHIFT-REDUCE

Comparison

� Shift-reduce parsers are faster

� Shift-reduce parsers do better at local (deeper) connections

� Arc-factored models do better at long-distance dependencies (e.g.,verbs)

Computational Linguistics: Jordan Boyd-Graber | UMD Dependency Parsing | 13 / 13


Recommended