Adversarial Text Generation via Feature-Mover's Distance
Liqun Chen, Shuyang Dai, Chenyang Tao, Dinghan Shen, Zhe Gan, Haichao Zhang, Yizhe Zhang, Lawrence Carin
Introduction
Natural language generation is an important building block in many applications, such as machine translation , dialogue generation , and image captioning . While these applications demonstrate the practical value of generating coherent and meaningful sentences in a supervised setup, unsupervised text generation, which aims to estimate the distribution of real text from a corpus, is still challenging. Previous approaches, that often maximize the log-likelihood of each ground-truth word given prior observed words , typically suffer from exposure bias , i.e., the discrepancy between training and inference stages. During inference, each word is generated in sequence based on previously generated words, while during training ground-truth words are used for each timestep .
Recently, adversarial training has emerged as a powerful paradigm to address the aforementioned issues. The generative adversarial network (GAN) matches the distribution of synthetic and real data by introducing a two-player adversarial game between a generator and a discriminator. The generator is trained to learn a nonlinear function that maps samples from a given (simple) prior distribution to synthetic data that appear realistic, while the discriminator aims to distinguish the fake data from real samples. GAN can be trained efficiently via back-propagation through the nonlinear function of the generator, which typically requires the data to be continuous (e.g., images). However, the discrete nature of text renders the model non-differentiable, hindering use of GAN in natural language processing tasks.
Attempts have been made to overcome such difficulties, which can be roughly divided into two categories. The first includes models that combine ideas from GAN and reinforcement learning (RL), framing text generation as a sequential decision-making process. Specifically, the gradient of the generator is estimated via the policy-gradient algorithm. Prominent examples from this category include SeqGAN , MaliGAN , RankGAN , LeakGAN and MaskGAN . Despite the promising performance of these approaches, one major disadvantage with such RL-based strategies is that they typically yield high-variance gradient estimates, known to be challenging for optimization .
Models from the second category adopt the original framework of GAN without incorporating the RL methods (i.e., RL-free). Distinct from RL-based approaches, TextGAN and Gumbel-Softmax GAN (GSGAN) apply a simple soft-argmax operator, and a similar Gumbel-softmax trick , respectively, to provide a continuous approximation of the discrete distribution (i.e., multinomial) on text, so that the model is still end-to-end differentiable. What makes this approach appealing is that it feeds the optimizer with low-variance gradients, improving stability and speed of training. In this work, we aim to improve the training of GAN that resides in this category.
When training GAN to generate text samples, one practical challenge is that the gradient from the discriminator often vanishes after being trained for only a few iterations. That is, the discriminator can easily distinguish the fake sentences from the real ones. TextGAN proposed a remedy based on feature matching , adding Maximum Mean Discrepancy (MMD) to the original objective of GAN . However, in practice, the model is still difficult to train. Specifically, (i) the bandwidth of the RBF kernel is difficult to choose; (ii) kernel methods often suffer from poor scaling; and (iii) empirically, TextGAN tends to generate short sentences.
In this work, we present feature mover GAN (FM-GAN), a novel adversarial approach that leverages optimal transport (OT) to construct a new model for text generation. Specifically, OT considers the problem of optimally transporting one set of data points to another, and is closely related to GAN. The earth-mover’s distance (EMD) is employed often as a metric for the OT problem. In our setting, a variant of the EMD between the feature distributions of real and synthetic sentences is proposed as the new objective, denoted as the feature-mover’s distance (FMD). In this adversarial game, the discriminator aims to maximize the dissimilarity of the feature distributions based on the FMD, while the generator is trained to minimize the FMD by synthesizing more-realistic text. In practice, the FMD is turned into a differentiable quantity and can be computed using the proximal point method .
The main contributions of this paper are as follows: (i) A new GAN model based on optimal transport is proposed for text generation. The proposed model is RL-free, and uses a so-called feature-mover’s distance as the objective. (ii) We evaluate our model comprehensively on unconditional text generation. When compared with previous methods, our model shows a substantial improvement in terms of generation quality based on the BLEU statistics and human evaluation. Further, our model also achieves good generation diversity based on the self-BLEU statistics . (iii) In order to demonstrate the versatility of the proposed method, we also generalize our model to conditional-generation tasks, including non-parallel text style transfer , and unsupervised cipher cracking .
Background
2 Sentence to feature
3 Optimal transport
GAN can be interpreted in the framework of optimal transport theory, and it has been shown that the Earth-Mover’s Distance (EMD) is a good objective for generative modeling . Originally applied in content-based image retrieval tasks , EMD is well-known for comparing multidimensional distributions that are used to describe the different features of images (, brightness, color, and texture content). It is defined as the ground distance (i.e., cost function) between every two perceptual features, extending the notion of a distance between single elements to a distance between sets of elements. Specifically, consider two probability distribution and ; EMD can be then defined as:
where denotes the set of all joint distributions with marginals and , and is the cost function (e.g., Euclidean or cosine distance). Intuitively, EMD is the minimum cost that has to transport from to .
Feature Mover GAN
We propose a new GAN framework for discrete text data, called feature mover GAN (FM-GAN). The idea of optimal transport (OT) is integrated into adversarial distribution matching. Explicitly, the original critic function in GANs is replaced by the Earth-Mover’s Distance (EMD) between the sentence features of real and synthetic data. In addition, to handle the intractable issue when computing (2) , we define the Feature-Mover’s Distance (FMD), a variant of EMD that can be solved tractably using the Inexact Proximal point method for OT (IPOT) algorithm . In the following sections, we discuss the main objective of our model, the detailed training process for text generation, as well as extensions. Illustration of the framework is shown in Figure 1.
where and are the constraints, and represents the Frobenius dot-product. In this work, the transport cost is defined as the cosine distance: , and is the cost matrix such that . Note that during training, we set as the mini-batch size.
We propose to use the Inexact Proximal point method for Optimal Transport (IPOT) algorithm to compute the optimal transport matrix , which provides a solution to the original optimal transport problem (3) . Specifically, IPOT iteratively solves the following optimization problem:
Notably, unlike the Sinkhorn algorithm , we do not need to back-propagate the gradient through the proximal point iterations, which is justified by the Envelope Theorem (see the Supplementary Material (SM)). This accelerates the learning process significantly and improves training stability .
2 Adversarial distribution matching with FMD
To integrate FMD into adversarial distribution matching, we propose to solve the following mini-max game:
where is the sentence feature extractor, and is the sentence generator. We call this feature mover GAN (FM-GAN). The detailed training procedure is provided in Algorithm 2.
where is the hidden unit updated recursively through the LSTM cell: , is a decoding matrix, defines the distribution over the vocabulary. Note that, distinct from a traditional sentence generator, here, the argmax operation is used, rather than sampling from a multinomial distribution, as in the standard LSTM. Therefore, all randomness during the generation is clamped into the noise vector .
The generator cannot be trained, due to the non-differentiable function argmax. Instead, an soft-argmax operator is used as a continuous approximation:
3 Extensions to conditional text generation tasks
Style transfer Our FM-GAN model can be readily generalized to conditional generation tasks, such as text style transfer . The style transfer task is essentially learning the conditional distribution and , where and represent the labels for different styles, with and sentences in different styles. Assuming and are conditionally independent given the latent code , we have:
Equation (8) suggests an autoencoder can be applied for this task. From this perspective, we can apply our optimal transport method in the cross-aligned autoencoder , by replacing the standard GAN loss with our FMD critic. We follow the same idea as to build the style transfer framework. is our encoder that infers the content from given style and sentence ; is our decoder that generates synthetic sentence , given content and style . We add the following reconstruction loss for the autoencoder:
where and are the empirical data distribution for each style. We also need to implement adversarial training on the generator with discrete data. First, we use the soft-argmax approximation discussed in Section 3.2; second, we also use Professor-Forcing algorithm to match the sequence of LSTM hidden states. That is, the discriminator is designed to discriminate with real sentence . Unlike which uses two discriminators, our model only needs to apply the FMD critic twice to match the distributions for two different styles:
where is the learned word embedding matrix. The final objective function for this task is: , where is a hyperparameter that balances these two terms.
Unsupervised decipher Our model can also be used to tackle the task of unsupervised cipher cracking by using the framework of CycleGAN . In this task, we have two different corpora, i.e., denotes the original sentences, and denotes the encrypted corpus using some cipher code, which is unknown to our model. Our goal is to design two generators that can map one corpus to the other, i.e., , . Unlike the style-transfer task, we define and as two sentence feature extractors for the different corpora. Here we denote to be the empirical distribution of the original corpus, and to be the distribution of the encrypted corpus. Following , we design two losses: the cycle-consistency loss (reconstruction loss) and the adversarial feature matching loss. The cycle-consistency loss is defined on the feature space as:
The final objective function for the decipher task is: , where is a hyperparameter that balances the two terms.
Related work
GAN for text generation SeqGAN , MaliGAN , RankGAN , and MaskGAN use reinforcement learning (RL) algorithms for text generation. The idea behind all these works are similar: they use the REINFORCE algorithm to get an unbiased gradient estimator for the generator, and apply the roll-out policy to obtain the reward from the discriminator. LeakGAN adopts a hierarchical RL framework to improve text generation. However, it is slow to train due to its complex design. For GANs in the RL-free category, GSGAN and TextGAN use the Gumbel-softmax and soft-argmax trick, respectively, to deal with discrete data. While the latter uses MMD to match the features of real and synthetic sentences, both models still keep the original GAN loss function, which may result in the gradient-vanishing issue of the discriminator.
GAN with OT Wasserstein GAN (WGAN) applies the EMD by imposing the constraint on the discriminator, which alleviates the gradient-vanishing issue when dealing with continuous data (i.e., images). However, for discrete data (i.e., text), the gradient still vanishes after a few iterations, even when weight-clipping or the gradient-penalty is applied on the discriminator . Instead, the Sinkhorn divergence generative model (Sinkhorn-GM) and Optimal transport GAN (OT-GAN) optimize the Sinkhorn divergence , defined as an entropy regularized EMD (2): , where is the entropy term, and is the hyperparameter. While the Sinkhorn algorithm is proposed to solve this entropy regularized EMD, the solution is sensitive to the value of the hyperparameter , leading to a trade-off between computational efficiency and training stability. Distinct from that, our method uses IPOT to tackle the original problem of OT. In practice, IPOT is more efficient than the Sinkhorn algorithm, and the hyperparameter in (4) only affects the convergence rate .
Experiment
We apply the proposed model to three application scenarios: generic (unconditional) sentence generation, conditional sentence generation (with pre-specified sentiment), and unsupervised decipher. For the generic sentence generation task, we experiment with three standard benchmarks: CUB captions , MS COCO captions , and EMNLP2017 WMT News .
Since the sentences in the CUB dataset are typically short and have similar structure, it is employed as our toy evaluation. For the second dataset, we sample sentences from the original MS COCO captions. Note that we do not remove any low-frequency words for the first two datasets, in order to evaluate the models in the case with a relatively large vocabulary size. The third dataset is a large long-text collection from EMNLP2017 WMT News Dataset. To facilitate comparison with baseline methods, we follow the same data preprocessing procedures as in . The summary statistics of all the datasets are presented in Table 1.
For conditional text generation, we consider the task of transferring an original sentence to the opposite sentiment, in the case where parallel (paired) data are not available. We use the same data as introduced in . For the unsupervised decipher task, we follow the experimental setup in CipherGAN and evaluate the model improvement after replacing the critic with the proposed FMD objective.
We employ test-BLEU score , self-BLEU score , and human evaluation as the evaluation metrics for the generic sentence generation task. To ensure fair comparison, we perform extensive comparisons with several strong baseline models using the benchmark tool in Texygen . For the non-parallel text style transfer experiment, following , we use a pretrained classifier to calculate the sentiment accuracy of transferred sentences. We also leverage human evaluation to further measure the quality of the transferring results. For the deciphering experiment, we adopt the average proportion of correctly mapped words as accuracy as proposed in . Our code will be released to encourage future research.
In general, when evaluating the performance of different models, we desire high test-BLEU score (good quality) and low self-BLEU score (high diversity). Both scores should be considered: (i) a high test-BLEU score together with a high self-BLEU score means that the model might generate good sentences while suffering from mode collapse (i.e., low diversity); (ii) if a model generates sentences randomly, the diversity of generated sentence could be high but the test-BLEU score would be low. Figure 2 is used to compare the performance of every model. For each subplot, the -axis represents test-BLEU, and the -axis represents self-BLEU (here we only show BLEU-3 and BLEU-4 figures; more quantitative results can be found in the SM). For the CUB and MS COCO datasets, our model achieves both high test-BLEU and low self-BLEU, providing realistic sentences with high diversity. For the EMNLP WMT dataset, the synthetic sentences from SeqGAN, RankGAN, GSGAN and TextGAN is less coherent and realistic (examples can be found in the SM) due to the long-text nature of the dataset. In comparison, our model is still capable of providing realistic results.
To further evaluate the generation quality based on the EMNLP WMT dataset, we conduct a human Turing test on Amazon Mechanical Turk; 10 judges are asked to rate over 100 randomly sampled sentences from each model with a scale from 0 to 5. The means and standard deviations of the rating score are calculated and provided in Table 2. We also provide some examples of the generated sentences from LeakGAN and our model in Table 3. More generated sentences are provided in the SM.
2 Non-parallel text style transfer
Table 4 presents the sentiment transfer results on the Yelp review dataset, which is evaluated with the accuracy of transferred sentences, determined by a pretrained CNN classifier . Note that with the same experimental setup as in , our model achieves significantly higher transferring accuracy compared with the cross-aligned autoencoder (CAE) model . Moreover, our model even outperforms the controllable text generation method and BST , where a sentiment classifier is directly pre-trained to guide the sentence generation process (on the contrary, our model is trained in an end-to-end manner and requires no pre-training steps), and thus should potentially have a better control over the style (i.e., sentiment) of generated sentences . The superior performance of the proposed method highlights the ability of FMD to mitigate the vanishing-gradient issue caused by the discrete nature of text samples, and give rises to better matching between the distributions of reviews belonging to two different sentiments.
Human evaluations are conducted to assess the quality of the transferred sentences. In this regard, we randomly sample 100 sentences from the test set, and 5 volunteers rate the outputs of different models in terms of their fluency, sentiment, and content preservation in a double blind fashion. The rating score is from 0 to 5. Detailed results are shown in Table 4. We also provide sentiment transfer examples in Table 5. More examples are provided in the SM.
3 Unsupervised decipher
CipherGAN uses GANs to tackle the task of unsupervised cipher cracking, utilizing the framework of CycleGAN and adopting techniques such as Gumbel-softmax that deal with discrete data. The implication of unsupervised deciphering could be understood as unsupervised machine translation, in which one language might be treated as an enciphering of the other. In this experiment, we adapt the idea of feature mover’s distance to the original framework of CipherGAN and test this modified model on the Brown English text dataset .
The Brown English-language corpus has a vocabulary size of over one million. In this experiment, only the top most frequent words are considered while the others are replaced by an “unknown” token. We denote this modified word-level dataset as Brown-W200. We use Vigenère to encipher the original plain text. This dataset can be downloaded from this repositoryhttps://github.com/for-ai/CipherGAN.
For fair comparison, all the model architectures and parameters are kept the same as CipherGAN while the critic for the discriminator is replaced by the FMD objective as shown in (3). Table 6 shows the quantitative results in terms of average proportion of words mapped in a given sequence (i.e., deciphering accuracy). The baseline frequency analysis model only operates when the cipher key is known. Our model achieves higher accuracy compared to the original CipherGAN. Note that some other experimental setups from are not evaluated, due to the extremely high accuracy (above ); the amount of improvement would not be apparent.
Conclusion
We introduce a novel approach for text generation using feature-mover’s distance (FMD), called feature mover GAN (FM-GAN). By applying our model to several tasks, we demonstrate that it delivers good performance compared to existing text generation approaches. For future work, FM-GAN has the potential to be applied on other tasks such as image captioning , joint distribution matching , unsupervised sequence classification , and unsupervised machine translation .
Acknowledgments
This research was supported in part by DARPA, DOE, NIH, ONR and NSF.
References
Appendix A Proof
In this section, we use Envelope theorem to prove that the gradient for the transport matrix is in our algorithm.
Then assume function is also continuous and differentiable, defined as the derivative of over is:
Assume the parameters in is , and the parameters in is . Using Envelope theorem, the gradient respect to is:
Similarly, the gradient respect to is:
Eqn. (A) and (14) show the derivative over the flow matrix is not computed.
Appendix B Additional experimental results
The detailed quantitative result is shown in Table 8, 8, 10, 10, 12, 12.
B.2 Qualitative results
The samples of sentiment transfer can be found in Table 13. The samples of text generation of different models can be found in Table 14, 15, 16.