Multi-Attribute Controlled Text Generation with Contrastive-Generator and External-Discriminator (2022)

Abstract: Though existing researches have achieved impressive results in controlled text generation, they focus mainly on single-attribute control. However, in applications like automatic comments, the topic and sentiment need to be controlled simultaneously. In this work, we propose a new framework for multi-attribute controlled text generation. To achieve this, we design a contrastive-generator that can effectively generate texts with more attributes. In order to increase the convergence of the text on the desired attributes, we adopt an external-discriminator to distinguish whether the generated text holds the desired attributes. Moreover, we propose top-n weighted decoding to further improve the relevance of texts to attributes. Automated evaluations and human evaluations show that our framework achieves remarkable controllability in multi-attribute generation while keeping the text fluent and diverse. It also yields promising performance on zero-shot generation.

## introduction large pre-trained language models (lm) have achieved impressive performance in natural language generation tasks @xcite @xcite . however, they suffer from the limitation of lacking controllability in practical applications, for their generated texts may have toxic meanings or undesired topics. hence how to control the text generation with desired attributes as topic, sentiment, style, etc., has been further studied. to effectively control the desired attribute of the generated text, class-conditional language models (cc-lm) such as conditional transformer language (ctrl) model @xcite generate texts conditioned on control codes. but the controlled ability are restricted since the control * corresponding author movie positive: in the end hitchcock brings one of those rare hollywood thrillers that i have been craving for a long time: the suspense thriller. it is one of my favorite genres and movies because you can always be sure that something exciting will happen in the ending (and sometimes it does!). i think it is also a classic hitchcock masterpiece. automobile negative: in the past sixty years, gm cars have gotten worse, because gm engineers were worse. now they are just as bad as ford's. but gm still makes good cars. i'm sorry but car makers need to go back to making things people want, like lawnmowers.it's a big step backwards. in light of the problem, we propose a multiattribute controlled framework that can effectively control topic and sentiment of the text at the same time. although there are previous researches @xcite @xcite about multi-attribute controlled text generation, they only conceptually raise the task but focus mainly on single-attribute control. the challenges of multi-attribute control lie in 1) the fusion of attributes and 2) the increased categories to be generated. to generate texts with desired topic and sentiment, we design a contrastive-generator with three negative samples in contrast to one positive sample. since the generator may generate texts with different categories, we train an externaldiscriminator to increase the convergence of texts on desired attributes. in the decoding phase, a topn weighted decoding is proposed to improve the ability of controlled text generation. we summarize the contributions of this work as follows: ## related work given a control code a, the purpose of controlled text generation is to generate text x by calculating the probability of p(x|a). there are mainly two categories: the first retrains language model with control codes, while the second changes the weight of the specific words for controlled text generation. models trained or fine-tuned @xcite @xcite on a large number of conditioned codes can achieve remarkable effectiveness for controlled text generation. however, the large training data and the computation cost are the heavy burdens. methods with a smaller lm @xcite @xcite to guide generation from large lm can generate text for sentiment control or topic control. gedi @xcite uses bayes rule to compute classification likelihoods of tokens, and its generative discriminator performs well on controlled text generation. similarly, a future discriminator @xcite is used to determine whether the desired attribute will appear in the future text. expert lm and anti-expert lm @xcite are utilized to reweight the predictions of the large lm. considering the promising results of the discriminator, a semantic discriminator @xcite is used to discriminate the coherence with external conditioning. to get a better attribute representation, @xcite introduces a new alignment function for sentiment control. a sentence-level emotion classifier @xcite ) is adopted to generate comments with the target emotion. the methods of retraining language models tend to produce fluent texts, but they need large labeled datasets for training. weighted decoding is also a useful method to control text generation with language models. these methods @xcite @xcite , which increase the probability of tokens that are similar to the target keyword or topic, control the desired attributes of texts flexibly. metropolis-hastings sampling is used to generate texts with more keywords @xcite . but since these methods do not update lm, it will decrease the fluency of the generated texts. the following works @xcite @xcite @xcite conduct constrained generation under gradient guidance. to control the sentiment better, the method in @xcite focuses on controlling more emotion categories and emotion intensity. however, gradient-based methods may lead to more computation to calculate the word's probability. although modifying the distribution of language models is a flexible way for controlled text generation, it will sacrifice the texts quality. our method draws on the above two thoughts. we design a contrastive-generator and an externaldiscriminator by retraining the language model to control text generation while keeping the text fluency. and we also propose top-n weighted decoding to increase the correlation of attributes. ## methodology as is illustrated in figure 1 , our method is composed of three main modules. we use ctrl as cc-lm to generate one positive sample and three negative samples for the contrastive-generator. then the contrastive-generator (subsection 3.1) outputs classification probabilities that guide the generation of the pre-trained lm. since there are multiple attributes to be considered in multi-attribute controlled text generation, we use an externaldiscriminator (subsection 3.2) to estimate whether the generated text achieves the target attributes. to ensure the text fluency, the top-n weighted decoding (subsection 3.3) recalculates the probabilities of the n most probable words. the details of these modules are described in the following subsections. ## experiment we conduct experiments on the task of multiattribute controlled text generation (subsection 4.1) and zero-shot generation (subsection 4.2) to evaluate the performance of our framework. the ablation experiments (subsection 4.3) are also presented to analyze the importance of each module. ## conclusion and future work in this paper, we propose an effective framework for multi-attribute controlled text generation. experiments and further analysis demonstrate that the contrastive-generator and the externaldiscriminator perform essentially on multi-attribute generation and zero-shot generation. and the controllability of the desired attributes is further improved by our proposed top-n weighted decoding without losing the quality of texts. we also conduct the ablation experiment, showing the importance of each module. in addition to the topic and sentiment control, our framework is capable of applying to other multi-attribute control. in the future, we will generalize our model to generate texts with other attributes, e.g. writing styles and toxicity, making the generation more safer and more qualified.