Cube Summing, Approximate Inference with Non-Local Features, and Dynamic Programming without Semirings Kevin Gimpel and Noah A. Smith Language Technologies Institute Carnegie Mellon University Pittsburgh, PA 15213, USA {kgimpel,nasmith}@cs.cmu.edu Abstract We introduce cube summing, a technique that permits dynamic programming algorithms for summing over structures (like the forward and inside algorithms) to be extended with non-local features that violate the classical structural independence assumptions. It is inspired by cube pruning (Chiang, 2007; Huang and Chiang, 2007) in its computation of non-local features dynamically using scored k-best lists, but also maintains additional residual quantities used in calculating approximate marginals. When restricted to local features, cube summing reduces to a novel semiring (k-best+residual) that generalizes many of the semirings of Goodman (1999). When non-local features are included, cube summing does not reduce to any semiring, but is compatible with generic techniques for solving dynamic programming equations. features, but leaves open the question of how the feature weights or probabilities are learned. Meanwhile, some learning algorithms, like maximum likelihood for conditional log-linear models (Lafferty et al., 2001), unsupervised models (Pereira and Schabes, 1992), and models with hidden variables (Koo and Collins, 2005; Wang et al., 2007; Blunsom et al., 2008), require summing over the scores of many structures to calculate marginals. We first review the semiring-weighted logic programming view of dynamic programming algorithms (Shieber et al., 1995) and identify an intuitive property of a program called proof locality that follows from feature locality in the underlying probability model (§2). We then provide an analysis of cube pruning as an approximation to the intractable problem of exact optimization over structures with non-local features and show how the use of non-local features with k-best lists breaks certain semiring properties (§3). The primary contribution of this paper is a novel technique-- cube summing--for approximate summing over discrete structures with non-local features, which we relate to cube pruning (§4). We discuss implementation (§5) and show that cube summing becomes exact and expressible as a semiring when restricted to local features; this semiring generalizes many commonly-used semirings in dynamic programming (§6). 1 Introduction Probabilistic NLP researchers frequently make independence assumptions to keep inference algorithms tractable. Doing so limits the features that are available to our models, requiring features to be structurally local. Yet many problems in NLP--machine translation, parsing, named-entity recognition, and others--have benefited from the addition of non-local features that break classical independence assumptions. Doing so has required algorithms for approximate inference. Recently cube pruning (Chiang, 2007; Huang and Chiang, 2007) was proposed as a way to leverage existing dynamic programming algorithms that find optimal-scoring derivations or structures when only local features are involved. Cube pruning permits approximate decoding with non-local 2 Background In this section, we discuss dynamic programming algorithms as semiring-weighted logic programs. We then review the definition of semirings and important examples. We discuss the relationship between locally-factored structure scores and proofs in logic programs. 2.1 Dynamic Programming Many algorithms in NLP involve dynamic programming (e.g., the Viterbi, forward-backward, Proceedings of the 12th Conference of the European Chapter of the ACL, pages 318­326, Athens, Greece, 30 March ­ 3 April 2009. c 2009 Association for Computational Linguistics 318 probabilistic Earley's, and minimum edit distance algorithms). Dynamic programming (DP) involves solving certain kinds of recursive equations with shared substructure and a topological ordering of the variables. Shieber et al. (1995) showed a connection between DP (specifically, as used in parsing) and logic programming, and Goodman (1999) augmented such logic programs with semiring weights, giving an algebraic explanation for the intuitive connections among classes of algorithms with the same logical structure. For example, in Goodman's framework, the forward algorithm and the Viterbi algorithm are comprised of the same logic program with different semirings. Goodman defined other semirings, including ones we will use here. This formal framework was the basis for the Dyna programming language, which permits a declarative specification of the logic program and compiles it into an efficient, agendabased, bottom-up procedure (Eisner et al., 2005). For our purposes, a DP consists of a set of recursive equations over a set of indexed variables. For example, the probabilistic CKY algorithm (run on sentence w1 w2 ...wn ) is written as CX,i-1,i = pXwi CX,i,k = max Y,ZN;j{i+1,...,k-1} Semirings define these values and define two operators over them, called "aggregation" (max in Eq. 1) and "combination" (× in Eq. 1). Goodman and Eisner et al. assumed that the values of the variables are in a semiring, and that the equations are defined solely in terms of the two semiring operations. We will often refer to the "probability" of a proof, by which we mean a nonnegative R-valued score defined by the semantics of the dynamic program variables; it may not be a normalized probability. 2.2 Semirings (1) pXY Z × CY,i,j × CZ,j,k goal = CS,0,n where N is the nonterminal set and S N is the start symbol. Each CX,i,j variable corresponds to the chart value (probability of the most likely subtree) of an X-constituent spanning the substring wi+1 ...wj . goal is a special variable of greatest interest, though solving for goal correctly may (in general, but not in this example) require solving for all the other values. We will use the term "index" to refer to the subscript values on variables (X, i, j on CX,i,j ). Where convenient, we will make use of Shieber et al.'s logic programming view of dynamic programming. In this view, each variable (e.g., CX,i,j in Eq. 1) corresponds to the value of a "theorem," the constants in the equations (e.g., pXY Z in Eq. 1) correspond to the values of "axioms," and the DP defines quantities corresponding to weighted "proofs" of the goal theorem (e.g., finding the maximum-valued proof, or aggregating proof values). The value of a proof is a combination of the values of the axioms it starts with. A semiring is a tuple A, , , 0, 1 , in which A is a set, : A × A A is the aggregation operation, : A × A A is the combination operation, 0 is the additive identity element (a A, a 0 = a), and 1 is the multiplicative identity element (a A, a 1 = a). A semiring requires to be associative and commutative, and to be associative and to distribute over . Finally, we require a 0 = 0 a = 0 for all a A.1 Examples include the inside semiring, R0 , +, ×, 0, 1 , and the Viterbi semiring, R0 , max, ×, 0, 1 . The former sums the probabilities of all proofs of each theorem. The latter (used in Eq. 1) calculates the probability of the most probable proof of each theorem. Two more examples follow. Viterbi proof semiring. We typically need to recover the steps in the most probable proof in addition to its probability. This is often done using backpointers, but can also be accomplished by representing the most probable proof for each theorem in its entirety as part of the semiring value (Goodman, 1999). For generality, we define a proof as a string that is constructed from strings associated with axioms, but the particular form of a proof is problem-dependent. The "Viterbi proof" semiring includes the probability of the most probable proof and the proof itself. Letting L be the proof language on some symbol set , this semiring is defined on the set R0 × L with 0 element 0, and 1 element 1, . For two values u1 , U1 and u2 , U2 , the aggregation operator returns max(u1 , u2 ), Uargmaxi{1,2} ui . 1 When cycles are permitted, i.e., where the value of one variable depends on itself, infinite sums can be involved. We must ensure that these infinite sums are well defined under the semiring. So-called complete semirings satisfy additional conditions to handle infinite sums, but for simplicity we will restrict our attention to DPs that do not involve cycles. 319 Semiring inside Viterbi Viterbi proof k-best proof A R0 R0 R0 × L (R0 × L)k Aggregation () u1 + u2 max(u1 , u2 ) max(u1 , u2 ), Uargmaxi{1,2} ui max-k(u1 u2 ) Combination () u1 u2 u1 u2 u1 u2 , U1 .U2 max-k(u1 u2 ) 0 0 0 0, 1 1 1 1, { 1, } Table 1: Commonly used semirings. An element in the Viterbi proof semiring is denoted u1 , U1 , where u1 is the probability of proof U1 . The max-k function returns a sorted list of the top-k proofs from a set. The function performs a cross-product on two k-best proof lists (Eq. 2). The combination operator returns u1 u2 , U1 .U2 , where U1 .U2 denotes the string concatenation of U1 and U2 .2 k-best proof semiring. The "k-best proof" semiring computes the values and proof strings of the k most-probable proofs for each theorem. The set is (R0 × L)k , i.e., sequences (up to length k) of sorted probability/proof pairs. The aggregation operator uses max-k, which chooses the k highest-scoring proofs from its argument (a set of scored proofs) and sorts them in decreasing order. To define the combination operator , we require a cross-product that pairs probabilities and proofs from two k-best lists. We call this , defined on two semiring values u = u1 , U1 , ..., uk , Uk and v = v1 , V1 , ..., vk , Vk by: u v = { ui vj , Ui .Vj | i, j {1, ..., k}} (2) Then, u v = max-k(u v). This is similar to the k-best semiring defined by Goodman (1999). These semirings are summarized in Table 1. 2.3 Features and Inference y Y for a given input x X: ^ y (x) = argmaxyY ^ M hm (x,y) m=1 m (4) The second is the summing problem, which marginalizes the proof probabilities (without normalization): s(x) = yY M hm (x,y) m=1 m (5) As defined, the feature functions hm can depend on arbitrary parts of the input axiom set x and the entire output proof y. 2.4 Proof and Feature Locality Let X be the space of inputs to our logic program, i.e., x X is a set of axioms. Let L denote the proof language and let Y L denote the set of proof strings that constitute full proofs, i.e., proofs of the special goal theorem. We assume an exponential probabilistic model such that p(y | x) hm (x,y) M m=1 m (3) where each m 0 is a parameter of the model and each hm is a feature function. There is a bijection between Y and the space of discrete structures that our model predicts. Given such a model, DP is helpful for solving two kinds of inference problems. The first problem, decoding, is to find the highest scoring proof We assume for simplicity that the best proof will never be a tie among more than one proof. Goodman (1999) handles this situation more carefully, though our version is more likely to be used in practice for both the Viterbi proof and k-best proof semirings. 2 An important characteristic of problems suited for DP is that the global calculation (i.e., the value of goal ) depend only on local factored parts. In DP equations, this means that each equation connects a relatively small number of indexed variables related through a relatively small number of indices. In the logic programming formulation, it means that each step of the proof depends only on the theorems being used at that step, not the full proofs of those theorems. We call this property proof locality. In the statistical modeling view of Eq. 3, classical DP requires that the probability model make strong Markovian conditional independence assumptions (e.g., in HMMs, St-1 St+1 | St ); in exponential families over discrete structures, this corresponds to feature locality. For a particular proof y of goal consisting of t intermediate theorems, we define a set of proof strings i L for i {1, ..., t}, where i corresponds to the proof of the ith theorem.3 We can break the computation of feature function hm into a summation over terms corresponding to each i : hm (x, y) = t i=1 fm (x, i ) (6) This is simply a way of noting that feature functions "fire" incrementally at specific points in the The theorem indexing scheme might be based on a topological ordering given by the proof structure, but is not important for our purposes. 3 320 proof, normally at the first opportunity. Any feature function can be expressed this way. For local features, we can go farther; we define a function top( ) that returns the proof string corresponding to the antecedents and consequent of the last inference step in . Local features have the property: hloc (x, y) m = t i=1 fm (x, top( i )) McDonald and Pereira (2006), in which an exact solution to a related decoding problem is found and then modified to fit the problem of interest. 3 Approximate Decoding (7) Local features only have access to the most recent deductive proof step (though they may "fire" repeatedly in the proof), while non-local features have access to the entire proof up to a given theorem. For both kinds of features, the "f " terms are used within the DP formulation. When taking an inference step to prove theorem i, the value fm (x, i ) M is combined into the calculation m=1 m of that theorem's value, along with the values of the antecedents. Note that typically only a small number of fm are nonzero for theorem i. When non-local hm /fm that depend on arbitrary parts of the proof are involved, the decoding and summing inference problems are NP-hard (they instantiate probabilistic inference in a fully connected graphical model). Sometimes, it is possible to achieve proof locality by adding more indices to the DP variables (for example, consider modifying the bigram HMM Viterbi algorithm for trigram HMMs). This increases the number of variables and hence computational cost. In general, it leads to exponential-time inference in the worst case. There have been many algorithms proposed for approximately solving instances of these decoding and summing problems with non-local features. Some stem from work on graphical models, including loopy belief propagation (Sutton and McCallum, 2004; Smith and Eisner, 2008), Gibbs sampling (Finkel et al., 2005), sequential Monte Carlo methods such as particle filtering (Levy et al., 2008), and variational inference (Jordan et al., 1999; MacKay, 1997; Kurihara and Sato, 2006). Also relevant are stacked learning (Cohen and Carvalho, 2005), interpretable as approximation of non-local feature values (Martins et al., 2008), and M-estimation (Smith et al., 2007), which allows training without inference. Several other approaches used frequently in NLP are approximate methods for decoding only. These include beam search (Lowerre, 1976), cube pruning, which we discuss in §3, integer linear programming (Roth and Yih, 2004), in which arbitrary features can act as constraints on y, and approximate solutions like Cube pruning (Chiang, 2007; Huang and Chiang, 2007) is an approximate technique for decoding (Eq. 4); it is used widely in machine translation. Given proof locality, it is essentially an efficient implementation of the k-best proof semiring. Cube pruning goes farther in that it permits nonlocal features to weigh in on the proof probabilities, at the expense of making the k-best operation approximate. We describe the two approximations cube pruning makes, then propose cube decoding, which removes the second approximation. Cube decoding cannot be represented as a semiring; we propose a more general algebraic structure that accommodates it. 3.1 Approximations in Cube Pruning Cube pruning is an approximate solution to the decoding problem (Eq. 4) in two ways. Approximation 1: k < . Cube pruning uses a finite k for the k-best lists stored in each value. If k = , the algorithm performs exact decoding with non-local features (at obviously formidable expense in combinatorial problems). Approximation 2: lazy computation. Cube pruning exploits the fact that k < to use lazy computation. When combining the k-best proof lists of d theorems' values, cube pruning does not enumerate all k d proofs, apply non-local features to all of them, and then return the top k. Instead, cube pruning uses a more efficient but approximate solution that only calculates the non-local factors on O(k) proofs to obtain the approximate top k. This trick is only approximate if non-local features are involved. Approximation 2 makes it impossible to formulate cube pruning using separate aggregation and combination operations, as the use of lazy computation causes these two operations to effectively be performed simultaneously. To more directly relate our summing algorithm (§4) to cube pruning, we suggest a modified version of cube pruning that does not use lazy computation. We call this algorithm cube decoding. This algorithm can be written down in terms of separate aggregation 321 and combination operations, though we will show it is not a semiring. 3.2 Cube Decoding in place by multiplying in the function result, and returns the modified proof list: g = .g(x, ) u1 g (U1 ), U1 , u2 g (U2 ), U2 , ..., uk g (Uk ), Uk Here, max-k is simply used to re-sort the k-best proof list following function evaluation. The semiring properties fail to hold when introducing non-local features in this way. In particular, cd is not associative when 1 < k < . For example, consider the probabilistic CKY algorithm as above, but using the cube decoding semiring with the non-local feature functions collectively known as "NGramTree" features (Huang, 2008) that score the string of terminals and nonterminals along the path from word j to word j + 1 when two constituents CY,i,j and CZ,j,k are combined. The semiring value associated with such a feature is u = , NGramTree (), 1 (for a specific path ), and we rewrite Eq. 1 as follows (where ranges for summation are omitted for space): CX,i,k = cd pXY Z We formally describe cube decoding, show that it does not instantiate a semiring, then describe a more general algebraic structure that it does instantiate. Consider the set G of non-local feature functions that map X × L R0 .4 Our definitions in §2.2 for the k-best proof semiring can be expanded to accommodate these functions within the semiring value. Recall that values in the k-best proof semiring fall in Ak = (R0 ×L)k . For cube decoding, we use a different set Acd defined as Acd = (R0 × L)k ×G × {0, 1} Ak exec(g, u) = ¯ where the binary variable indicates whether the value contains a k-best list (0, which we call an "ordinary" value) or a non-local feature function in G (1, which we call a "function" value). We denote a value u Acd by u= u1 , U1 , u2 , U2 , ..., uk , Uk , gu , us u ¯ cd CY,i,j cd CZ,j,k cd u where each ui R0 is a probability and each Ui L is a proof string. We use k and k to denote the k-best proof semiring's operators, defined in §2.2. We let g0 be such that g0 ( ) is undefined for all L. For two values u = u, gu , us , v = v, gv , vs Acd , ¯ ¯ cube decoding's aggregation operator is: u cd v = u k v, g0 , 0 if ¬us ¬vs ¯ ¯ (8) The combination operator is not associative since the following will give different answers:5 (pXY Z cd CY,i,j ) cd (CZ,j,k cd u) ((pXY Z cd CY,i,j ) cd CZ,j,k ) cd u (10) (11) Under standard models, only ordinary values will be operands of cd , so cd is undefined when us vs . We define the combination operator cd : u cd v = u k v, g0 , 0 ¯ ¯ max-k(exec(g , u)), g , 0 v ¯ 0 max-k(exec(gu , v)), g0 , 0 ¯ , z.(g (z) × g (z)), 1 u v (9) if ¬us ¬vs , if ¬us vs , if us ¬vs , if us vs . where exec(g, u) executes the function g upon ¯ each proof in the proof list u, modifies the scores ¯ In our setting, gm (x, ) will most commonly be defined fm (x, ) as m in the notation of §2.3. But functions in G could also be used to implement, e.g., hard constraints or other nonlocal score factors. 4 In Eq. 10, the non-local feature function is executed on the k-best proof list for Z, while in Eq. 11, NGramTree is called on the k-best proof list for the X constructed from Y and Z. Furthermore, neither of the above gives the desired result, since we actually wish to expand the full set of k 2 proofs of X and then apply NGramTree to each of them (or a higher-dimensional "cube" if more operands are present) before selecting the k-best. The binary operations above retain only the top k proofs of X in Eq. 11 before applying NGramTree to each of them. We actually would like to redefine combination so that it can operate on arbitrarily-sized sets of values. We can understand cube decoding through an algebraic structure with two operations and , where need not be associative and need not distribute over , and furthermore where and are 5 Distributivity of combination over aggregation fails for related reasons. We omit a full discussion due to space. 322 defined on arbitrarily many operands. We will refer here to such a structure as a generalized semiring.6 To define cd on a set of operands with N ordinary operands and N function operands, we first compute the full O(k N ) cross-product of the ordinary operands, then apply each of the N functions from the remaining operands in turn upon the full N -dimensional "cube," finally calling max-k on the result. 4 Cube Summing We present an approximate solution to the summing problem when non-local features are involved, which we call cube summing. It is an extension of cube decoding, and so we will describe it as a generalized semiring. The key addition is to maintain in each value, in addition to the k-best list of proofs from Ak , a scalar corresponding to the residual probability (possibly unnormalized) of all proofs not among the k-best.7 The k-best proofs are still used for dynamically computing non-local features but the aggregation and combination operations are redefined to update the residual as appropriate. We define the set Acs for cube summing as Acs = R0 × (R0 × L)k × G × {0, 1} A value u Acs is defined as u = u0 , u1 , U1 , u2 , U2 , ..., uk , Uk , gu , us u ¯ where Res returns the "residual" set of scored proofs not in the k-best among its arguments, possibly the empty set. For a set of N +N operands {vi }N {wj }N j=1 i=1 such that vis = 1 (non-local feature functions) and wjs = 1 (ordinary values), the combination operator is shown in Eq. 13 Fig. 1. Note that the case where N = 0 is not needed in this application; an ordinary value will always be included in combination. In the special case of two ordinary operands (where us = vs = 0), Eq. 13 reduces to uv = max-k(¯ v), g0 , 0 u ¯ We define 0 as 0, , g0 , 0 ; an appropriate definition for the combination identity element is less straightforward and of little practical importance; we leave it to future work. If we use this generalized semiring to solve a DP and achieve goal value of u, the approximate sum of all proof probabilities is given by u0 + u . ¯ If all features are local, the approach is exact. With non-local features, the k-best list may not contain the k-best proofs, and the residual score, while including all possible proofs, may not include all of the non-local features in all of those proofs' probabilities. (14) u0 v0 + u0 v + v0 u + Res(¯ v) , ¯ ¯ u ¯ 5 Implementation For a proof list u, we use u to denote the sum ¯ ¯ of all proof scores, i: ui ,Ui ¯ ui . u The aggregation operator over operands {ui }N , all such that uis = 0,8 is defined by: i=1 N i=1 ui = N i=1 ui0 (12) + Res N ¯ i=1 ui N ¯ i=1 ui , max-k , g0 , 0 6 Algebraic structures are typically defined with binary operators only, so we were unable to find a suitable term for this structure in the literature. 7 Blunsom and Osborne (2008) described a related approach to approximate summing using the chart computed during cube pruning, but did not keep track of the residual terms as we do here. 8 We assume that operands ui to cs will never be such that uis = 1 (non-local feature functions). This is reasonable in the widely used log-linear model setting we have adopted, where weights m are factors in a proof's product score. We have so far viewed dynamic programming algorithms in terms of their declarative specifications as semiring-weighted logic programs. Solvers have been proposed by Goodman (1999), by Klein and Manning (2001) using a hypergraph representation, and by Eisner et al. (2005). Because Goodman's and Eisner et al.'s algorithms assume semirings, adapting them for cube summing is non-trivial.9 To generalize Goodman's algorithm, we suggest using the directed-graph data structure known variously as an arithmetic circuit or computation graph.10 Arithmetic circuits have recently drawn interest in the graphical model community as a 9 The bottom-up agenda algorithm in Eisner et al. (2005) might possibly be generalized so that associativity, distributivity, and binary operators are not required (John Blatz, p.c.). 10 This data structure is not specific to any particular set of operations. We have also used it successfully with the inside semiring. 323 N N wj = wb0 BP(S) bB cS\B wc ¯ (13) vi i=1 j=1 ¯ ¯ + Res(exec(gv1 , . . . exec(gvN , w1 · · · wN ) . . .)) , ¯ ¯ max-k(exec(gv1 , . . . exec(gvN , w1 · · · wN ) . . .)), g0 , 0 Figure 1: Combination operation for cube summing, where S = {1, 2, . . . , N } and P(S) is the power set of S excluding . tool for performing probabilistic inference (Darwiche, 2003). In the directed graph, there are vertices corresponding to axioms (these are sinks in the graph), vertices corresponding to theorems, and vertices corresponding to summands in the dynamic programming equations. Directed edges point from each node to the nodes it depends on; vertices depend on vertices, which depend on and axiom vertices. Arithmetic circuits are amenable to automatic differentiation in the reverse mode (Griewank and Corliss, 1991), commonly used in backpropagation algorithms. Importantly, this permits us to calculate the exact gradient of the approximate summation with respect to axiom values, following Eisner et al. (2005). This is desirable when carrying out the optimization problems involved in parameter estimation. Another differentiation technique, implemented within the semiring, is given by Eisner (2002). Cube pruning is based on the k-best algorithms of Huang and Chiang (2005), which save time over generic semiring implementations through lazy computation in both the aggregation and combination operations. Their techniques are not as clearly applicable here, because our goal is to sum over all proofs instead of only finding a small subset of them. If computing non-local features is a computational bottleneck, they can be computed only for the O(k) proofs considered when choosing the best k as in cube pruning. Then, the computational requirements for approximate summing are nearly equivalent to cube pruning, but the approximation is less accurate. k-best + residual or gn l ua sid e er k= 0 inside i (Goodman, 1999) k-best proof 1 k= k= (Baum et al., 1970) (Goodman, 1999) ignore proof (Viterbi, 1967) Viterbi proof (Goodman, 1999) all proof Viterbi Figure 2: Semirings generalized by k-best+residual. ings. Cube pruning reduces to an implementation of the k-best semiring (Goodman, 1998), and cube summing reduces to a novel semiring we call the k-best+residual semiring. Binary instantiations of and can be iteratively reapplied to give the equivalent formulations in Eqs. 12 and 13. We define 0 as 0, and 1 as 1, 1, . The operator is easily shown to be commutative. That is associative follows from associativity of max-k, shown by Goodman (1998). Showing that is associative and that distributes over are less straightforward; proof sketches are provided in Appendix A. The k-best+residual semiring generalizes many semirings previously introduced in the literature; see Fig. 2. 6.2 Variations 6 Semirings Old and New We now consider interesting special cases and variations of cube summing. 6.1 The k-best+residual Semiring When restricted to local features, cube pruning and cube summing can be seen as proper semir- Once we relax requirements about associativity and distributivity and permit aggregation and combination operators to operate on sets, several extensions to cube summing become possible. First, when computing approximate summations with non-local features, we may not always be interested in the best proofs for each item. Since the purpose of summing is often to calculate statistics 324 under a model distribution, we may wish instead to sample from that distribution. We can replace the max-k function with a sample-k function that samples k proofs from the scored list in its argument, possibly using the scores or possibly uniformly at random. This breaks associativity of . We conjecture that this approach can be used to simulate particle filtering for structured models. Another variation is to vary k for different theorems. This might be used to simulate beam search, or to reserve computation for theorems closer to goal , which have more proofs. out immediately. Three more cancel using Eq. 15, leaving: LHS = Res(¯ v) w + Res(max-k(¯ v) w) u ¯ ¯ u ¯ ¯ RHS = u Res(¯ w) + Res(¯ max-k(¯ w)) ¯ v ¯ u v ¯ If LHS = RHS, associativity holds. Using Eq. 15 again, we can rewrite the second term in LHS to obtain LHS = Res(¯ v) w + max-k(¯ v) w u ¯ ¯ u ¯ ¯ - max-k(max-k(¯ v) w) u ¯ ¯ Using Eq. 16 and pulling out the common term w , we have ¯ LHS =( Res(¯ v) + max-k(¯ v) ) w u ¯ u ¯ ¯ - max-k(max-k(¯ v) w) u ¯ ¯ = (¯ v) w - max-k(max-k(¯ v) w) u ¯ ¯ u ¯ ¯ = (¯ v) w - max-k((¯ v) w) u ¯ ¯ u ¯ ¯ The resulting expression is intuitive: the residual of (uv) w is the difference between the sum of all proof scores and the sum of the k-best. RHS can be transformed into this same expression with a similar line of reasoning (and using associativity of ). Therefore, LHS = RHS and is associative. Distributivity. To prove that distributes over , we must show left-distributivity, i.e., that u(vw) = (uv)(u w), and right-distributivity. We show left-distributivity here. As above, we expand the expressions, finding 8 terms on the LHS and 9 on the RHS. Six on each side cancel, leaving: LHS = Res(¯ w) u + Res(¯ max-k(¯ w)) v ¯ ¯ u v ¯ RHS = Res(¯ v) + Res(¯ w) u ¯ u ¯ + Res(max-k(¯ v) max-k(¯ w)) u ¯ u ¯ We can rewrite LHS as: LHS = Res(¯ w) u + u max-k(¯ w) v ¯ ¯ ¯ v ¯ - max-k(¯ max-k(¯ w)) u v ¯ = u ( Res(¯ w) + max-k(¯ w) ) ¯ v ¯ v ¯ - max-k(¯ max-k(¯ w)) u v ¯ = u v w - max-k(¯ (¯ w)) ¯ ¯ ¯ u v ¯ = u v w - max-k((¯ v) (¯ w)) ¯ ¯ ¯ u ¯ u ¯ where the last line follows because distributes over (Goodman, 1998). We now work with the RHS: RHS = Res(¯ v) + Res(¯ w) u ¯ u ¯ + Res(max-k(¯ v) max-k(¯ w)) u ¯ u ¯ = Res(¯ v) + Res(¯ w) u ¯ u ¯ + max-k(¯ v) max-k(¯ w) u ¯ u ¯ - max-k(max-k(¯ v) max-k(¯ w)) u ¯ u ¯ Since max-k(¯ v) and max-k(¯ w) are disjoint (we u ¯ u ¯ assume no duplicates; i.e., two different theorems cannot have exactly the same proof), the third term becomes max-k(¯ v) + max-k(¯ w) and we have u ¯ u ¯ = u v + u w ¯ ¯ ¯ ¯ - max-k(max-k(¯ v) max-k(¯ w)) u ¯ u ¯ = u v + u w ¯ ¯ ¯ ¯ - max-k((¯ v) (¯ w)) u ¯ u ¯ = u v w - max-k((¯ v) (¯ w)) . ¯ ¯ ¯ u ¯ u ¯ 7 Conclusion This paper has drawn a connection between cube pruning, a popular technique for approximately solving decoding problems, and the semiringweighted logic programming view of dynamic programming. We have introduced a generalization called cube summing, to be used for solving summing problems, and have argued that cube pruning and cube summing are both semirings that can be used generically, as long as the underlying probability models only include local features. With non-local features, cube pruning and cube summing can be used for approximate decoding and summing, respectively, and although they no longer correspond to semirings, generic algorithms can still be used. Acknowledgments We thank three anonymous EACL reviewers, John Blatz, Pedro Domingos, Jason Eisner, Joshua Goodman, and members of the ARK group for helpful comments and feedback that improved this paper. This research was supported by NSF IIS-0836431 and an IBM faculty award. A k-best+residual is a Semiring In showing that k-best+residual is a semiring, we will restrict our attention to the computation of the residuals. The computation over proof lists is identical to that performed in the k-best proof semiring, which was shown to be a semiring by Goodman (1998). We sketch the proofs that is associative and that distributes over ; associativity of is straightforward. a a P For a proof list ¯, ¯ denotes the sum of proof scores, i: ai ,Ai ¯ ai . Note that: a Res(¯) + max-k(¯) = ¯ a a a , , , , ,¯ b, = ¯ ,¯ , ¯ a a b (15) (16) Associativity. Given three semiring values u, v, and w, we need to show that (uv)w = u(vw). After expanding the expressions for the residuals using Eq. 14, there are 10 terms on each side, five of which are identical and cancel 325 References L. E. Baum, T. Petrie, G. Soules, and N. Weiss. 1970. A maximization technique occurring in the statistical analysis of probabilistic functions of Markov chains. Annals of Mathematical Statistics, 41(1). P. Blunsom and M. Osborne. 2008. Probabilistic inference for machine translation. In Proc. of EMNLP. P. Blunsom, T. Cohn, and M. Osborne. 2008. A discriminative latent variable model for statistical machine translation. In Proc. of ACL. D. Chiang. 2007. Hierarchical phrase-based translation. Computational Linguistics, 33(2):201­228. W. W. Cohen and V. Carvalho. 2005. Stacked sequential learning. In Proc. of IJCAI. A. Darwiche. 2003. A differential approach to inference in Bayesian networks. Journal of the ACM, 50(3). J. Eisner, E. Goldlust, and N. A. Smith. 2005. Compiling Comp Ling: Practical weighted dynamic programming and the Dyna language. In Proc. of HLTEMNLP. J. Eisner. 2002. Parameter estimation for probabilistic finite-state transducers. In Proc. of ACL. J. R. Finkel, T. Grenager, and C. D. Manning. 2005. Incorporating non-local information into information extraction systems by gibbs sampling. In Proc. of ACL. J. Goodman. 1998. Parsing inside-out. Ph.D. thesis, Harvard University. J. Goodman. 1999. Semiring parsing. Computational Linguistics, 25(4):573­605. A. Griewank and G. Corliss. 1991. Automatic Differentiation of Algorithms. SIAM. L. Huang and D. Chiang. 2005. Better k-best parsing. In Proc. of IWPT. L. Huang and D. Chiang. 2007. Forest rescoring: Faster decoding with integrated language models. In Proc. of ACL. L. Huang. 2008. Forest reranking: Discriminative parsing with non-local features. In Proc. of ACL. M. I. Jordan, Z. Ghahramani, T. Jaakkola, and L. Saul. 1999. An introduction to variational methods for graphical models. Machine Learning, 37(2). D. Klein and C. Manning. 2001. Parsing and hypergraphs. In Proc. of IWPT. T. Koo and M. Collins. 2005. Hidden-variable models for discriminative reranking. In Proc. of EMNLP. K. Kurihara and T. Sato. 2006. Variational Bayesian grammar induction for natural language. In Proc. of ICGI. J. Lafferty, A. McCallum, and F. Pereira. 2001. Conditional random fields: Probabilistic models for segmenting and labeling sequence data. In Proc. of ICML. R. Levy, F. Reali, and T. Griffiths. 2008. Modeling the effects of memory on human online sentence processing with particle filters. In Advances in NIPS. B. T. Lowerre. 1976. The Harpy Speech Recognition System. Ph.D. thesis, Carnegie Mellon University. D. J. C. MacKay. 1997. Ensemble learning for hidden Markov models. Technical report, Cavendish Laboratory, Cambridge. A. F. T. Martins, D. Das, N. A. Smith, and E. P. Xing. 2008. Stacking dependency parsers. In Proc. of EMNLP. R. McDonald and F. Pereira. 2006. Online learning of approximate dependency parsing algorithms. In Proc. of EACL. F. C. N. Pereira and Y. Schabes. 1992. Inside-outside reestimation from partially bracketed corpora. In Proc. of ACL, pages 128­135. D. Roth and W. Yih. 2004. A linear programming formulation for global inference in natural language tasks. In Proc. of CoNLL. S. Shieber, Y. Schabes, and F. Pereira. 1995. Principles and implementation of deductive parsing. Journal of Logic Programming, 24(1-2):3­36. D. A. Smith and J. Eisner. 2008. Dependency parsing by belief propagation. In Proc. of EMNLP. N. A. Smith, D. L. Vail, and J. D. Lafferty. 2007. Computationally efficient M-estimation of log-linear structure models. In Proc. of ACL. C. Sutton and A. McCallum. 2004. Collective segmentation and labeling of distant entities in information extraction. In Proc. of ICML Workshop on Statistical Relational Learning and Its Connections to Other Fields. A. J. Viterbi. 1967. Error bounds for convolutional codes and an asymptotically optimal decoding algorithm. IEEE Transactions on Information Processing, 13(2). M. Wang, N. A. Smith, and T. Mitamura. 2007. What is the Jeopardy model? a quasi-synchronous grammar for QA. In Proc. of EMNLP-CoNLL. 326