C o CGAN : Contrastive Learning for Adversarial Category Text Generation (2022)

Abstract: The task of generating texts of different categories has attracted more and more attention in the area of natural language generation recently. Meanwhile, generative adversarial net (GAN) has demonstrated its effectiveness on text generation, and is further applied to category text generation in later works. Different from existing methods, which mainly consider the pairwise relations between the text embedding and the corresponding fixed one-hot class label (data-to-class relations), this paper proposes a novel Contrastive Category Generative Adversarial Net (CoCGAN) to incorporate contrastive learning into adversarial category text generation, considering more flexible data-to-class relations as well as relations between the multiple text embeddings in the same batch (data-to-data relations). The discriminator of CoCGAN discriminates the authenticity of given samples and optimizes a contrastive learning objective to capture both more flexible data-to-class relations and data-to-data relations among training samples. Accordingly, the generator tries to produce more realistic samples which can confuse the discriminator. Experimental results on both synthetic and real category text generation datasets demonstrate that CoCGAN can achieve significant improvements over the baseline category text generation models.

## introduction category text generation is the task of generating coherent and meaningful text with different categories and has received increasing attention in many natural language processing applications, such as sentiment analysis @xcite and dialogue generation @xcite . it is a further expression of machine intelligence, and makes the generated texts more friendly to humans. category text generation is a generalization of sentimental * corresponding author text generation and can be seen as a type of conditional text generation. this task focuses on how to integrate the auxiliary category information with the conventional text generation frameworks. recently, generative adversarial net (gan) @xcite , where the discriminator is designed to guide the generator, is combined with the reinforcement learning (rl) @xcite methods to generate discrete text sequences for general text generation with some remarkable successes @xcite @xcite . different from the general text generation task, category text generation mainly focuses on automatically generating a variety of controllable texts according to the specified categories. however, it is challenging to incorporate the category information into the sentences and design an appropriate objective for generating texts of different categories simultaneously. in previous works, attempts have been made to extend the general text generation models to category text generation @xcite @xcite . however, they only consider relations between the text embeddings and the class labels with simple constraints (datato-class relations). among them, sentigan @xcite heavily relies on the discriminator based on a (k + 1)-class classifier, which classifies between "generated" and k real classes. but it ignores the fact that each generated sample involves the degree of authenticity as well as the probability of belonging to a certain category simultaneously, therefore it is less reasonable to directly set the discriminator as a (k + 1)-class classifier. to address this issue, csgan @xcite splits the discriminator into an authenticity discriminator and a category classifier, and optimize the generator with reward-based policy gradient strategy. nevertheless, both the discriminators of sentigan and csgan are still limited by the simple category constraints (i.e., cross-entropy loss using fixed one-hot class label as target). more recently, catgan proposes a category-aware model with a generator based on the relational memory core (rmc) to generate category texts. however, its discriminator still focuses on vanilla data-to-class relations and ignores relations between these text embeddings in the same batch @xcite . in this paper, inspired by recent application of contrastive learning in conditional image generation @xcite , we propose a novel adversarial category text generation framework, namely contrastive category generative adversarial net (cocgan), to further exploit the category information. different from sentigan, which uses multiple generators, we adopt a conditional generator @xcite to simplify the model, where an additional class label embedding is set as input to control the type of the generated category text. following @xcite , we consider the sequence generation procedure as a sequential decision making process and the generator is regarded as a stochastic parametrized policy. regarding the discriminator, since each generated sample is associated with a real class label and it is rather rough to simply mark it as "generated", the proposed discriminator is divided into two parts: an authenticity discriminator and a contrastive category projector. the authenticity discriminator is a conventional gan discriminator which is designed as a binary classifier to judge whether the input text is real or not. as for the contrastive category projector, we abandon the conventional way which adopts the cross-entropy loss as the training objective and take class label embeddings into account for more flexible learning. specifically, the discriminator leverages contrastive learning to pull the text embeddings closer to their corresponding class label embeddings. furthermore, we also consider relations between the text embeddings which share the same class labels. in other words, the contrastive category projector aims to pull the multiple text embeddings, which are in the same batch, closer to each other when their class labels are the same, while pushing away from each other otherwise. as benefits of the novel contrastive learning paradigm, the discriminator can capture not only more flexible data-to-class relations but also datato-data relations among training samples. during adversarial training, we adopt monte carlo tree search to approximate the state-action value function and the penalty-based @xcite training objective is used to update the generator with policy gradient strategy @xcite , where we integrate the output of the authenticity discriminator and the contrastive category projector to obtain the overall penalty. we conduct category text generation experiments on both synthetic and real category datasets and adopt multiple metrics to evaluate the quality of the generated texts. we also compare the proposed cocgan with several state-of-the-art category text generation models, including senti-gan and catgan. experimental results on three datasets (i.e., movie reviews, amazon reviews and synthetic datasets) demonstrate that our model consistently outperforms the state-of-the-art models. the contributions of this work are three-fold: ## related work text generation is an important task in natural language processing and has received more and more attention in many fields recently @xcite . traditional text generation models based on recurrent neural network (rnn) @xcite generate each token of a sentence conditioned on the previous tokens and the current hidden state. nevertheless, the training paradigm maximum likelihood estimation (mle) may suffer from exposure bias @xcite , which is due to the inherent difference between the training stage and the inference stage of text generation models trained via mle. scheduled sampling is proposed by @xcite to solve it but soon proved to be inconsistent @xcite . to alleviate this issue, some works adopt generative adversarial net (gan) @xcite , which has achieved significant successes on computer vision @xcite . in gan, the discriminator learns to distinguish whether a given sample is real or not, and the generator learns to confuse the discriminator by generating high quality data. nevertheless, gan is designed for differentiable data, which conflicts with the discrete nature of text generation. to tackle the above non-differentiability problem, reinforcement learning is introduced in seq-gan @xcite and leakgan @xcite , where the discriminator guides the generator with the reward signal. and this training paradigm is widely adopted @xcite . alternatively, maskgan @xcite uses the actor-critic algorithm to fill in the missing text conditioned on the surrounding context. rankgan @xcite replaces the conventional binary classifier with a ranking model as the discriminator. a different direction to address the non-differentiability problem is approximation methods. specifically, @xcite and @xcite apply an annealed softmax to approximate the argmax operation. while @xcite and @xcite propose to use the gumbel-softmax relaxation to approximate the categorical distribution. the aforementioned methods mostly focus on general text generation. for the task of category text generation, csgan @xcite proposes a descriptor which consists of a binary discriminator and a classifier that aims to distinguish the categories of the given sentence. however, the adversarial generator optimization of csgan still adopts the reward-based training objective, which is the same as seqgan and restricts the diversity of the generated sentences. meanwhile, senti-gan @xcite introduces multiple generators where each generator focuses on generating samples with a specified sentiment label. in addition, sentigan proposes a novel penaltybased training objective to improve the diversity of the generated samples. however, the multiple generators of sentigan will increase the complexity of the model with the increase of category numbers. more recently, catgan @xcite introduces a category-aware model for category text generation. nevertheless, the discriminator of cat-gan still focuses on vanilla data-to-class relations. as can be noticed, in all the methods discussed above, data-to-data relations among the training batch are ignored. besides these gan-based methods, some works also make various attempts to improve the conventional conditional generative models @xcite @xcite , and they are orthogonal to our model which focuses on improving the discriminator to better guide the conditional generator. and these models can replace the conditional generator of our model for further improvements. thus, in this work, we mainly focus on the gan-based methods. recently, many unsupervised representation learning methods are proposed based on the principle of contrastive learning @xcite @xcite @xcite , and contrastive learning paradigm is firstly adopted for adversarial image generation in @xcite . besides, contrastive learning is also applied to conventional conditional text generative models @xcite . to effectively leverage the class label information, the proposed cocgan makes the first attempt to integrate contrastive learning into the discriminator for adversarial category text generation. by exploring both more flexible datato-class relations and data-to-data relations with contrastive learning, cocgan achieves significant improvements over previous works, including the state-of-the-art model catgan. ## methodology in this section, we propose cocgan by adapting contrastive learning to adversarial category text generation. we begin with introducing the framework of the generator (sec. 3.1). then, in order to consider both more flexible data-to-class relations and data-to-data relations, we split the discriminator into an authenticity discriminator and a contrastive category projector (sec. 3.2) to introduce a label-incorporated contrastive loss. accordingly, a penalty-based contrastive learning paradigm is designed to optimize the generator during adversarial training (sec. 3.3). finally, we propose the contrastive category generative adversarial net (coc-gan) for category text generation (sec. 3.4). ## conclusion this paper proposes a novel contrastive learning paradigm for adversarial category text generation (cocgan). in cocgan, a novel labelincorporated contrastive loss is introduced to further exploit more flexible data-to-class relations and data-to-data relations in the training batch, and the category text generation model is enhanced accordingly. it is worth noting that cocgan focuses on the perspective of adversarial learning, therefore it is orthogonal to some works which try to optimize the conditonal text generative models themselves, and can be applied to them for further improvements. extensive experiments demonstrate that our proposed model outperforms the state-ofthe-art adversarial category text generation models with better quality and diversity.