Emotion-Conditioned Text Generation through Automatic Prompt Optimization (2023)

Abstract: Conditional natural language generation methods often require either expensive fine-tuning or training a large language model from scratch. Both are unlikely to lead to good results without a substantial amount of data and computational resources. Prompt learning without changing the parameters of a large language model presents a promising alternative. It is a cost-effective approach, while still achieving competitive results. While this procedure is now established for zero- and few-shot text classification and structured prediction, it has received limited attention in conditional text generation. We present the first automatic prompt optimization approach for emotion-conditioned text generation with instruction-fine-tuned models. Our method uses an iterative optimization procedure that changes the prompt by adding, removing, or replacing tokens. As objective function, we only require a text classifier that measures the realization of the conditional variable in the generated text. We evaluate the method on emotion-conditioned text generation with a focus on event reports and compare it to manually designed prompts that also act as the seed for the optimization procedure. The optimized prompts achieve 0.75 macro-average F1 to fulfill the emotion condition in contrast to manually designed seed prompts with only 0.22 macro-average F1.

## introduction emotions are fundamental in communication, where they play an important role in transferring meaning and intent @xcite . emotionconditioned natural language generation models aim at improving human-computer interaction, by generating text that is not limited to conveying propositional information. however, state-of-theart conditional generation models require a large amount of data and computational power to achieve models that allow for a fine-grained control over the generated texts @xcite i. input prompt generated text 0 text with disgust disgust is a character in inside out 1 text expressing disgust disgusting 2 write a text to express disgust a look of disgust came over his face. in areas like text classification or structured prediction, prompt optimization has established itself as a zero-or few-shot learning paradigm @xcite @xcite , also in emotion analysis @xcite @xcite . here, only parameters that are concatenated to the input are optimized and the large language model's parameters are frozen. such models, therefore, exploit encoded knowledge in models such as flan @xcite , gpt-3 @xcite and alpaca @xcite more explicitly than finetuning them for the task at hand. the optimization method learns "how to use" a model, not "how to change" it. in recent instruction-based models, the prompt is an instruction to elicit a desired response. the instruction serves as a starting point for generating text that aligns with the intended task. prompting in text classification @xcite usually includes the instruction (e.g., "classify the text. . . ") and the label representation (e.g., "positive", "negative"). summarization has been represented as an instruction by appending "tl;dr" or "summarize" @xcite . for text generation that translates tables to text, li and liang (2021) proposed to tune a prefix prompt to accomplish the task. in machine translation, prompts typically mention the source and target language, such as "translate english to german" @xcite . the task of prompt optimization can be formulated in various directions. the goal is to find the optimal sequence of tokens to represent the prompt for a specific model (e.g., flan) and task (e.g., summarization), while keeping the model weights unchanged. autoprompt @xcite defines the prompt optimization as "fill-in-the-blanks" based on a gradient-guided search. openprompt @xcite provides a toolkit for training prompts using a template dataset, along with corresponding verbalizers for different classes. @xcite use reinforcement learning to infer a successful prompt variation strategy. a different approach for optimization is fine-tuning the model to improve its performance with a specific prompt, while keeping the prompt unchanged @xcite . in contrast to most previous work, we use models that have been fine-tuned to solve instruction-based tasks; in our case to generate emotion-conditioned texts. this comes with distinct challenges because the loss function cannot be determined by a single expected label (e.g., positive or negative). in our work, we use a classifier that measures the fulfillment of the condition as a source to calculate the value of an objective function. the optimization procedure that we propose is an evolutionary optimization method @xcite . next to the objective function, an important component are actions that allow changes to a prompt to explore the search space. ## methods we propose a method (summarized in pseudocode in algorithm 1) for text generation conditioned on emotions using prompt optimization. it involves an iterative optimization procedure with three modules, namely prompt modification, text generation, and prompt evaluation. we describe the modules in section 2.1 and the iterative optimization in section 2.2. ## experiments section 3.1 explains the experimental settings used to optimize an initial prompt that we assume to be provided by a user. section 3.3 validates the proposed method by showing that emotionconditioned text generation improves when using the optimized prompt compared to the seed prompt. ## conclusion and future work in this study, we introduced the first automatic prompt optimization method for text generation conditioned on emotions. our approach involved three token operations: addition, replacement, and removal. we utilized a bleu score and an automatic classifier to filter and rank the modified prompts. we demonstrated that the optimized prompts led to a higher fulfillment of the intended this leads to important future work. while our approach improves emotion-conditioned text generation, there are several areas that need to be explored further. first, we need to explore different search techniques for prompt optimization (e.g., beam search). second, it is essential to compare the performance of the optimized prompts across different domains to assess the generalizability of our method. our evaluation is arguably comparably narrow, with only one seed prompt and one domain in which emotions are expressed. finally, it is crucial to analyze our approach by comparing it against a fine-tuned or trained model from scratch to evaluate its effectiveness and efficiency. another interesting direction of research would be to study in more detail how the expected domain of the generated texts (here: emotion self-reports) might be in conflict with the emotion condition and how that can be encoded in either the optimization process, the seed prompt selection or the objective functions, or in combinations of these parameters.