Residual Energy-Based Models for Text Generation

1 INTRODUCTION . The dominant approach to parametric text generation is based on large neural auto-regressive models ( Radford et al. , 2019 ) . These models can be trained efficiently via maximum likelihood and they can efficiently generate samples of remarkable quality . Key to their success is local normalization , i.e . they are defined in terms of a product of conditional distributions , one for each token in the sequence . Such distributions are relatively cheap to compute with modern hardware given the limited vocabulary size of common sub-word units like BPE ( Sennrich et al. , 2015 ) . Unfortunately , local normalization also brings some drawbacks . First , the designer of the model needs to specify the order in which tokens are generated . Second , at training time the model is conditioned on ground truth context while at test time it is conditioned on its own generations , a discrepancy referred to as exposure bias ( Ranzato et al. , 2016 ) . Finally , while heuristics like beam search somewhat help rescore at the sequence level , generation generally lacks long-range coherency because it is produced by the greedy selection of one token at a time without lookahead . Energy-based models ( EBMs ) ( Hinton , 2002 ; LeCun et al. , 2006 ; Ranzato et al. , 2007 ) are a more general framework which potentially address all these issues , as they do not require any local normalization . They only require the definition of an energy function defined over the whole input sequence . Training aims at shaping the energy function such that regions of high density of training data points have lower energy than elsewhere . In principle , EBMs are ideal for modeling text as they can score the whole input at once , they are not prone to label bias ( Bottou , 1991 ) and they may enable generation of large chunks of text , which should help improve coherency . However , so far EBMs had limited application in text generation , because sampling from the model is intractable , and so is maximum likelihood training . The problem is that shaping the energy function is accomplished by updating the model parameters such that the energy is decreased at the training data points ( a.k.a . positive examples ) and increased at other data points ( a.k.a . negative examples ) . In maximum likelihood training negatives are generated from the model , but in text application we can not use gradient-based MCMC methods ( Teh et al. , 2003 ; Du & Mordatch , 2019 ) and Gibbs sampling ( Welling et al. , 2005 ) is too slow to be practical . Generating negatives by local perturbations of the ground truth would be efficient but hardly useful for generation purposes , when at test time the model needs to generate from scratch . Recently , Bakhtin et al . ( 2019 ) carefully studied the problem of training a discriminator to distinguish human written text from language model generations . They experimented with different language model and discriminator architectures , training/test time corpora and concluded that the discriminator can generalize rather well to weaker language models when the training/test corpora match . Bakhtin et al . ( 2019 ) found that the learned discriminator is not robust to random perturbations , and argued that the discriminator operates in the “ residual ” space of the language model . Concurrently , Grover et al . ( 2019 ) proposed a general approach to “ de-bias ” a generator , by simply training a discriminator and using its output for importance sampling . In this work , we build upon these two works . First , we formalize the residual interpretation by Bakhtin et al . ( 2019 ) and use a generative model of the form : Pθ ( x ) ∝ PLM ( x ) exp ( −Eθ ( x ) ) ( 1 ) where PLM ( x ) is a locally normalized language model which is fixed during training , and Eθ is the energy function parameterized by θ . The resulting model Pθ ( x ) is globally normalized due to the energy term . Note that the same residual formulation was also used in Rosenfeld et al . ( 2001 ) ; Wang & Ou ( 2018b ) ; Parshakova et al . ( 2019 ) . This formulation has multi-fold benefits . First , by incorporating a locally normalized language model , we can leverage recent advancements in locally normalized language modeling . Second , the language model provides a natural proposal distribution for training ( Bakhtin et al. , 2019 ) , and training can be made efficient by using the conditional noise contrastive estimation objective ( Gutmann & Hyvärinen , 2010 ) as we shall see in §3 . Lastly , this formulation enables efficient evaluation and generation via importance sampling ( Horvitz & Thompson , 1952 ; Grover et al. , 2019 ) . In some sense , this last point is perhaps the central contribution of the paper , as it allows estimating perplexity of the residual EBM , and thus allows these EBMs to be compared in a standard way to other models . Indeed , in §4 we show that our joint model decreases perplexity on two large datasets , when compared to various auto-regressive language model baselines . Finally , the EBM generations are significantly preferred by humans according to our qualitative evaluation . To the best of our knowledge , this is the first time that an EBM has demonstrated improved generation ability against very strong auto-regressive baselines , both in terms of estimated perplexity and through human evaluation . 2 RELATED WORK . Energy-based models have a long history in machine learning ( Hopfield , 1982 ; Hinton , 2002 ; LeCun et al. , 2006 ; Ranzato et al. , 2007 ) . The key challenge of training is mining for good negatives . This can be accomplished explicitly by fantasizing inputs where the energy should be increased or implicitly via global constraints such as sparsity ( Ranzato et al. , 2007 ) . Methods attempting at maximizing the likelihood of the data require to sample from the distribution induced by the model . Unfortunately , gradient-based MCMC approaches like Hybrid Monte Carlo ( Teh et al. , 2003 ) and Langevyn dynamics ( Ranzato et al. , 2007 ; Du & Mordatch , 2019 ; Xie et al. , 2016 ; 2017 ; 2019 ; 2018 ; Gao et al. , 2018 ; Nijkamp et al. , 2019 ) are not applicable when the input is discrete like in text applications . Other approaches like Gibbs sampling ( Hinton , 2002 ) were applied to binary inputs but do not scale well to large dictionaries once the energy function is a large bidirectional transformer model like the one used in this work . Several variants of auto-encoders have also been investigated for representing and generating text ( Bowman et al. , 2016 ; Zhao et al. , 2018 ) , but they have not shown significant improvements in terms of perplexity and they have so far been applied to relatively small datasets only . Our approach appears similar to discriminative reranking approaches used in the parsing and machine translation community ( Shen et al. , 2004 ) . However , our approach provides a generative model , and parameters/hyper-parameters are directly tuned to close the gap between the model distribution and the data distribution , rather than relying on surrogate ranking losses . This approach is also related to other sequence level training objectives ( Edunov et al. , 2018 ) , with the major differ- ence that in those works training aims at improving the baseline model , but generation at test time is still greedy . Energy Networks have been used for sequence modeling ( Rosenfeld et al. , 2001 ; Wang et al. , 2015 ; 2017 ; Wang & Ou , 2017 ; 2018a ; Parshakova et al. , 2019 ) . In particular , our residual modeling form and the training algorithm is the same as in Wang & Ou ( 2018b ) , where they used an LSTM as the generator and a CNN-LSTM as the energy function , and showed significant gains compared to LSTM baselines in speech recognition . Our work builds on these prior works and develops new lower and upper bounds for the log-probability under the joint model , which makes it possible to show that the residual EBM approach gets better perplexity . We also develop an importance weighting sampling scheme used at generation time , which is focused on conditional generation as opposed to rescoring in speech recognition ( Wang & Ou , 2018b ) . The residual EBM formalism makes it very natural to use BERT for language modeling , and we show that empirically this type of approach can outperform modern state-of-the-art language modeling baselines , both in terms of perplexity , and through human evaluation . Generative Adversarial Networks ( Goodfellow et al. , 2014 ) also relate to EBMs , except that in EBMs the generator is implicit and negatives samples are produced by the discriminator itself . In our work , the pretrained locally normalized language model can be seen as a fixed generator , like in Bakhtin et al . ( 2019 ) . Azadi et al . ( 2018 ) also share our same goal but their generator is not locally normalized and they propose to improve the sampling from the generator by using the discriminator for rejection sampling . Similar to our work , Grover et al . ( 2019 ) propose to use the discriminator to de-bias the pretrained generator using importance sampling . We adapt this work to the application of text generation . In particular , we adopt the conditional noise contrastive estimation ( NCE ) objective ( Ma & Collins , 2018 ; Gutmann & Hyvärinen , 2010 ) to our residual model energy function and then sample from the joint model using importance sampling . We want to note that the same formulation has been proposed in ( Wang & Ou , 2018b ; Parshakova et al. , 2019 ) . While Ma & Collins ( 2018 ) used conditional NCE to predict the next word in a sequence , we apply it to produce a whole sequence at once with the pretrained auto-regressive language model as the noise distribution . 3 RESIDUAL ENERGY-BASED MODELS . We study the problem of conditional generation of discrete sequences . Given a prefix x1 , · · · , xp with xj ∈ V where V is the vocabulary , we want to model the probabilities of generating a sequence of total length T > p1 . The generative model is : Pθ ( xp+1 , · · · , xT |x1 , · · · , xp ) = PLM ( xp+1 , · · · , xT |x1 , · · · , xp ) exp ( −Eθ ( x1 , · · · , xT ) ) Zθ ( x1 , · · · , xp ) ( 2 ) where Zθ ( x1 , · · · , xp ) is a normalizing factor known as partition function . Computing the partition function is intractable in our case since it involves a sum over |V |T−p terms which grow exponentially with the sequence length : in our experiments the size of the vocabulary is 50,096 and the length of the generation is 40 tokens . We call Pθ the joint model , andEθ the residual energy function since PLM is fixed throughout training . The goal of training is to learn the parameters of the energy function such that the joint model distribution gets close to the data distribution . For the sake of reducing clutter in the notation , we will drop the conditioning variables in the following discussion .

Summary: The main contribution of this paper lies in the proposed Residual Energy-based Model (EBM) for text generation. Traditional normalized models operate at the token level with MLE training, while the proposed EBM operates at the sentence level. Therefore, BERT, or RoBERTa, can be leveraged for EBM design. The residual energy function is trained via conditional NCE, which reduces to training a binary classifier to discriminate between real text and text generated by an auto-regressive language model. After model training, text can be generated by top-k joint sampling. Experiments are conducted on two large language modeling datasets. The proposed model achieves lower perplexity, and preferred by human evaluation.