Posterior Control of Blackbox Generation (2020)

Abstract: Text generation often requires high-precision output that obeys task-specific rules. This fine-grained control is difficult to enforce with off-the-shelf deep learning models. In this work, we consider augmenting neural generation models with discrete control states learned through a structured latent-variable approach. Under this formulation, task-specific knowledge can be encoded through a range of rich, posterior constraints that are effectively trained into the model. This approach allows users to ground internal model decisions based on prior knowledge, without sacrificing the representational power of neural generative models. Experiments consider applications of this approach for text generation. We find that this method improves over standard benchmarks, while also providing fine-grained control.

## introduction a core challenge in using deep learning for nlp is developing methods that allow for controlled output while maintaining the broad coverage of data-driven methods. while this issue is less problematic in classification tasks, it has hampered the deployment of systems for conditional natural language generation (nlg), where users often need to control output through task-specific knowledge or plans. while there have been significant improvements in generation quality from automatic systems @xcite @xcite , these methods are still far from being able to produce controlled output @xcite . recent state-of-the-art system have even begun to utilize manual control through rulebased planning modules @xcite . consider the case of encoder-decoder models for generation, built with rnns or transformers. these models generate fluent output and provide flexible representations of their conditioning. unfortunately, auto-regressive decoders are also globally dependent, which makes it challenging to incorporate domain constraints. research into controllable deep models aims to circumvent the all-or-nothing dependency tradeoff of encoder-decoder systems and expose explicit higher-level decisions. one line of research has looked at global control states that represent sentence-level properties for the full decoder. for example, @xcite uses generative adversarial networks where the attributes of the text (e.g., sentiment, tense) are exposed. another line of research exposes fine-level properties, such as phrase type, but requires factoring the decoder to expose local decisions, e.g. @xcite . this work proposes a method for augmenting any neural decoder architecture to incorporate finegrained control states. the approach first modifies training to incorporate structured latent control variables. then, training constraints are added to anchor the state values to problem-specific knowledge. at test time, the control states can be ignored or utilized as grounding for test-time constraints. technically, the approach builds on recent advances in structured amortized variational inference to enforce additional constraints on the learned distribution. these constraints are enforced through efficient structured posterior calculations and do not hamper modeling power. we demonstrate that the method can improve accuracy and control, while utilizing a range of different posterior constraints. in particular on two large-scale data-to-text generation datasets, e2e @xcite and wikibio @xcite , our method increases the performance of benchmark systems while also producing outputs that respect the grounded control states. our code is available at https://github.com/xiangli1999/ posteriorcontrol-nlg . ## control states for blackbox generation consider a conditional generation setting where the input consists of an arbitrary context x and the output y 1:t is a sequence of target tokens. we are interested in modeling latent fine-grained, discrete control states @xmath0:t each with a label in c. we assume that these states are weaklysupervised at training through problem-specific constraints. the goal is to induce a model of p(y | x) = z p(y, z | x). concretely, our experiments will focus on a data-to-text generation problem where x corresponds to a table of data, and y 1:t is a textual description. we hope to induce control states z that indicate which table fields are being described, and our weak supervision corresponds to indicators of known alignments. we assume the generative model is a blackbox auto-regressive decoder that produces both y and z. define this general model as: for a neural decoder, where h t (y 1:t-1 , z 1:t-1 ) is the hidden state at time-step t, we might generate the latent class z @xmath1, here g θ is a parameterized embedding function and w, b are model parameters from θ. the log-likelihood of the model is given by l(θ) = log p θ (y | x). the key latent term of interest is the posterior distribution p θ (z | x, y), i.e. the probability of over state sequences for a known output. the decoder parameterization makes this distribution intractable to compute in general. we instead use variational inference to define a parameterized variational posterior distribution, q φ (z | x, y), from a preselected family of possible distributions q. 1 to fit the model parameters θ, we utilize the evidence lower bound (for any variational parameters φ), several recent works have shown methods for effectively fitting neural models with structured variational inference @xcite @xcite . we therefore use these techniques as a backbone for enforcing problem-specific control. see §4 for a full description of the variational family used. ## posterior regularization of control states posterior regularization (pr) is an approach for enforcing soft constraints on the posterior distribution of generative models @xcite . our goal is to utilize these soft constraints to enforce problem specific weak supervision. traditionally pr uses linear constraints which in the special case of expectation maximization for exponential families leads to convenient closed-form training updates. as this method does not apply to neural generative models, we resort to gradient-based methods. in this section, we develop a form of posterior regularization that accommodates the neural variational setting. starting with the log-likelihood objective, l(θ), pr aims to add distributional constraints on the posterior. these soft constraints are expressed as a distributional penalty, r p (x, y) ≥ 0. for example, if we have partial information that a specific control state takes on label c we can add a constraint r p (x, y) = 1p(z @xmath2, y). we might also consider other distributional properties, for instance penalizing the entropy of a specific posterior marginal, r p (x, y) = h z (z @xmath3, y). see §5 for more constraint examples. pr uses these soft constraints to regularize the model. ideally we would penalize the posterior directly, but as noted above, computing this term in a blackbox model is intractable. we therefore follow @xcite and use a relaxed version with a surrogate posterior q φ (z | x, y), we can write this in terms of a variational lowerbound on the relaxed pr objective. this allows us to relate the q in the prlbo to the variational posterior in the elbo simply by clowns is a restaurant british r q (x,y) < l a t e x i t s h a 1 _ b a s e 6 4 = " s x r 8 g 3 g h 4 m b n q 0 n p a w o 5 r c / n 4 p @xmath4, to train, we jointly maximize over both terms in the prlbo: the model parameters θ and the variational parameters φ (which tightens the bounds). following standard practice, we use an amortized inference network, i.e. a variational autoencoder @xcite @xcite , to define φ. ## structured variational family for segmental generation we now discuss how to efficiently compute the prlbo under a structured variational family. we need a q φ (z | x, y) for which we can efficiently (1) take samples, (2) compute entropy, and (3) compute the distributional penalties. this motivates the use of a factored conditional random field (crf), defined by a potential function φ(x, y, z). at training time, x, y are observed and z is the latent variable that denotes the control states. we then specify a variational posterior distribution: q φ (z | x, y) = φ(x,y,z) z φ(x,y,z ) . in this work, we focus on the semi-markov crf @xcite , a common crf family used in generation @xcite . it divides tokens into segmental spans, which are useful for generating entity mentions and commonly used phrases. this model divides the potential function into three parts: the emission potential for a span of tokens given given φ and generic semiring (⊕, ⊗, 0, 1) set β t (c) = 1 ∀@xmath5, . . . , 0 do for @xmath6 a state, denoted as φ (e) ; the transition potential between states, φ (t) ; and the length potential of span length given a state, φ (l) . suppose our control states define a span from i (inclusive) to j (exclusive) labeled by c, we denote it as z i:@xmath7. the potential function of a labeled sequence is defined: for computational efficiency, we restrict all segment length to @xmath8. 2 with this model, we can use the forwardbackward algorithm for all required inferences: exact sampling, computing partition function, entropy, and posterior marginals q φ (z i:@xmath9, y), useful for term (3). in algorithm 1, we give a one-to-one one-to-many name penalty name penalty inclusion for (i, j, f ) ∈ a(x, y), sparsity for @xmath10, for @xmath11, j, f ) ∈ a(x, y), fit for (i, j, f ) ∈ a(x, y) @xmath12: the algorithm is generic in the sense that different (⊗, ⊕) operators allow us to compute different needed terms. for example, computing the partition function @xmath13, y, z ) requires the (+,×) semiring @xcite , other distributional terms can be computed by using the same algorithm with alternative semirings and backpropagation 3 . ## posterior constraints from data alignment to make the pr model concrete, we consider the problem of incorporating weak supervision from heuristic alignment in a data-to-text generation task. assume that we are tasked with describing a table x consisting of global field names f each with a text value v, e.g. x @xmath14. not all global fields may be used in a given x, we use @xmath15: (a) log-partition term log z φ(x, y, z ) requires the log semiring (logsumexp, +). the posterior marginals q(z | x, y) requires backpropagating from the log-partition term; (b) max score maxz φ(x, y, z): (max, +) max semiring and argmax arg max z φ(x, y, z) by (subgradient) backpropagation, (c) entropy through an expectation semiring p1, r1 ⊗ p2, @xmath16, p1r2 + p2r1 , and p1, r1 ⊕ p2, @xmath17, r1 + r2 , with 1 = 1, 0 . to initialize, all the emission, transition and length scores takes the form φ, -log φ . the algorithm returns z, r , and the true entropy is r z + log z. (d) exact sampling through one backward pass and one forward filtering backward sampling, where forward uses the log-partition semiring and backpropagation is by categorical sampling. one-to-one constraints we first consider oneto-one constraints where we assume that we have a static, mapping from fields to states σ : @xmath18. given this mapping, we need to add penalties to encourage the semi-markov model to overlap with the given weak supervision. to enforce soft alignments, we define three posterior constraint types and their computation as shown in one-to-many constraints we also consider the case when it is infeasible to specify a hard mapping σ between the fields and the states. for example, f could be unbounded or large, whereas we hope to keep the cardinality of states small for computational efficiency. we propose a method of inducing a dynamic soft mapping σ(c | f ) as we train the model, and impose constraints on the mapping from table field to the state names. first, we would like the distribution of state given table field to be consistent, so one table field is mapped to roughly 1 state. second, we want to make use of the state space as much as possible by requiring a diverse usage of states. in order to enforce these properties we introduce the dynamic mapping as a second amortized variational distribution σ(c | f ; m ) = softmax(m f ) which gives the probability that a table field f takes on state c. as shown in ## related work in addition to previously mentioned work, other researchers have noted the lack of control of deep neural networks and proposed methods at sentencelevel, word-level, and phrase-level. for example @xcite and @xcite control the sentiment in longer-form story generation. others aim for sentence-level properties such as sentiment, style, tense, and specificity in generative neural models @xcite @xcite . closest to this work is that of @xcite who control phrase-level content by using a neuralized hidden semi-markov model for generation itself. our work differs in that it makes no independence assumption on the decoder model, uses a faster training algorithm, and proposes a specific method for adding constraints. finally, there is a line of work that manipulates the syntactic structure of generated texts, by using some labeled syntactic attribute (e.g., parses) or an exemplar @xcite @xcite . while our work uses control states, there is no inherent assumption of compositional syntax or grammar. posterior regularization (pr) is mostly used in standard em settings to impose constraints on the posterior distribution that would otherwise be intractable (or computationally hard) in the prior. @xcite applies posterior regularization to word alignment, dependency parsing, and part-of-speech tagging. combining powerful deep neural networks with structured knowledge has been a popular area of study: @xcite applies pr to multi-object generation to limit object overlap; @xcite focuses on object detection, and uses pr features to exploit mutual exclusion. in natural language processing; @xcite propose an iterative distillation procedure that transfers logic rules into the weights of neural networks, as a regularization to improve accuracy and interpretability. finally, the core of this work is the use of amortized inference/variation autoencoder to approximate variational posterior @xcite @xcite . we rely heavily on a structure distribution, either linear chain or semi-markov, which was introduced as a structured vaes @xcite @xcite . our setting and optimization are based on @xcite , who introduce a latent tree variable in a variational autoencoding model with a crf as the inference network, and on @xcite who use an encoder-decoder model as the inference network. ## experimental setup data and metrics we consider two standard neural generation benchmarks: e2e @xcite and wikibio @xcite datasets, with examples shown in figure 1 . the e2e dataset contains approximately 50k examples with 8 distinct fields and 945 distinct word types; it contains multiple test references for one source table. we evaluate in terms of bleu @xcite , nist @xcite , rouge-l table (x): name[clowns] eattype[coffee shop] food[chinese] customer-rating[1 out of 5] area[riverside] near[clare hall] ref.1: clowns is a coffee shop in the riverside area near clare hall that has a rating 1 out of 5 . they serve chinese food . ref.2: the chinese coffee shop by the riverside near clare hall that only has a customer rating of 1 out of 5 is called clowns . ref.3: there is a chinese coffee shop near clare hall in the riverside area called clowns its not got a good rating though . ref.1: frederick parker-rhodes (21 march 1914 -21 november 1987) was an english linguist, plant pathologist, computer scientist, mathematician, mystic, and mycologist. figure 2 : generation benchmarks. model is given a table x consisting of semantic fields and is tasked with generating a description y 1:t of this data. two example datasets are shown. left: e2e, right: wikibio. @xcite , cider @xcite and meteor @xcite , using the official scoring scripts 4 . the wikibio dataset contains approximately 700k examples, 6k distinct table field types, and 400k word types approximately; it contains one reference for one source table. we follow the metrics from @xcite and evaluate the bleu, nist, and rouge-4 scores. architecture and hyperparameters for all tasks, we use an encoder-decoder lstm for the generative model. we follow recent state-of-the-art works in parametrizing our encoder, and we use copy attention and dual attention @xcite @xcite : full model architectures are given in the supplement. the inference network scores are computed using a bilstm. we compute the emission scores φ (e) using span embeddings @xcite @xcite ; transition scores φ (t) by dot product between embedding vectors for the class labels; lengths φ (l) is kept uniform, as in @xcite . additional details are in the supplement. at training time, we use a rate for alleviating posterior collapse in the elbo: warm-up the elbo objective by linearly annealing the coefficient on the term t @xmath19, @xmath20, y)] from 0 to 1, as implemented in @xcite . we use the reinforce algorithm to do monte carlo estimation of the stochastic gradient. we choose the control variate to be the mean of the samples @xcite . at decoding time, we only use the generative model. we use beam search with length normalizabaselines for generation on e2e, we compare externally against 4 systems: e2e-benchmark @xcite is an encoder-decoder network followed by a reranker used as the shared task benchmark; ntemp, a controllable neuralized hidden semi-markov model; ntemp+ar, the product of experts of both a ntemp model and an autoregressive lstm network @xcite ; shen19 @xcite is an pragmatically informed model, which is the current state-ofthe-art system on e2e dataset. we also compare internally with ablations of our system: encdec is a conditional model p(y | x) trained without control states. pc 0 is posterior control model with no constraints. it uses structured encoder with the pr coefficient set to 0. pc ∞ is our model with hard constraints, which assumes fully-observed control states. these control states are obtained by mapping tokens with lexical overlap to their designated state; otherwise we map to a generic state. we train a seq2seq model p(y, z | x) with full supervision of both control states and target text. our main model is pc λ , which applies pr with coefficient given by hyperparameter λ. for wikibio, we compare externally against 5 systems: ntemp and ntemp+ar as above; le-bret16 @xcite , which uses copy attention and an nnlm; liu18 (encdec), which is our base encoder-decoder lstm model, and liu18 (field gating) which uses a field gating table encoder and a decoder with dual attention @xcite . for internal comparison on wikibio, we compare between the one-to-one and one-tomany constraints in §5. pc λ one-to-one applies the one-to-one posterior constraints (left of ## experiments for internal comparison, having soft constraints on the posterior outperforms the system pc ∞ (forced hard constraints) and pc 0 (no constraints). anecdotally, we find that if two fields have the same value, then the hard coding system is often forced into the wrong decision. similarly removing posterior regularization altogether leads to a slightly weaker performance than our controlled model. on the larger wikibio dataset (right) our model also significantly outperforms both the controllable ntemp and ntemp+ar baselines in all three met-rics. it gives improvements over @xcite 's strong encoder-decoder style model. the promising result from wikibio dataset suggests that the method scales to larger datasets and the pr style works well in handling large field spaces. in addition, we find that dynamic constraints are feasible compared with static constraints (we believe this is because the modeling burden on pc λ one-to-many is heavier since it also needs to figure out the clustering). overall, the dynamic framework opens up the possibility of generalizing to work well with a wider set of constraints. ## analysis qualitative analysis table (x): name[james horton]; birthdate[1850]; deathdate[none]; birthplace[boston, massachusetts]; allegiance[united states of america]; branch[united states navy]; rank[captain of the top]; awards[medal of honor] ref: james horton -lrb-born 1850 -rrb-was a sailor serving in the united states navy who received the medal of honor for bravery . pc λ : james horton -lrb-born 1850 , date of death unknown -rrb-was a united states navy sailor and a recipient of the united states military 's highest decoration , the medal of honor . here we fix the prior on z to 8 different sequences of class labels shown in different colors, and do constrained beam search on the generative model by holding z fixed, and decoding from the model p θ (y | x, z). controllability next we consider a quantitive experiment on model control. assuming we have a mapping from control states to fields, ideally, at test time z should use the right states from the source x. 5 let @xmath21, j, f ) : z i,@xmath22, @xmath23, σ(f ) = c} be the field states used by z. define the field word overlap between x and y as, under these metrics we see the following control metrics on the e2e dataset, 5 on e2e dataset, we remove the binary table field, "family friendly" which is never expressed by lexical match. p r c pc ∞ 0.996 0.895 0.833 pc λ 1.0 0.969 1.0 the pc model with soft posterior constraints performs better than having hard constraints on all three metrics. having @xmath24, and @xmath25. on wikibio, the model has a precision of 0.83 on the, meaning that on average, when we generate a good control state, 83% of the generated tokens will match the table content. since only a fraction of the source table in wikibio is used, recall and coverage are less applicable. distributional metrics limitations given the promise of pr as a technique for inducing control states, it is worth noting some of the current limitations to our specific application of the method. currently, we use simple rules which do not generalize well to paraphrase. our weak supervision relies on direct overlap to align states and fails on aligning phrases like less then 10 dollars that are expressed as cheap. additionally, while at test time, our method is comparable to a standard decoder model, it does require slightly longer to train due to both the dynamic program and the requirement to compute multiple samples. ## conclusion this work introduces a method for controlling the output of a blackbox neural decoder model to follow weak supervision. the methodology utilizes posterior regularization within a structured variational framework. we show that this approach can induce a fully autoregressive neural model that is as expressive as standard neural decoders but also utilizes meaningful discrete control states. we show this decoder is effective for text generation while inducing meaningful discrete representations. table (x): name[clowns] eattype[coffee shop] food[english] customerrating[5 out of 5] area[riverside] near[clare hall]