A Tabular Method for Dynamic Oracles in Transition-Based Parsing

We develop parsing oracles for two transition-based dependency parsers, including the arc-standard parser, solving a problem that was left open in (Goldberg and Nivre, 2013). We experimentally show that using these oracles during training yields superior parsing accuracies on many languages.


Introduction
Greedy transition-based dependency parsers (Nivre, 2008) incrementally process an input sentence from left to right. These parsers are very fast and provide competitive parsing accuracies (Nivre et al., 2007). However, greedy transition-based parsers still fall behind search-based parsers (Zhang and Clark, 2008;Huang and Sagae, 2010) with respect to accuracy.
The training of transition-based parsers relies on a component called the parsing oracle, which maps parser configurations to optimal transitions with respect to a gold tree. A discriminative model is then trained to simulate the oracle's behavior. A parsing oracle is deterministic if it returns a single canonical transition. Furthermore, an oracle is partial if it is defined only for configurations that can reach the gold tree, that is, configurations representing parsing histories with no mistake. Oracles that are both deterministic and partial are called static. Traditionally, only static oracles have been exploited in training of transition-based parsers.
Recently, Goldberg and Nivre (2012; showed that the accuracy of greedy parsers can be substantially improved without affecting their parsing speed. This improvement relies on the introduction of novel oracles that are nondeterministic and complete. An oracle is nondeterministic if it returns the set of all transitions that are optimal with respect to the gold tree, and it is complete if it is well-defined and correct for every configuration that is reachable by the parser. Oracles that are both nondeterministic and complete are called dynamic. Goldberg and Nivre (2013) develop dynamic oracles for several transition-based parsers. The construction of these oracles is based on a property of transition-based parsers that they call arc decomposition. They also prove that the popular arc-standard system (Nivre, 2004) is not arc-decomposable, and they leave as an open research question the construction of a dynamic oracle for the arc-standard system. In this article, we develop one such oracle ( §4) and prove its correctness ( §5).
An extension to the arc-standard parser was presented by Sartorio et al. (2013), which relaxes the bottom-up construction order and allows mixing of bottom-up and top-down strategies. This parser, called here the LR-spine parser, achieves state-ofthe-art results for greedy parsing. Like the arc-standard system, the LR-spine parser is not arc-decomposable, and a dynamic oracle for this system was not known. We extend our oracle for the arc-standard system to work for the LR-spine system as well ( §6).
The dynamic oracles developed by Goldberg and Nivre (2013) for arc-decomposable systems are based on local properties of computations. In contrast, our novel dynamic oracle algorithms rely on arguably more complex structural properties of computations, which are computed through dynamic programming. This leaves open the question of whether a machine-learning model can learn to effectively simulate such complex processes: will the benefit of training with the dynamic oracle carry over to the arc-standard and LR-spine systems? We show experimentally that this is indeed the case ( §8), and that using the training-with-exploration method of (Goldberg and Nivre, 2013) with our dynamic programming based oracles yields superior parsing accuracies on many languages.

Arc-Standard Parser
In this section we introduce the arc-standard parser of Nivre (2004), which is the model that we use in this article. To keep the notation at a simple level, we only discuss the unlabeled version of the parser; however, a labeled extension is used in §8 for our experiments.

Preliminaries and Notation
The set of non-negative integers is denoted as N 0 . For i, j ∈ N 0 with i ≤ j, we write [i, j] to denote the set {i, i + 1, . . . , j}. When i > j, [i, j] denotes the empty set.
We represent an input sentence as a string w = w 0 · · · w n , n ∈ N 0 , where token w 0 is a special root symbol, and each w i with i ∈ [1, n] is a lexical token. For i, j ∈ [0, n] with i ≤ j, we write w[i, j] to denote the substring w i w i+1 · · · w j of w.
We write i → j to denote a grammatical dependency of some unspecified type between lexical tokens w i and w j , where w i is the head and w j is the dependent. A dependency tree for w is a directed, ordered tree t = (V w , A), such that V w = [0, n] is the set of nodes, A ⊆ V w × V w is the set of arcs, and node 0 is the root. Arc (i, j) encodes a dependency i → j, and we will often use the latter notation to denote arcs.

Transition-Based Dependency Parsing
We assume the reader is familiar with the formal framework of transition-based dependency parsing originally introduced by Nivre (2003); see Nivre (2008) for an introduction. We only summarize here our notation.
Transition-based dependency parsers use a stack data structure, where each stack element is associated with a tree spanning (generating) some substring of the input w. The parser processes the input string incrementally, from left to right, applying at each step a transition that updates the stack and/or consumes one token from the input. Transitions may also construct new dependencies, which are added to the current configuration of the parser.
We represent the stack data structure as an ordered sequence σ = [σ d , . . . , σ 1 ], d ∈ N 0 , of nodes σ i ∈ V w , with the topmost element placed at the right. When d = 0, we have the empty stack σ = []. Sometimes we use the vertical bar to denote the append operator for σ, and write σ = σ |σ 1 to indicate that σ 1 is the topmost element of σ.
The parser also uses a buffer to store the portion of the input string still to be processed. We represent the buffer as an ordered sequence β = [i, . . . , n] of nodes from V w , with i the first element of the buffer. In this way β always encodes a (non-necessarily proper) suffix of w. We denote the empty buffer as β = []. Sometimes we use the vertical bar to denote the append operator for β, and write β = i|β to indicate that i is the first token of β; consequently, we have β = [i + 1, . . . , n].
When processing w, the parser reaches several states, technically called configurations. A configuration of the parser relative to w is a triple c = (σ, β, A), where σ and β are a stack and a buffer, respectively, and A ⊆ V w × V w is a set of arcs. The initial configuration for w is ([], [0, . . . , n], ∅). For the purpose of this article, a configuration is final if it has the form ([0], [], A), and in a final configuration arc set A always defines a dependency tree for w.
The core of a transition-based parser is the set of its transitions, which are specific to each family of parsers. A transition is a binary relation defined over the set of configurations of the parser. We use symbol to denote the union of all transition relations of a parser.
A computation of the parser on w is a sequence c 0 , . . . , c m , m ∈ N 0 , of configurations (defined relative to w) such that c i−1 c i for each i ∈ [1, m]. We also use the reflexive and transitive closure relation * to represent computations. A computation is called complete whenever c 0 is initial and c m is final. In this way, a complete computation is uniquely associated with a dependency tree for w.

Arc-Standard Parser
The arc-standard model uses the three types of transitions formally specified in Figure 1 (σ, i|β, A) sh (σ|i, β, A) • Shift (sh) removes the first node in the buffer and pushes it into the stack; • Left-Arc (la) creates a new arc with the topmost node on the stack as the head and the secondtopmost node as the dependent, and removes the second-topmost node from the stack; • Right-Arc (ra) is symmetric to la in that it creates an arc with the second-topmost node as the head and the topmost node as the dependent, and removes the topmost node.
Notation We sometimes use the functional notation for a transition τ ∈ {sh, la, ra}, and write τ (c) = c in place of c τ c . Naturally, sh applies only when the buffer is not empty, and la,ra require two elements on the stack. We denote by valid(c) the set of valid transitions in a given configuration.

Arc Decomposition
Goldberg and Nivre (2013) show how to derive dynamic oracles for any transition-based parser which has the arc decomposition property, defined below. They also show that the arc-standard parser is not arc-decomposable. For a configuration c, we write A c to denote the associated set of arcs. A transition-based parser is arc-decomposable if, for every configuration c and for every set of arcs A that can be extended to a projective tree, we have In words, if each arc in A is individually derivable from c, then the set A in its entirety can be derived from c as well. The arc decomposition property is useful for deriving dynamic oracles because it is relatively easy to investigate derivability for single arcs and then, using this property, draw conclusions about the number of gold-arcs that are simultaneously derivable from the given configuration.
Unfortunately, the arc-standard parser is not arcdecomposable. To see why, consider a configuration with stack σ = [i, j, k]. Consider also arc set A = {(i, j), (i, k)}. The arc (i, j) can be derived through the transition sequence ra, ra, and the arc (i, k) can be derived through the alternative transition sequence la, ra. Yet, it is easy to see that a configuration containing both arcs cannot be reached.
As we cannot rely on the arc decomposition property, in order to derive a dynamic oracle for the arcstandard model we need to develop more sophisticated techniques which take into account the interaction among the applied transitions.

Configuration Loss and Dynamic Oracles
We aim to derive a dynamic oracle for the arc-standard (and related) system. This is a function that takes a configuration c and a gold tree t G and returns a set of transitions that are "optimal" for c with respect to t G . As already mentioned in the introduction, a dynamic oracle can be used to improve training of greedy transition-based parsers. In this section we provide a formal definition for a dynamic oracle.
Let t 1 and t 2 be two dependency trees over the same string w, with arc sets A 1 and A 2 , respectively. We define the loss of t 1 with respect to t 2 as (1) Note that L(t 1 , t 2 ) = L(t 2 , t 1 ), since |A 1 | = |A 2 |. Furthermore L(t 1 , t 2 ) = 0 if and only if t 1 and t 2 are the same tree.
Let c be a configuration of our parser relative to input string w. We write D(c) to denote the set of all dependency trees that can be obtained in a computation of the form c * c f , where c f is some final configuration. We extend the loss function in (1) to configurations by letting Assume some reference (desired) dependency tree t G for w, which we call the gold tree. Quantity L(c, t G ) can be used to compute a dynamic oracle relating a parser configuration c to a set of optimal actions by setting We therefore need to develop an algorithm for computing (2). We will do this first for the arc-standard parser, and then for an extension of this model.

Notation
We also apply the loss function L(t, t G ) in (1) when t is a dependency tree for a substring of w. In this case the nodes of t are a subset of the nodes of t G , and L(t, t G ) provides a count of the nodes of t that are assigned a wrong head node, when t G is considered as the reference tree.

Main Algorithm
Throughout this section we assume an arc-standard parser. Our algorithm takes as input a projective gold tree t G and a configuration c = (σ L , β, A). We call σ L the left stack, in contrast with a right stack whose construction is specified below.

Basic Idea
The algorithm consists of two steps. Informally, in the first step we compute the largest subtrees, called here tree fragments, of the gold tree t G that have their span entirely included in the buffer β. The root nodes of these tree fragments are then arranged into a stack data structure, according to the order in which they appear in β and with the leftmost root in β being the topmost element of the stack. We call this structure the right stack σ R . Intuitively, σ R can be viewed as the result of pre-computing β by applying all sequences of transitions that match t G and that can be performed independently of the stack in the input configuration c, that is, σ L . In the second step of the algorithm we use dynamic programming techniques to simulate all computations of the arc-standard parser starting in a configuration with stack σ L and with a buffer consisting of σ R , with the topmost token of σ R being the first token of the buffer. As we will see later, the search space defined by these computations includes the dependency trees for w that are reachable from the input configuration c and that have minimum loss. We then perform a Viterbi search to pick up such value.
The second step is very similar to standard implementations of the CKY parser for context-free grammars (Hopcroft and Ullman, 1979), running on an input string obtained as the concatenation of σ L and σ R . The main difference is that we restrict ourselves to parse only those constituents in σ L σ R that dominate the topmost element of σ L (the rightmost ele-ment, if σ L is viewed as a string). In this way, we account for the additional constraint that we visit only those configurations of the arc-standard parser that can be reached from the input configuration c. For instance, this excludes the reduction of two nodes in σ L that are not at the two topmost positions. This would also exclude the reduction of two nodes in σ R : this is correct, since the associated tree fragments have been chosen as the largest such fragments in β.
The above intuitive explanation will be made mathematically precise in §5, where the notion of linear dependency tree is introduced.

Construction of the Right Stack
In the first step we process β and construct a stack σ R , which we call the right stack associated with c and t G . Each node of σ R is the root of a tree t which satisfies the following properties • t is a tree fragment of the gold tree t G having span entirely included in the buffer β; • t is bottom-up complete for t G , meaning that for each node i of t different from t's root, the dependents of i in t G cannot be in σ L ; • t is maximal for t G , meaning that every supertree of t in t G violates the above conditions.
The stack σ R is incrementally constructed by processig β from left to right. Each node i is copied into σ R if it satisfies any of the following conditions • the parent node of i in t G is not in β; • some dependent of i in t G is in σ L or has already been inserted in σ R .
It is not difficult to see that the nodes in σ R are the roots of tree fragments of t G that satisfy the condition of bottom-up completeness and the condition of maximality defined above.

Computation of Configuration Loss
We start with some notation. Let L = |σ L | and Algorithm 1 Computation of the loss function for the arc-standard parser if i < L then expand to the left 6: for each h ∈ ∆ i,j do 7: if j < R then expand to the right 10: for each h ∈ ∆ i,j do 11: Therefore the elements of σ R which have been con- Algorithm 1 uses a two-dimensional array T of size L × R , where each entry T [i, j] is an association list from integers to integers. An entry T [i, j](h) stores the minimum loss among dependency trees rooted at h that can be obtained by running the parser on the first i elements of stack σ L and the first j elements of buffer σ R . More precisely, let For each h ∈ ∆ i,j , the entry T [i, j](h) is the minimum loss among all dependency trees defined as above and with root h. We also assume that Algorithm 1 starts at the top-left corner of T , visiting each individual sub-anti-diagonal of T in ascending order, and eventually reaching the bottomright corner of the array. For each entry T [i, j], the left expansion is considered (lines 5 to 8) by combining with tree fragment σ L [i + 1], through a left or a right arc reduction. This results in the update of T [i + 1, j](h), for each h ∈ ∆ i+1,j , whenever a smaller value of the loss is achieved for a tree with root h. The Kronecker-like function used at line 8 provides the contribution of each single arc to the loss of the current tree. Denoting with A G the set of arcs of t G , such a function is defined as A symmetrical process is implemented for the right expansion of T [i, j] through tree fragment σ R [j + 1] (lines 9 to 12). As we will see in the next section, quantity T [ L , R ](0) is the minimal loss of a tree composed only by arcs that connect nodes in σ L and σ R . By summing the loss of all tree fragments t(σ L [i]) to the loss in T [ L , R ](0), at line 13, we obtain the desired result, since the loss of each tree fragment t(σ R [j]) is zero.

Formal Properties
Throughout this section we let w, t G , σ L , σ R and c = (σ L , β, A) be defined as in §4, but we no longer assume that σ L [1] = σ R [1]. To simplify the presentation, we sometimes identify the tokens in w with the associated nodes in a dependency tree for w.

Linear Trees
Algorithm 1 explores all dependency trees that can be reached by an arc-standard parser from configuration c, under the condition that (i) the nodes in the buffer β are pre-computed into tree fragments and collapsed into their root nodes in the right stack σ R , and (ii) nodes in σ R cannot be combined together prior to their combination with other nodes in the left stack σ L . This set of dependency trees is char- The dependency trees satisfying the restrictions above are captured by the following definition. A linear tree over (σ L , σ R ) is a projective dependency tree t for string σ L σ R satisfying both of the additional conditions reported below. The path from t's root to node σ L [1] is called the spine of t.
• Every node of t not in the spine is a dependent of some node in the spine.
• For each arc i → j in t with j in the spine, no dependent of i can be placed in between i and j within string σ L σ R .
An example of a linear tree is depicted in Figure 2. Observe that the second condition above forbids the reduction of two nodes i and j, in case none of these dominates node σ L [1]. For instance, the ra reduction of nodes i 3 and i 2 would result in arc i 3 → i 2 replacing arc i 1 → i 2 in Figure 2. The new dependency tree is not linear, because of a violation of the second condition above. Similarly, the la reduction of nodes j 3 and j 4 would result in arc j 4 → j 3 replacing arc i 3 → j 3 in Figure 2, again a violation of the second condition above.
Lemma 1 Any tree t ∈ D(c) can be decomposed into trees t(σ L [i]), i ∈ [1, L ], trees t j , j ∈ [1, q] and q ≥ 1, and a linear tree t l over (σ L , σ R,t ), where σ R,t = r 1 · · · r q and each r j is the root node of t j . 2 PROOF (SKETCH) Trees t(σ L [i]) are common to every tree in D(c), since the arc-standard model can not undo the arcs already built in the current configuration c. Similar to the construction in §4.2 of the right stack σ R from t G , we let t j , j ∈ [1, q], be tree fragments of t that cover only nodes associated with the tokens in the buffer β and that are bottomup complete and maximal for t. These trees are indexed according to their left to right order in β. Finally, t l is implicitly defined by all arcs of t that are not in trees t(σ L [i]) and t j . It is not difficult to see that t l has a spine ending with node σ L [1] and is a linear tree over (σ L , σ R,t ).

Correctness
Our proof of correctness for Algorithm 1 is based on a specific dependency tree t * for w, which we define below. Let S L = {σ L [i] | i ∈ [1, L ]} and let D L be the set of nodes that are descendants of some node in S L . Similarly, let S R = {σ R [i] | i ∈ [1, R ]} and let D R be the set of descendants of nodes in S R . Note that sets S L , S R , D L and D R provide a partition of V w . We choose any linear tree t * l over (σ L , σ R ) having root 0, such that L(t * l , t G ) = min t L(t, t G ), where t ranges over all possible linear trees over (σ L , σ R ) with root 0. Tree t * consists of the set of nodes V w and the set of arcs obtained as the union of the set of arcs of t * l and the set of arcs of all trees t(σ L Lemma 2 t * ∈ D(c). 2 PROOF (SKETCH) All tree fragments t(σ L [i]) have already been parsed and are available in the stack associated with c. Each tree fragment t(σ R [j]) can later be constructed in the computation, when a configuration c is reached with the relevant segment of w at the start of the buffer. Note also that parsing of t(σ R [j]) can be done in a way that does not depend on the content of the stack in c .
Finally, the parsing of the tree fragments t(σ R [j]) is interleaved with the construction of the arcs from the linear tree t * l , which are all of the form (i → j) with i, j ∈ (S L ∪ S R ). More precisely, if (i → j) is an arc from t * l , at some point in the computation nodes i and j will become available at the two topmost positions in the stack. This follows from the second condition in the definition of linear tree.
We now show that tree t * is "optimal" within the set D(c) and with respect to t G .

2
PROOF Consider an arbitrary tree t ∈ D(c). Assume the decomposition of t defined in the proof of Lemma 1, through trees t(σ L [i]), i ∈ [1, L ], trees t j , j ∈ [1, q], and linear tree t l over (σ L , σ R,t ).
Recall that an arc i → j denotes an ordered pair (i, j). Let us consider the following partition for the set of arcs of any dependency tree for w In what follows, we compare the losses L(t, t G ) and L(t * , t G ) by separately looking into the contribution to such quantities due to the arcs in A 1 , A 2 and A 3 .
Note that the arcs of trees t(σ L [i]) are all in A 1 , the arcs of trees t(σ R [j]) are all in A 2 , and the arcs of tree t * l are all in A 3 . Since t and t * share trees t(σ L [i]), when restricted to arcs in A 1 quantities L(t, t G ) and L(t * , t G ) are the same. When restricted to arcs in A 2 , quantity L(t * , t G ) is zero, by construction of the trees t(σ R [j]). Thus L(t, t G ) can not be smaller than L(t * , t G ) for these arcs. The difficult part is the comparison of the contribution to L(t, t G ) and L(t * , t G ) due to the arcs in A 3 . We deal with this below.
Let A S,G be the set of all arcs from t G that are also in set (S L × S R ) ∪ (S R × S L ). In words, A S,G represents gold arcs connecting nodes in S L and nodes in S R , in any direction. Within tree t, these arcs can only be found in the t l component, since nodes in S L are all placed within the spine of t l , or else at the left of that spine.
Let us consider an arc (j → i) ∈ A S,G with j ∈ S L and i ∈ S R , and let us assume that (j → i) is in t * l . If token a i does not occur in σ R,t , node i is not in t l and (j → i) can not be an arc of t. We then have that (j → i) contributes one unit to L(t, t G ) but does not contribute to L(t * , t G ). Similarly, let (i → j) ∈ A S,G be such that i ∈ S R and j ∈ S L , and assume that (i → j) is in t * l . If token a i does not occur in σ R,t , arc (i → j) can not be in t. We then have that (i → j) contributes one unit to L(t, t G ) but does not contribute to L(t * , t G ).
Intuitively, the above observations mean that the winning strategy for trees in D(c) is to move nodes from S R as much as possible into the linear tree component t l , in order to make it possible for these nodes to connect to nodes in S L , in any direction. In this case, arcs from A 3 will also move into the linear tree component of a tree in D(c), as it happens in the case of t * . We thus conclude that, when restricted to the set of arcs in A 3 , quantity L(t, t G ) is not smaller than L(t * , t G ), because stack σ R has at least as many tokens corresponding to nodes in S R as stack σ R,t , and because t * l has the minimum loss among all the linear trees over (σ L , σ R ).
Putting all of the above observations together, we conclude that L(t, t G ) can not be smaller than L(t * , t G ). This concludes the proof, since t has been arbitrarily chosen in D(c).
2 PROOF (SKETCH) Algorithm 1 implements a Viterbi search for trees with smallest loss among all linear trees over (σ L , σ R ). Thus T [ L , R ](0) = L(t * l , t G ). The loss of the tree fragments t(σ R [j]) is 0 and the loss of the tree fragments t(σ L [i]) is added at line 13 in the algorithm. Thus the algorithm returns L(t * , t G ), and the statement follows from Lemma 2 and Lemma 3.

Computational Analysis
Following §4.2, the right stack σ R can be easily constructed in time O(n), n the length of the input string. We now analyze Algorithm 1. For each entry T [i, j] and for each h ∈ ∆ i,j , we update T [i, j](h) a number of times bounded by a constant which does not depend on the input. Each updating can be computed in constant time as well. We thus conclude that Algorithm 1 runs in time O( L · R · ( L + R )). Quantity L + R is bounded by n, but in practice the former is significantly smaller. When measured over the sentences in the Penn Treebank, the average value of L + R n is 0.29. In terms of runtime, training is 2.3 times slower when using our oracle instead of a static oracle.

Extension to the LR-Spine Parser
In this section we consider the transition-based parser proposed by Sartorio et al. (2013), called here the LR-spine parser. This parser is not arcdecomposable: the same example reported in §2.4 can be used to show this fact. We therefore extend to the LR-spine parser the algorithm developed in §4.

The LR-Spine Parser
Let t be a dependency tree. The left spine of t is an ordered sequence i 1 , . . . , i p , p ≥ 1, consisting of all nodes in a descending path from the root of t taking the leftmost child node at each step. The right spine of t is defined symmetrically. We use ⊕ to denote sequence concatenation.
In the LR-spine parser each stack element σ[i] denotes a partially built subtree t(σ[i]) and is represented by a pair (ls i , rs i ), with ls i and rs i the left and the right spine, respectively, of t(σ[i]). We write ls i [k] (rs i [k]) to represent the k-th element of ls i (rs i , respectively). We also write r(σ Informally, the LR-spine parser uses the same transition typologies as the arc-standard parser. However, an arc (h → d) can now be created with the head node h chosen from any node in the spine of the involved tree. The transition types of the LRspine parser are defined as follows.
• Shift (sh) removes the first node from the buffer and pushes into the stack a new element, consisting of the left and right spines of the associated tree • Left-Arc k (la k ) creates a new arc h → d from the k-th node in the left spine of the topmost tree in the stack to the head of the second element in the stack. Furthermore, the two topmost stack elements are replaced by a new element associated with the resulting tree where we have set h = ls 1 [k], d = r(σ[2]) and σ la k = ( ls 1 [1], . . . , ls 1 [k] ⊕ ls 2 , rs 1 ).
Note that, at each configuration in the LR-spine parser, there are |ls 1 | possible la k transitions, one for each choice of a node in the left spine of t(σ[1]); similarly, there are |rs 2 | possible ra k transitions, one for each choice of a node in the right spine of t(σ[2]).

Configuration Loss
We only provide an informal description of the extended algorithm here, since it is very similar to the algorithm in §4.
In the first phase we use the procedure of §4.2 for the construction of the right stack σ R , considering only the roots of elements in σ L and ignoring the rest of the spines. The only difference is that each element σ R [j] is now a pair of spines (ls R,j , rs R,j ). Since tree fragment t(σ R [j]) is bottom-up complete (see §4.1), we now restrict the search space in such a way that only the root node r(σ R [j]) can take dependents. This is done by setting ls R,j = rs R,j = r(σ R [j]) for each j ∈ [1, R ]. In order to simplify the presentation we also assume σ R [1] = σ L [1], as done in §4.3.
In the second phase we compute the loss of an input configuration using a two-dimensional array T , defined as in §4.3. However, because of the way transitions are defined in the LR-spine parser, we now need to distinguish tree fragments not only on the basis of their roots, but also on the basis of their left and right spines. Accordingly, we define each entry T [i, j] as an association list with keys of the form (ls, rs). More specifically, T [i, j](ls, rs) is the minimum loss of a tree with left and right spines ls and rs, respectively, that can be obtained by running the parser on the first i elements of stack σ L and the first j elements of buffer σ R .
We follow the main idea of Algorithm 1 and expand each tree in T [i, j] at its left side, by combining with tree fragment t(σ L [i + 1]), and at its right side, by combining with tree fragment t(σ R [j + 1]).
Tree combination deserves some more detailed discussion, reported below.
We consider the combination of a tree t a from T [i, j] and tree t(σ L [i + 1]) by means of a left-arc transition. All other cases are treated symmetrically. Let (ls a , rs a ) be the spine pair of t a , so that the loss of t a is stored in T [i, j](ls a , rs a ). Let also (ls b , rs b ) be the spine pair of t(σ L [i + 1]). In case there exists a gold arc in t G connecting a node from ls a to r(σ L [i + 1]), we choose the transition la k , k ∈ [1, |ls a |], that creates such arc. In case such gold arc does not exists, we choose the transition la k with the maximum possible value of k, that is, k = |ls a |. We therefore explore only one of the several possible ways of combining these two trees by means of a left-arc transition.
We remark that the above strategy is safe. In fact, in case the gold arc exists, no other gold arc can ever involve the nodes of ls a eliminated by la k (see the definition in §6.1), because arcs can not cross each other. In case the gold arc does not exist, our choice of k = |ls a | guarantees that we do not eliminate any element from ls a .
Once a transition la k is chosen, as described above, the reduction is performed and the spine pair (ls, rs) for the resulting tree is computed from (ls a , rs a ) and (ls b , rs b ), as defined in §6.1. At the same time, the loss of the resulting tree is computed, on the basis of the loss T [i, j](ls a , rs a ), the loss of tree t(σ L [i + 1]), and a Kronecker-like function defined below. This loss is then used to update T [i + 1, j](ls, rs).
Let t a and t b be two trees that must be combined in such a way that t b becomes the dependent of some node in one of the two spines of t a . Let also p a = (ls a , rs a ) and p b = (ls b , rs b ) be spine pairs for t a and t b , respectively. Recall that A G is the set of arcs of t G . The new Kronecker-like function for the computation of the loss is defined as ) ∈ A G ]; 1, otherwise.

Efficiency Improvement
The algorithm in §6.2 has an exponential behaviour. To see why, consider trees in T [i, j]. These trees are produced by the combination of trees in T [i − 1, j] with tree t(σ L [i]), or by the combination of trees in T [i, j − 1] with tree t(σ R [j]). Since each combination involves either a left-arc or a right-arc transition, we obtain a recursive relation that resolves into a number of trees in T [i, j] bounded by 4 i+j−2 .
We introduce now two restrictions to the search space of our extended algorithm that result in a huge computational saving. For a spine s, we write N (s) to denote the set of all nodes in s. We also let ∆ i,j be the set of all pairs (ls, rs) such that T [i, j](ls, rs) = +∞. The first restriction above reduces the size of a spine by eliminating a node if it is irrelevant for the computation of the loss of the associated tree. The second restriction eliminates a tree t a if there is a tree t b with smaller loss than t a , such that in the computations of the parser t b provides exactly the same context as t a . It is not difficult to see that the above restrictions do not affect the correctness of the algorithm, since they always leave in our search space some tree that has optimal loss. A mathematical analysis of the computational complexity of the extended algorithm is quite involved. In Figure 3 while not FINAL(c) do 7: if τ p ∈ oracle(c, t G ) then 10: oracle is only about 8 times slower than training with the oracle of Sartorio et al. (2013) without exploring incorrect configurations.

Training
We follow the training procedure suggested by Goldberg and Nivre (2013), as described in Algorithm 2. The algorithm performs online learning using the averaged perceptron algorithm. A weight vector w (initialized to 0) is used to score the valid transitions in each configuration based on a feature representation φ, and the highest scoring transition τ p is predicted. If the predicted transition is not optimal according to the oracle, the weights w are updated away from the predicted transition and to-wards the highest scoring oracle transition τ o . The parser then moves to the next configuration, by taking either the predicted or the oracle transition. In the "error exploration" mode (EXPLORE is true), the parser follows the predicted transition, and otherwise the parser follows the oracle transition. Note that the error exploration mode requires the completeness property of a dynamic oracle.
We consider three training conditions: static, in which the oracle is deterministic (returning a single canonical transition for each configuration) and no error exploration is performed; nondet, in which we use a nondeterministic partial oracle (Sartorio et al., 2013), but do not perform error exploration; and explore in which we use the dynamic oracle and perform error exploration. The static setup mirrors the way greedy parsers are traditionally trained. The nondet setup allows the training procedure to choose which transition to take in case of spurious ambiguities. The explore setup increases the configuration space explored by the parser during training, by exposing the training procedure to non-optimal configurations that are likely to occur during parsing, together with the optimal transitions to take in these configurations. It was shown by Goldberg and Nivre (2012; that the nondet setup outperforms the static setup, and that the explore setup outperforms the nondet setup.

Experimental Evaluation
Datasets Performance evaluation is carried out on CoNLL 2007 multilingual dataset, as well as on the Penn Treebank (PTB) (Marcus et al., 1993) converted to Stanford basic dependencies (De Marneffe et al., 2006). For the CoNLL datasets we use gold part-of-speech tags, while for the PTB we use automatically assigned tags. As usual, the PTB parser is trained on sections 2-21 and tested on section 23.
Setup We train labeled versions of the arc-standard (std) and LR-spine (lrs) parsers under the static, nondet and explore setups, as defined in §7. In the nondet setup we use a nondeterministic partial oracle and in the explore setup we use the nondeterministic complete oracles we present in this paper. In the static setup we resolve oracle ambiguities and choose a canonic transition sequence by attaching arcs as soon as possible. In the explore setup, Table 1: Scores on the CoNLL 2007 dataset (including punctuation, gold parts of speech) and on Penn Tree Bank (excluding punctuation, predicted parts of speech). Label 'std' refers to the arc-standard parser, and 'lrs' refers to the LR-spine parser. Each number is an average over 5 runs with different randomization seeds. from the first round of training onward, we always follow the predicted transition (EXPLORE is true). For all languages, we deal with non-projectivity by skipping the non-projective sentences during training but not during test. For each parsing system, we use the same feature templates across all languages. 1 The arc-standard models are trained for 15 iterations and the LR-spine models for 30 iterations, after which all the models seem to have converged.

Results
In Table 1 we report the labeled (LAS) and unlabeled (UAS) attachment scores. As expected, the LR-spine parsers outperform the arc-standard parsers trained under the same setup. Training with the dynamic oracles is also beneficial: despite the arguable complexity of our proposed oracles, the trends are consistent with those reported by Goldberg and Nivre (2012;. For the arc-standard model we observe that the move from a static to a nondeterministic oracle during training improves the accuracy for most of languages. Making use of the completeness of the dynamic oracle and moving to the error exploring setup further improve results. The only exceptions are Basque, that has a small dataset with more than 20% of non-projective sentences, and Chinese. For Chinese we observe a reduction of accuracy in the nondet setup, but an increase in the explore setup.
For the LR-spine parser we observe a practically constant increase of performance by moving from 1 Our complete code, together with the description of the feature templates, is available on the second author's homepage. the static to the nondeterministic and then to the error exploring setups.

Conclusions
We presented dynamic oracles, based on dynamic programming, for the arc-standard and the LRspine parsers. Empirical evaluation on 10 languages showed that, despite the apparent complexity of the oracle calculation procedure, the oracles are still learnable, in the sense that using these oracles in the error exploration training algorithm presented in (Goldberg and Nivre, 2012) considerably improves the accuracy of the trained parsers.
Our algorithm computes a dynamic oracle using dynamic programming to explore a forest of dependency trees that can be reached from a given parser configuration. For the arc-standard parser, the computation takes cubic time in the size of the largest of the left and right input stacks. Dynamic programming for the simulation of arc-standard parsers have been proposed by Kuhlmann et al. (2011). That algorithm could be adapted to compute minimum loss for a given configuration, but the running time is O(n 4 ), n the size of the input string: besides being asymptotically slower by one order of magnitude, in practice n is also larger than the stack size above.