Massive-scale Decoding for Text Generation using Lattices (2022)

Abstract: Conditional neural text generation models generate high-quality outputs, but often concentrate around a mode when what we really want is a diverse set of options. We present a search algorithm to construct lattices encoding a massive number of generation options. First, we restructure decoding as a best-first search, which explores the space differently than beam search and improves efficiency by avoiding pruning paths. Second, we revisit the idea of hypothesis recombination: we can identify pairs of similar generation candidates during search and merge them as an approximation. On both summarization and machine translation, we show that our algorithm encodes thousands of diverse options that remain grammatical and high-quality into one lattice. This algorithm provides a foundation for building downstream generation applications on top of massive-scale diverse outputs.

## introduction although pre-trained text generation models @xcite have achieved impressive results across a range of tasks, these models do not always deliver what system developers want. machine generated text may be non-factual @xcite @xcite or toxic @xcite . we might patch these problems by applying discriminators over the output @xcite to enforce these properties post-hoc; we could, for instance, apply a secondary model as a reranker over a small collection of outputs. however, if the generator returns a homogeneous set of candidates, we may fail to find any usable generation output. what if generation models could return massive numbers of candidates rather than a few outputs with optimal score? 1 code, implementation guideline, and visualization are available at https://github.com/jiacheng-xu/ lattice-generation . with a large set of candidates, our secondary model could more easily find an acceptable one without having to take more extreme steps like re-training the initial generation model. output diversity has separately been established as a useful goal for for applications such as dialogue and story generation @xcite . standard approaches including beam search (bs) and sampling methods fall short of our goal. beam search uses significant computational resources to explore similar hypotheses, and much of the computation in the search process is invested into paths that could be acceptable generation outputs, but are ultimately pruned. sampling approaches like nucleus sampling @xcite , although achieving better diversity than beam search, often re-discover seen hypotheses and can be harder to control for quality. a central problem with both methods is that they do not handle very similar hypotheses efficiently. in this paper, we present a decoding framework with two key components. first, we argue that a modified best-first search (bfs) is the right way to explore the search space. we augment standard best-first search with a depth-first path completion strategy: we eagerly expand each node until we reach an eos token, thereby guaranteeing that each node is part of some completed path returned to the user. this generation strategy avoids exploring large numbers of states which end up being pruned. bfs is also more flexible than static beam search and can prioritize exploration in more uncertain parts of the generation. second, our algorithm returns a massive number of generation options encoded in a lattice, with different hypotheses recombined in an approximate fashion. beam search preserves similar outputs such as "a cardiff recycling company has gone into" and "a cardiff waste management company has gone into" as different states. however, these prefixes actually have very similar distributions of following words under the model; if we identify states like this, we can recombine them (figure 2 ) and treat them as the same from the perspective of future continuations. in figure 1 , we show an illustration of the lattice structure this recombination can form for document summarization. we broaden a recombination method used previously in beam search for machine translation @xcite , enabling us to compactly encode large number of generation candidates and achieve dense lattices. we show results for both document summarization and machine translation in three language pairs. for each setting, we show that our lattice encodes a large number of high-quality candidates, including good matches with annotated reference generations. we further show that a variant of our method can still achieve strong results with a lower number of nodes expanded than the baselines, suggesting that this can be a path towards saving computational resources. we believe that computing thousands of high-quality generation candidates within a single compact data structure can provide a powerful starting point for various downstream purposes: diversity, factuality, customizability, and more. ## problem & setup we define our algorithm in the context of conditional text generation @xcite . conditional text generation is formulated as sequence transformation from a source input x to target output @xmath0, . . . , y n ) via a neural text generation model parameterized by θ. each y i is a symbol in a vocabulary v. the probability of a decoded sequence is given by p(y | x; θ) = n @xmath1, x; θ). decoding text from a model can be framed as a search problem, where the search objective is to find the path to merge merge target a cardiff waste company has gone into bankruptcy recycling plant has gone into 𝒪.pop() apply recombination check for possible recombinations pop from pop the node with highest score from search frontier 𝒪 𝒪 . y expand a node n after recombination: a cardiff waste company has gone into bankruptcy recycling plant has gone into . deleted figure 2: our search algorithm. at each step, the algorithm pops a node from search frontier o, checks for possible recombinations with existing nodes, and merges the nodes if a match is found. in this example, "has gone into" is the merge target to match. "waste company" and "recycling plant" are interchangeable paraphrases which do not affect the continuation from the model's perspective. output sequence that maximizes the conditional probability under the model: arg max ŷ p(ŷ | x; θ). because p(ŷ t | ŷ<t , x; θ) depends on the entire generated sequence so far, this decoding problem is intractable to solve exactly. while typically the goal of decoding is to find the hypothesis with the highest possible model score, we instead focus on finding a large set of "good enough" hypotheses. that is, finding a set y: arg max y |y| s.t. p(y | x; θ) > for all @xmath2. emerges naturally by adjusting search hyperparameters to control the number of returned hypotheses. our goal in this paper is to design an algorithm that can efficiently find y. notation we encode predicted generation candidates ŷ in a lattice. a lattice @xmath3, e) is a directed graph where each node represents a token and paths defined by directed edges encode candidates. a path π in l from a unique startof-sequence node n sos to any node n represents a (partially) decoded string, consisting of the words in that path. all completed paths start with n sos and end at (potentially different) end-of-sequence nodes n eos . the search graph l is constructed iteratively through a search procedure. we maintain the closed graph c with explored nodes and edges as well as a search frontier o, a set consisting of successors to nodes currently in the graph. for each node, there are |v| possible successors. we define the search budget as the number of nodes expanded from the search frontier. our experiments will seek to compare different methods using the same search budget. we will define this more precisely in sec. 7. ## inadequacies of beam search as we have alluded to, beam search is inadequate for our goal for several reasons. we show experiments on these aspects in this section and appendix a. better model score better hypothesis the most critical issue is that beam search is designed to efficiently approximate arg max ŷ = p(ŷ | x; θ), but the optimal model score is neither our goal nor a guarantee of a good hypothesis. in figure 3 , we compare the correlation of model score and rouge under beam search for text summarization. the pearson correlation between these two variables is very weak. beyond rouge score, the example in fig. 1 shows that the main differences between these summaries may be minor differences in surface realization that have little effect on our qualitative judgments of summary quality. the hypothesis with the best score under beam search is not substantially better quality than hypotheses with slightly lower scores. ## modified best-first search as established in the previous section, beam search prunes many paths that would potentially yield high-quality summaries and wastes computational resources expanding nodes that aren't included in a algorithm 1 best-first search with depth-first completion and path recombination input: generation model θ with vocabulary v, search budget b, o and c denote open set (max priority queue) and closed set, isrecomb and dorecomb are functions checking and running path recombination. output: all completed paths p 1: o ← {(∞,n sos )}, c ← ∅, expanded ← 0. o ← o ∪ (score, nv) 16: c ← c ∪ ĥ 20: end while final search graph. we tackle this issue by changing from beam search to best-first search (bfs) @xcite . bfs prioritizes searching over nodes according to a scoring function, giving us more flexibility in how we explore the space. our chief modification of the base algorithm is a heuristic we call depth-first completion. depth-first path completion neural text generation is a search problem with large branching factor (v) and deep search depth (sequence length). as a result, applying bfs with the scoring function being the model score of a state often leads to a broad search that rarely returns a valid path. one solution to this problem is to incorporate a heuristic based on length. model score is monotonically decreasing as a sequence grows in length, so prior work @xcite @xcite has used a length reward term to alleviate this issue. 2 we found that, even with a length heuristic, bfs will still have "dangling" nodes that are not part of any path to an eos (goal) token, and it might return few or no valid hypotheses. recognizing our objective from equation 1 , we can take a simple step to ensure that every node ends up on some completed path: eagerly do a greedy search from each node until we reach n eos 2 this can be considered a heuristic like in (weighted) a * search, but it is not necessarily admissible or consistent. or exceed a maximum length. in algorithm 1, we implement this by modifying the priority of the highest scored token with ∞ (line 12), so it will be explored immediately after the current time step. in figure 5 , we illustrate depth-first completion. ## path recombination path recombination, also known as hypothesis recombination, was originally proposed and used in phrase-based machine translation @xcite @xcite . the idea of path recombination is to combine similar paths if what the model predicts for them in the future is the same, reflecting a similar dynamic programming principle as the viterbi algorithm. we focus on finding hypotheses which approximately exhibit this property, and show that merging them can yield high-quality outputs. figure 2 shows an example of recombination. the two hypotheses being merged here roughly convey the same intent, and it turns out that the shared suffix "has gone into" is a strong indicator that the model will treat them similarly in the rest of the generation. ## recombination mechanism we illustrate the two major recombination techniques we introduce, rcb and zip, in figure 6 . these methods represent our two implementations of dorecomb in algorithm 1. rcb: generalization of zbeam zbeam has a major limitation: a limited set of merging candidates. the potential merge candidates in zbeam are only nodes in the current beam hypotheses and their previous steps, so the method cannot merge with nodes from earlier timesteps. for example, "a waste plant has gone into" cannot be merged with the hypothesis with ending in node 4 shown in figure 6 . the proposed generalization, rcb, addresses this limitation. we index all of the nodes in the lattice across all timesteps by their n-grams using a hash table, making it o(1) time to look up an n-gram pattern and retrieve potential merge candidates if they exist. zip: recombining more if we take a closer look at rcb in figure 6 , we see that even in the merged structure, nodes 3 and 7 and nodes 2 and 6 are preserved as separate. they do not pass the recombination criterion themselves, but these nodes are part of the suffix matched strings, still correspond to the same words, and have the same directly generated next word. there is reason to believe that these might be equivalent as well. hence, we explore a variant called zip that propagates the merge backwards through the lattice. this change relaxes the merging criterion and up to n pairs of nodes are combined when a merge is identified, leading to a more compact lattice. we describe some of the details in appendix d. ## evaluation to evaluate the proposed methods, we conduct experiments on abstractive text summarization and machine translation. our evaluation focuses on two questions: (1) how large and diverse are our lattices? ( 2 ) are the candidates encoded in the lattices high quality and grammatical? ## related work the techniques used in this work partially reflect an outgrowth of a few lines of literature: understanding the behavior of text generation models @xcite @xcite , investigations into beam search @xcite , and studies of diversity in generation. in terms of search strategies, best-first beam search @xcite is a method integrat-ing best-first search with beam search. some other variants of search have also been studied in previous work @xcite . beam search has been critically examined in some recent work @xcite , but largely of focused on specific challenges in mt. as for diverse generation, neural text degeneration has been discussed in @xcite ; @xcite ; @xcite , which led to an interest in diverse generation models. diverse text generation has been studied in previous work @xcite , including in dialogue @xcite , story generation @xcite , and particularly paraphrasing @xcite . our method can also diversify content coverage @xcite and word choice @xcite . ## discussion & conclusion we presented an algorithm for decoding in text generation with two main components: best-first search to more efficiently structure exploration of the space and hypothesis recombination to encode summaries in a lattice structure. we showed that across summarization and machine translation, these lattices successfully encode large numbers of high-quality generation options. there are a few limitations of our method. first, we currently benchmark these techniques using number of nodes expanded, not wall clock time. there are strategies for parallelizing the bfs expansion @xcite , but it remains to be seen how this parallelism compares to the parallelism achieved by beam search. regardless, the dramatically larger number of hypotheses we return outweighs efficiency differences for now. second, we focus on auto-regressive methods in this paper. however, we believe our framework could also be applied and adopted to non auto-regressive generation models @xcite .