1
Yulia Tsvetkov
Algorithms for NLP
IITP, Fall 2019
Lecture 11: Parsing III
Algorithms for NLP IITP, Fall 2019 Lecture 11: Parsing III Yulia - - PowerPoint PPT Presentation
Algorithms for NLP IITP, Fall 2019 Lecture 11: Parsing III Yulia Tsvetkov 1 Syntactic Parsing INPUT: The move followed a round of similar increases by other lenders, reflecting a continuing decline in that market OUTPUT:
1
Yulia Tsvetkov
IITP, Fall 2019
Lecture 11: Parsing III
▪ INPUT:
▪ The move followed a round of similar increases by other
lenders, reflecting a continuing decline in that market ▪ OUTPUT:
▪ Internal nodes correspond to phrases
▪ S – a sentence ▪ NP (Noun Phrase): My dog, a sandwich, lakes,.. ▪ VP (Verb Phrase): ate a sausage, barked, … ▪ PP (Prepositional phrases): with a friend, in a
car, …
▪ Nodes immediately above words are PoS tags (aka preterminals)
▪ PN – pronoun ▪ D – determiner ▪ V – verb ▪ N – noun ▪ P – preposition
▪ Other grammar formalisms: LFG, HPSG, TAG, CCG…
Grammar (CFG) Lexicon
ROOT → S S → NP VP NP → DT NN NP → NN NNS NN → interest NNS → raises VBP → interest VBZ → raises … NP → NP PP VP → VBP NP VP → VBP NP PP PP → IN NP
▪ The basic CKY algorithm supports only rules in the Chomsky Normal Form (CNF): ▪ Any CFG can be converted to an equivalent CNF
▪ Equivalent means that they define the same language ▪ However (syntactic) trees will look differently ▪ It is possible to address it by defining such transformations that allows for easy reverse transformation
Preterminal rules Inner rules
Preterminal rules Inner rules
Chart (aka parsing triangle)
Preterminal rules Inner rules
Preterminal rules Inner rules
Preterminal rules Inner rules
Preterminal rules Inner rules
Preterminal rules Inner rules
Preterminal rules Inner rules
Preterminal rules Inner rules
Preterminal rules Inner rules
Preterminal rules Inner rules
Preterminal rules Inner rules
Preterminal rules Inner rules
Preterminal rules Inner rules
Preterminal rules Inner rules
Preterminal rules Inner rules
Preterminal rules Inner rules
Preterminal rules Inner rules
Preterminal rules Inner rules
mid=1
Preterminal rules Inner rules
mid=2
Preterminal rules Inner rules
The sentence is ambiguous for the grammar: (as the grammar overgenerates)
1.0 0.2 1.0 0.4 0.5 0.2 0.3 0.5 1.0 0.6 0.5 0.3 0.3 0.7
27
1.0 0.2 0.4 0.4 0.3 0.5 0.2 1.0 0.2 0.7 0.1 1.0 0.5 0.5 0.6 0.4 0.3 0.7
▪ Chart is represented by a 3d array of floats chart[min][max][label]
▪ It stores probabilities for the most probable subtree with a given signature
▪ chart[0][n][S] will store the probability of the most probable full parse tree
For every C choose C1 , C2 and mid such that is maximal, where T1 and T2 are left and right subtrees.
max min
▪ For each signature we store backpointers to the elements from which it was built
▪ start recovering from [0, n, S]
▪ What backpointers do we store?
▪ For each signature we store backpointers to the elements from which it was built
▪ start recovering from [0, n, S]
▪ What backpointers do we store?
▪ rule ▪ for binary rules, midpoint
▪ Basic pruning (roughly):
▪ For every span (i,j) store only labels which have the probability at most N times smaller than the probability of the most probable label for this span ▪ Check not all rules but only rules yielding subtree labels having non-zero probability
▪ Coarse-to-fine pruning
▪ Parse with a smaller (simpler) grammar, and precompute (posterior) probabilities for each spans, and use only the ones with non-negligible probability from the previous grammar
▪ Intrinsic evaluation:
▪ Automatic: evaluate against annotation provided by human experts (gold standard) according to some predefined measure ▪ Manual: … according to human judgment
▪ Extrinsic evaluation: score syntactic representation by comparing how well a system using this representation performs on some task
▪ E.g., use syntactic representation as input for a semantic analyzer and compare results of the analyzer using syntax predicted by different parsers.
▪ Automatic intrinsic evaluation is used: parsers are evaluated against gold standard by provided by linguists
▪ There is a standard split into the parts:
▪ training set: used for estimation of model parameters ▪ development set: used for tuning the model (initial experiments) ▪ test set: final experiments to compare against previous work
▪ Exact match: percentage of trees predicted correctly ▪ Bracket score: scores how well individual phrases (and their boundaries) are identified
The most standard measure; we will focus on it
▪ The most standard score is bracket score ▪ It regards a tree as a collection of brackets: ▪ The set of brackets predicted by a parser is compared against the set of brackets in the tree annotated by a linguist ▪ Precision, recall and F1 are used as scores
Subtree signatures for CKY
▪ A dependency structure can be defined as a directed graph G, consisting of
▪ a set V of nodes – vertices, words, punctuation, morphemes ▪ a set A of arcs – directed edges, ▪ a linear precedence order < on V (word order).
▪ Labeled graphs
▪ nodes in V are labeled with word forms (and annotation). ▪ arcs in A are labeled with dependency types ▪ is the set of permissible arc labels; ▪ Every arc in A is a triple (i,j,k), representing a dependency from to with label .
▪ Dependency structures explicitly represent
▪ head-dependent relations (directed arcs), ▪ functional categories (arc labels) ▪ possibly some structural categories (parts of speech)
▪ Phrase (aka constituent) structures explicitly represent
▪ phrases (nonterminal nodes), ▪ structural categories (nonterminal labels)
I prefer the morning flight through Denver Я предпочитаю утренний перелет через Денвер
I prefer the morning flight through Denver Я предпочитаю утренний перелет через Денвер Я предпочитаю через Денвер утренний перелет Утренний перелет я предпочитаю через Денвер Перелет утренний я предпочитаю через Денвер Через Денвер я предпочитаю утренний перелет Я через Денвер предпочитаю утренний перелет ...
▪ The clausal relations NSUBJ and DOBJ identify the arguments: the subject and direct object of the predicate cancel ▪ The NMOD, DET, and CASE relations denote modifiers of the nouns flights and Houston.
▪ Syntactic structure is complete (connectedness)
▪ connectedness can be enforced by adding a special root node
▪ Syntactic structure is hierarchical (acyclicity)
▪ there is a unique pass from the root to each vertex
▪ Every word has at most one syntactic head (single-head constraint)
▪ except root that does not have incoming arcs
This makes the dependencies a tree
▪ Projective parse
▪ arcs don’t cross each other ▪ mostly true for English
▪ Non-projective structures are needed to account for
▪ long-distance dependencies ▪ flexible word order
▪ Dependency grammars do not normally assume that all dependency-trees are projective, because some linguistic phenomena can only be achieved using non-projective trees. ▪ But a lot of parsers assume that the output trees are projective ▪ Reasons
▪ conversion from constituency to dependency ▪ the most widely used families of parsing algorithms impose projectivity
▪ The idea is to use the inorder traversal of the tree: <left-child, root, right-child>
▪ This is well defined for binary trees. We need to extend it to n-ary trees.
▪ If we have a projective tree, the inorder traversal will give us the original linear order.
▪ the major English dependency treebanks converted from the WSJ sections of the PTB (Marcus et al., 1993) ▪ OntoNotes project (Hovy et al. 2006, Weischedel et al. 2011) adds conversational telephone speech, weblogs, usenet newsgroups, broadcast, and talk shows in English, Chinese and Arabic ▪ annotated dependency treebanks created for morphologically rich languages such as Czech, Hindi and Finnish, eg Prague Dependency Treebank (Bejcek et al., 2013) ▪ http://universaldependencies.org/
▪ 122 treebanks, 71 languages
▪ Xia and Palmer (2001)
▪ mark the head child of each node in a phrase structure, using the appropriate head rules ▪ make the head of each non-head child depend on the head of the head-child
The parsing problem for a dependency parser is to find the
This amounts to assigning a syntactic head i and a label l to every node j corresponding to a word xj in such a way that the resulting graph is a tree rooted at the node 0
▪ This is equivalent to finding a spanning tree in the complete graph containing all possible arcs
▪ Transition based
▪ greedy choice of local transitions guided by a goodclassifier ▪ deterministic ▪ MaltParser (Nivre et al. 2008)
▪ Graph based
▪ Minimum Spanning Tree for a sentence ▪ McDonald et al.’s (2005) MSTParser ▪ Martins et al.’s (2009) Turbo Parser
▪ greedy discriminative dependency parser ▪ motivated by a stack-based approach called shift-reduce parsing originally developed for analyzing programming languages (Aho & Ullman, 1972). ▪ Nivre 2003
Buffer: unprocessed words Stack: partially processed words Oracle: a classifier
Buffer: unprocessed words Stack: partially processed words Oracle: a classifier
At each step choose: ▪ Shift
Buffer: unprocessed words Stack: partially processed words Oracle: a classifier
At each step choose: ▪ Shift ▪ Reduce left
Buffer: unprocessed words Stack: partially processed words Oracle: a classifier
At each step choose: ▪ Shift ▪ LeftArc or Reduce left ▪ RightArc or Reduce right
Configuration: ▪ Stack, Buffer, Oracle, Set of dependency relations Operations by a classifier at each step: ▪ Shift
▪ remove w1 from the buffer, add it to the top of the stack as s1
▪ LeftArc or Reduce left
▪ assert a head-dependent relation between s1 and s2 ▪ remove s2 from the stack
▪ RightArc or Reduce right
▪ assert a head-dependent relation between s2 and s1 ▪ remove s1 from the stack
Configuration: ▪ Stack, Buffer, Oracle, Set of dependency relations Operations by a classifier at each step: ▪ Shift
▪ remove w1 from the buffer, add it to the top of the stack as s1
▪ LeftArc or Reduce left
▪ assert a head-dependent relation between s1 and s2 ▪ remove s2 from the stack
▪ RightArc or Reduce right
▪ assert a head-dependent relation between s2 and s1 ▪ remove s1 from the stack
Oracle decisions can correspond to unlabeled
▪ Oracle is a supervised classifier that learns a function from the configuration to the next operation ▪ How to extract the training set?
▪ How to extract the training set?
▪ if LeftArc → LeftArc ▪ if RightArc
▪ if s1 dependents have been processed → RightArc
▪ else → Shift
▪ How to extract the training set?
▪ if LeftArc → LeftArc ▪ if RightArc
▪ if s1 dependents have been processed → RightArc
▪ else → Shift
▪ Oracle is a supervised classifier that learns a function from the configuration to the next operation ▪ How to extract the training set?
▪ if LeftArc → LeftArc ▪ if RightArc
▪ if s1 dependents have been processed → RightArc
▪ else → Shift
▪ What features to use?
▪ POS, word-forms, lemmas on the stack/buffer ▪ morphological features for some languages ▪ previous relations ▪ conjunction features (e.g. Zhang&Clark’08; Huang&Sagae’10; Zhang&Nivre’11)
▪ Before 2014: SVMs, ▪ After 2014: Neural Nets
Slides by Danqi Chen & Chris Manning
▪ Features
▪ s1, s2, s3, b1, b2, b3 ▪ leftmost/rightmost children of s1 and s2 ▪ leftmost/rightmost grandchildren of s1 and s2 ▪ POS tags for the above ▪ arc labels for children/grandchildren
▪ LAS - labeled attachment score ▪ UAS - unlabeled attachment score
▪ LEFTARC: Assert a head-dependent relation between s1 and b1; pop the stack. ▪ RIGHTARC: Assert a head-dependent relation between s1 and b1; shift b1 to be s1. ▪ SHIFT: Remove b1 and push it to be s1. ▪ REDUCE: Pop the stack.
▪ Transition based
▪ greedy choice of local transitions guided by a goodclassifier ▪ deterministic ▪ MaltParser (Nivre et al. 2008), Stack LSTM (Dyer et al. 2015)
▪ Graph based
▪ Minimum Spanning Tree for a sentence ▪ non-projective ▪ globally optimized ▪ McDonald et al.’s (2005) MSTParser ▪ Martins et al.’s (2009) Turbo Parser
▪ Start with a fully-connected directed graph ▪ Find a Minimum Spanning Tree
▪ Chu and Liu (1965) and Edmonds (1967) algorithm
edge-factored approaches
Select best incoming edge for each node Subtract its score from all incoming edges Contract nodes if there are cycles Stopping condition Recursively compute MST Expand contracted nodes
▪ Select best incoming edge for each node
▪ Subtract its score from all incoming edges
▪ Contract nodes if there are cycles
▪ Recursively compute MST
▪ Expand contracted nodes
▪ Wordforms, lemmas, and parts of speech of the headword and its dependent. ▪ Corresponding features derived from the contexts before, after and between the words. ▪ Word embeddings. ▪ The dependency relation itself. ▪ The direction of the relation (to the right or left). ▪ The distance from the head to the dependent.
▪ Transition-based
▪ + Fast ▪ + Rich features of context ▪ - Greedy decoding
▪ Graph-based
▪ + Exact or close to exact decoding ▪ - Weaker features
Well-engineered versions of the approaches achieve comparable accuracy (on English), but make different errors
→ combining the strategies results in a substantial boost in performance
Goal: 1) build a generative parser
2) implement coarse-to-fine pruning (extra credit) Evaluation: F1 score Data:
Penn Treebank: 2400 sentences + parsing tree
Submit to Canvas (Assignment 2)
read more than 4 pages), and should be written in the voice and style of a typical computer science conference paper.
(1) your implementation choices (annotation, markovization, ...) (2) report performance using appropriate graphs and tables, and (3) include some of your own investigation/error analysis on the results.
No hard requirements this time,
but following submissions are considered strong:
training: takes 10-15 secs max_length 15: decode 17 secs, 86.01 F1 max_length 40: decode 664 secs, 79.92 F1
There will be a recitation this Friday (Oct 4, 1:30 - 2:20 pm, DH 2302) It will cover 1) CKY parsing + coarse-to-fine pruning recap 2) Implementation tips