lecture 15: dependency parsingkc2wc/teaching/nlp16/slides/15-dp.pdf · lecture 15: dependency...

51
Lecture 15: Dependency Parsing Kai-Wei Chang CS @ University of Virginia [email protected] Couse webpage: http://kwchang.net/teaching/NLP16 1 CS6501: NLP

Upload: others

Post on 30-May-2020

7 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Lecture 15: Dependency Parsingkc2wc/teaching/NLP16/slides/15-DP.pdf · Lecture 15: Dependency Parsing Kai-Wei Chang CS @ University of Virginia ... CS6501: NLP 15. CS6501: NLP 16

Lecture 15: Dependency Parsing

Kai-Wei ChangCS @ University of Virginia

[email protected]

Couse webpage: http://kwchang.net/teaching/NLP16

1CS6501: NLP

Page 2: Lecture 15: Dependency Parsingkc2wc/teaching/NLP16/slides/15-DP.pdf · Lecture 15: Dependency Parsing Kai-Wei Chang CS @ University of Virginia ... CS6501: NLP 15. CS6501: NLP 16

How to represent the structure

CS6501: NLP 2

Page 3: Lecture 15: Dependency Parsingkc2wc/teaching/NLP16/slides/15-DP.pdf · Lecture 15: Dependency Parsing Kai-Wei Chang CS @ University of Virginia ... CS6501: NLP 15. CS6501: NLP 16

Dependency trees

vDependency grammar describe the structure of sentences as a graph (tree)vNodes represent wordsvEdges represent dependencies

v Idea goes back to 4th century BCin ancient India

CS6501: NLP 3

Page 4: Lecture 15: Dependency Parsingkc2wc/teaching/NLP16/slides/15-DP.pdf · Lecture 15: Dependency Parsing Kai-Wei Chang CS @ University of Virginia ... CS6501: NLP 15. CS6501: NLP 16

Phrase structure (constituent parse) trees

v Can be modeled by Context-free grammarsv We will see how constituent parse and

dependency parse are related

CS6501: NLP 4

Page 5: Lecture 15: Dependency Parsingkc2wc/teaching/NLP16/slides/15-DP.pdf · Lecture 15: Dependency Parsing Kai-Wei Chang CS @ University of Virginia ... CS6501: NLP 15. CS6501: NLP 16

Context-free grammars

CS6501: NLP 5

PP→ PNPPP→ PDTNPP→ inthegarden

Non-terminal:DT,N,P,NP,PP,…Terminal:the,a,ball,garden

Page 6: Lecture 15: Dependency Parsingkc2wc/teaching/NLP16/slides/15-DP.pdf · Lecture 15: Dependency Parsing Kai-Wei Chang CS @ University of Virginia ... CS6501: NLP 15. CS6501: NLP 16

Generate sentences by CFG

CS6501: NLP 6

Page 7: Lecture 15: Dependency Parsingkc2wc/teaching/NLP16/slides/15-DP.pdf · Lecture 15: Dependency Parsing Kai-Wei Chang CS @ University of Virginia ... CS6501: NLP 15. CS6501: NLP 16

Parse tree defined by CFG

CS6501: NLP 7

1234567 Rule2 Rule4&1

Rule6

Page 8: Lecture 15: Dependency Parsingkc2wc/teaching/NLP16/slides/15-DP.pdf · Lecture 15: Dependency Parsing Kai-Wei Chang CS @ University of Virginia ... CS6501: NLP 15. CS6501: NLP 16

Example: noun phrases

CS6501: NLP 8

Page 9: Lecture 15: Dependency Parsingkc2wc/teaching/NLP16/slides/15-DP.pdf · Lecture 15: Dependency Parsing Kai-Wei Chang CS @ University of Virginia ... CS6501: NLP 15. CS6501: NLP 16

Example: verb phrase

CS6501: NLP 9

Page 10: Lecture 15: Dependency Parsingkc2wc/teaching/NLP16/slides/15-DP.pdf · Lecture 15: Dependency Parsing Kai-Wei Chang CS @ University of Virginia ... CS6501: NLP 15. CS6501: NLP 16

Sentences

CS6501: NLP 10

Page 11: Lecture 15: Dependency Parsingkc2wc/teaching/NLP16/slides/15-DP.pdf · Lecture 15: Dependency Parsing Kai-Wei Chang CS @ University of Virginia ... CS6501: NLP 15. CS6501: NLP 16

Constituent Parse

CS6501: NLP 11

From:KevinGimpel

Page 12: Lecture 15: Dependency Parsingkc2wc/teaching/NLP16/slides/15-DP.pdf · Lecture 15: Dependency Parsing Kai-Wei Chang CS @ University of Virginia ... CS6501: NLP 15. CS6501: NLP 16

Constituent Parse

CS6501: NLP 12

Non-terminal

Terminal

Sà NPVPNPà DTNNNPà DTPP à INNPVPà VBDPPVPà NPVBDNPVPà NPVB

Page 13: Lecture 15: Dependency Parsingkc2wc/teaching/NLP16/slides/15-DP.pdf · Lecture 15: Dependency Parsing Kai-Wei Chang CS @ University of Virginia ... CS6501: NLP 15. CS6501: NLP 16

Nonterminal in Penn Treebank

CS6501: NLP 13

Page 14: Lecture 15: Dependency Parsingkc2wc/teaching/NLP16/slides/15-DP.pdf · Lecture 15: Dependency Parsing Kai-Wei Chang CS @ University of Virginia ... CS6501: NLP 15. CS6501: NLP 16

Probabilistic Context-free Grammar

CS6501: NLP 14

Non-terminal

Terminal

1.0Sà NPVP0.6NPà DTNN0.4NPà NPPP1.0PPà INNP0.5VPà VBDPP0.2VPà NPVBDNP0.3VPà NPVB

Page 15: Lecture 15: Dependency Parsingkc2wc/teaching/NLP16/slides/15-DP.pdf · Lecture 15: Dependency Parsing Kai-Wei Chang CS @ University of Virginia ... CS6501: NLP 15. CS6501: NLP 16

Probabilistic Context-free Grammar

vPCFG achieves ~73% on PTBvState-of-the art ~92%

v Lexicalized PCFG(Collins 1997)

CS6501: NLP 15

Page 16: Lecture 15: Dependency Parsingkc2wc/teaching/NLP16/slides/15-DP.pdf · Lecture 15: Dependency Parsing Kai-Wei Chang CS @ University of Virginia ... CS6501: NLP 15. CS6501: NLP 16

CS6501: NLP 16

Page 17: Lecture 15: Dependency Parsingkc2wc/teaching/NLP16/slides/15-DP.pdf · Lecture 15: Dependency Parsing Kai-Wei Chang CS @ University of Virginia ... CS6501: NLP 15. CS6501: NLP 16

How to decide head?

vUsually use deterministic head rules (e.g., Collins head rules)

vDefine heads in CFGvS → NP VPvVP → VBD NP PPvNP → DT JJ NN

CS6501: NLP 17

FromNoahSmith

Page 18: Lecture 15: Dependency Parsingkc2wc/teaching/NLP16/slides/15-DP.pdf · Lecture 15: Dependency Parsing Kai-Wei Chang CS @ University of Virginia ... CS6501: NLP 15. CS6501: NLP 16

Lexical Head Annotation

CS6501: NLP 18

Page 19: Lecture 15: Dependency Parsingkc2wc/teaching/NLP16/slides/15-DP.pdf · Lecture 15: Dependency Parsing Kai-Wei Chang CS @ University of Virginia ... CS6501: NLP 15. CS6501: NLP 16

Constituent parse → Dependency Parse

CS6501: NLP 19

Page 20: Lecture 15: Dependency Parsingkc2wc/teaching/NLP16/slides/15-DP.pdf · Lecture 15: Dependency Parsing Kai-Wei Chang CS @ University of Virginia ... CS6501: NLP 15. CS6501: NLP 16

Constituent parse → Dependency Parse

CS6501: NLP 20

Page 21: Lecture 15: Dependency Parsingkc2wc/teaching/NLP16/slides/15-DP.pdf · Lecture 15: Dependency Parsing Kai-Wei Chang CS @ University of Virginia ... CS6501: NLP 15. CS6501: NLP 16

CS6501: NLP 21

HeadrulescanbeusedtoextractdependencyparsefromaCFG

Page 22: Lecture 15: Dependency Parsingkc2wc/teaching/NLP16/slides/15-DP.pdf · Lecture 15: Dependency Parsing Kai-Wei Chang CS @ University of Virginia ... CS6501: NLP 15. CS6501: NLP 16

CS6501: NLP 22

Arrowtypesshowthenameofgrammaticalrelations

Page 23: Lecture 15: Dependency Parsingkc2wc/teaching/NLP16/slides/15-DP.pdf · Lecture 15: Dependency Parsing Kai-Wei Chang CS @ University of Virginia ... CS6501: NLP 15. CS6501: NLP 16

Dependency parsing

vCan be more flexible (non-projective)vEnglish are mostly projective

vSome free word order languages (e.g., Czech) are non-projective

CS6501: NLP 23

Page 24: Lecture 15: Dependency Parsingkc2wc/teaching/NLP16/slides/15-DP.pdf · Lecture 15: Dependency Parsing Kai-Wei Chang CS @ University of Virginia ... CS6501: NLP 15. CS6501: NLP 16

How to build a dependency tree?

vThere are several approachesvGraph Algorithms

v Consider all word pairsv Create a Maximum Spanning Tree for a sentence

v Transition-base Approachesv Similar to how we parse a program:

Shift-Reduce Parser

v Many other approaches…

CS6501: NLP 24

Page 25: Lecture 15: Dependency Parsingkc2wc/teaching/NLP16/slides/15-DP.pdf · Lecture 15: Dependency Parsing Kai-Wei Chang CS @ University of Virginia ... CS6501: NLP 15. CS6501: NLP 16

Sources of information for DP

v Lexical affinitiesv [ issues → the ]v [ issues → I ]

vDistances vWords usually depend on nearby words

vValency of headsv# dependents for a head

CS6501: NLP 25

Page 26: Lecture 15: Dependency Parsingkc2wc/teaching/NLP16/slides/15-DP.pdf · Lecture 15: Dependency Parsing Kai-Wei Chang CS @ University of Virginia ... CS6501: NLP 15. CS6501: NLP 16

Graph-Based Approaches[McDonald et al. 2005]

vConsider all word pairs and assign scoresvScore of a tree = sum of score of edgesvCan be solve as a MST problem

vChu-Liu-Edmonds

CS6501: NLP 26

Page 27: Lecture 15: Dependency Parsingkc2wc/teaching/NLP16/slides/15-DP.pdf · Lecture 15: Dependency Parsing Kai-Wei Chang CS @ University of Virginia ... CS6501: NLP 15. CS6501: NLP 16

Transition-based parser

vMaltParser (Nivre et al. 2008)vSimilar to a Shift-Reduce Parser

vBut “reduce” actions can create dependencies

vThe parser has:vA stack 𝜎– starts with a “Root” symbolvA buffer 𝛽– starts with the input sentencevA set of dependency arcs A– starts off empty

vUse a set of actions to parse sentencesvMany possible action sets

CS6501: NLP 27

Page 28: Lecture 15: Dependency Parsingkc2wc/teaching/NLP16/slides/15-DP.pdf · Lecture 15: Dependency Parsing Kai-Wei Chang CS @ University of Virginia ... CS6501: NLP 15. CS6501: NLP 16

Arc-Eager Dependency Parser

vShift:

v Left-Arc:

CS6501: NLP 28

ROOTJoe likesMary Joe

ROOTlikesMary→

JoeROOT

likesMary →ROOT

likesMary

Joe

Precondition:𝑤% ≠ Root&(𝑤(,𝑤%) ∉ 𝐴

Page 29: Lecture 15: Dependency Parsingkc2wc/teaching/NLP16/slides/15-DP.pdf · Lecture 15: Dependency Parsing Kai-Wei Chang CS @ University of Virginia ... CS6501: NLP 15. CS6501: NLP 16

Arc-Eager Dependency Parser

vRight-Arc

vReduce:

CS6501: NLP 29

likeROOT

MaryMarylikeROOT→

Joe Joe

MarylikeROOT

Joe

→ likeROOT

Joe

Precondition:(𝑤(, 𝑤%) ∈ 𝐴Mary

Page 30: Lecture 15: Dependency Parsingkc2wc/teaching/NLP16/slides/15-DP.pdf · Lecture 15: Dependency Parsing Kai-Wei Chang CS @ University of Virginia ... CS6501: NLP 15. CS6501: NLP 16

Arc-Eager Dependency Parser

vStart:vConduct a sequence of actions

vTerminate with 𝜎, 𝛽 = ∅

CS6501: NLP 30

Page 31: Lecture 15: Dependency Parsingkc2wc/teaching/NLP16/slides/15-DP.pdf · Lecture 15: Dependency Parsing Kai-Wei Chang CS @ University of Virginia ... CS6501: NLP 15. CS6501: NLP 16

CS6501: NLP 31

Page 32: Lecture 15: Dependency Parsingkc2wc/teaching/NLP16/slides/15-DP.pdf · Lecture 15: Dependency Parsing Kai-Wei Chang CS @ University of Virginia ... CS6501: NLP 15. CS6501: NLP 16

CS6501: NLP 32

Page 33: Lecture 15: Dependency Parsingkc2wc/teaching/NLP16/slides/15-DP.pdf · Lecture 15: Dependency Parsing Kai-Wei Chang CS @ University of Virginia ... CS6501: NLP 15. CS6501: NLP 16

CS6501: NLP 33

Page 34: Lecture 15: Dependency Parsingkc2wc/teaching/NLP16/slides/15-DP.pdf · Lecture 15: Dependency Parsing Kai-Wei Chang CS @ University of Virginia ... CS6501: NLP 15. CS6501: NLP 16

CS6501: NLP 34

Page 35: Lecture 15: Dependency Parsingkc2wc/teaching/NLP16/slides/15-DP.pdf · Lecture 15: Dependency Parsing Kai-Wei Chang CS @ University of Virginia ... CS6501: NLP 15. CS6501: NLP 16

CS6501: NLP 35

Page 36: Lecture 15: Dependency Parsingkc2wc/teaching/NLP16/slides/15-DP.pdf · Lecture 15: Dependency Parsing Kai-Wei Chang CS @ University of Virginia ... CS6501: NLP 15. CS6501: NLP 16

CS6501: NLP 36

Page 37: Lecture 15: Dependency Parsingkc2wc/teaching/NLP16/slides/15-DP.pdf · Lecture 15: Dependency Parsing Kai-Wei Chang CS @ University of Virginia ... CS6501: NLP 15. CS6501: NLP 16

CS6501: NLP 37

Page 38: Lecture 15: Dependency Parsingkc2wc/teaching/NLP16/slides/15-DP.pdf · Lecture 15: Dependency Parsing Kai-Wei Chang CS @ University of Virginia ... CS6501: NLP 15. CS6501: NLP 16

CS6501: NLP 38

Page 39: Lecture 15: Dependency Parsingkc2wc/teaching/NLP16/slides/15-DP.pdf · Lecture 15: Dependency Parsing Kai-Wei Chang CS @ University of Virginia ... CS6501: NLP 15. CS6501: NLP 16

CS6501: NLP 39

Page 40: Lecture 15: Dependency Parsingkc2wc/teaching/NLP16/slides/15-DP.pdf · Lecture 15: Dependency Parsing Kai-Wei Chang CS @ University of Virginia ... CS6501: NLP 15. CS6501: NLP 16

CS6501: NLP 40

Page 41: Lecture 15: Dependency Parsingkc2wc/teaching/NLP16/slides/15-DP.pdf · Lecture 15: Dependency Parsing Kai-Wei Chang CS @ University of Virginia ... CS6501: NLP 15. CS6501: NLP 16

CS6501: NLP 41

Page 42: Lecture 15: Dependency Parsingkc2wc/teaching/NLP16/slides/15-DP.pdf · Lecture 15: Dependency Parsing Kai-Wei Chang CS @ University of Virginia ... CS6501: NLP 15. CS6501: NLP 16

CS6501: NLP 42

Page 43: Lecture 15: Dependency Parsingkc2wc/teaching/NLP16/slides/15-DP.pdf · Lecture 15: Dependency Parsing Kai-Wei Chang CS @ University of Virginia ... CS6501: NLP 15. CS6501: NLP 16

CS6501: NLP 43

Page 44: Lecture 15: Dependency Parsingkc2wc/teaching/NLP16/slides/15-DP.pdf · Lecture 15: Dependency Parsing Kai-Wei Chang CS @ University of Virginia ... CS6501: NLP 15. CS6501: NLP 16

CS6501: NLP 44

Page 45: Lecture 15: Dependency Parsingkc2wc/teaching/NLP16/slides/15-DP.pdf · Lecture 15: Dependency Parsing Kai-Wei Chang CS @ University of Virginia ... CS6501: NLP 15. CS6501: NLP 16

CS6501: NLP 45

Page 46: Lecture 15: Dependency Parsingkc2wc/teaching/NLP16/slides/15-DP.pdf · Lecture 15: Dependency Parsing Kai-Wei Chang CS @ University of Virginia ... CS6501: NLP 15. CS6501: NLP 16

CS6501: NLP 46

Page 47: Lecture 15: Dependency Parsingkc2wc/teaching/NLP16/slides/15-DP.pdf · Lecture 15: Dependency Parsing Kai-Wei Chang CS @ University of Virginia ... CS6501: NLP 15. CS6501: NLP 16

CS6501: NLP 47

Page 48: Lecture 15: Dependency Parsingkc2wc/teaching/NLP16/slides/15-DP.pdf · Lecture 15: Dependency Parsing Kai-Wei Chang CS @ University of Virginia ... CS6501: NLP 15. CS6501: NLP 16

It’s your turn

vHappy children like to play with their friend .vShift→ Left-arc→ Shift→ Left-arc →Right-arc→ Shift →Left-arc →Right-arc →Right-arc → Shift →Left-arc →Right-arc →Reduce*3→Right-arc →Reduce*3

CS6501: NLP 48

Page 49: Lecture 15: Dependency Parsingkc2wc/teaching/NLP16/slides/15-DP.pdf · Lecture 15: Dependency Parsing Kai-Wei Chang CS @ University of Virginia ... CS6501: NLP 15. CS6501: NLP 16

CS6501: NLP 49

FromChrisManning

Page 50: Lecture 15: Dependency Parsingkc2wc/teaching/NLP16/slides/15-DP.pdf · Lecture 15: Dependency Parsing Kai-Wei Chang CS @ University of Virginia ... CS6501: NLP 15. CS6501: NLP 16

CS6501: NLP 50

Page 51: Lecture 15: Dependency Parsingkc2wc/teaching/NLP16/slides/15-DP.pdf · Lecture 15: Dependency Parsing Kai-Wei Chang CS @ University of Virginia ... CS6501: NLP 15. CS6501: NLP 16

Structured Prediction –beyond sequence tagging

Task Input Output

Part-of-speechTagging

They operate ships and banks.

Dependency Parsing

They operate ships and banks.

51

Pronoun Verb Noun And Noun

Root Theyoperateshipsandbanks.

Assign values to a set of interdependent output variables