Prompt-and-Rerank: A Method for Zero-Shot and Few-Shot Arbitrary Textual Style Transfer with Small Language Models (2022)

Abstract: We propose a method for arbitrary textual style transfer (TST)—the task of transforming a text into any given style—utilizing general-purpose pre-trained language models. Our method, Prompt-and-Rerank, is based on a mathematical formulation of the TST task, decomposing it into three constituent components: textual similarity, target style strength, and fluency. Our method uses zero-shot or few-shot prompting to obtain a set of candidate generations in the target style, and then re-ranks them according to the three components. Our method enables small pre-trained language models to perform on par with state-of-the-art large-scale models while using two orders of magnitude less compute and memory. We also investigate the effect of model size and prompt design (e.g., prompt paraphrasing and delimiter-pair choice) on style transfer quality across seven diverse textual style transfer datasets, finding, among other things, that delimiter-pair choice has a large impact on performance, and that models have biases on the direction of style transfer.

## introduction textual style transfer (tst) refers to the task of transferring one stylistic aspect of a piece of text (e.g., sentiment polarity, formality, politeness, etc.) without changing its main semantic content, structure, or other attributes. traditionally, the natural language generation (nlg) community has approached each instantiation of style transfer as a distinct task, designing and training specialized models on style-specific training corpora. for example, sentiment transfer has been studied extensively (li et al. (2018); sudhakar et al. (2019); luo et al. (2019a), inter alia). this paradigm has restricted tst research to a limited, simple set of style choices with parallel corpora, which can often be solved adequately by word replacement (e.g., re-1 our code, data, and results are available at https:// github.com/suzgunmirac/prompt-and-rerank sentiment transfer input the food was low quality and thrown together quickly with little flavor. gpt-j-6b the food was delicious and prepared with a lot of care! input the staff is awesome and location is right in the heart of old town! gpt-j-6b the staff is terrible and location is in the middle of nowhere! @xmath0, because he hath wakened thy dog that hath lain asleep in the sun. gpt-j-6b you have cursed a man because he's coughed in the street, because he has woken your dog, which has been sleeping in the sun. input if thou art fickle, what dost thou with him that is renown'd for faith? gpt-j-6b if you are fickle, then what are you doing with that person who is known for being reliable? fluency and grammar correction input forexample, my cousin is 12years old. gpt-j-6b for example, my cousin is twelve years old. ## method: prompt-based arbitrary tst this section begins with a mathematical formalization of the task of textual style transfer. @xcite our formalization elucidates the three underlying components of the task, namely text similarity, target style strength, and fluency, and naturally leads us to prompt-and-rerank, our prompt-based re-ranking algorithm for solving tst. ## prompt construction in practice, we found the specific syntax and semantics of the prompt template significantly impact model performance. thus, we conducted a systematic investigation of the impact of different prompt design choices on the quality of tst generations. ## conclusion in this paper, we propose a novel formal framework for textual style transfer. this framework naturally leads us to a new method, which we denote prompt-and-rerank, that utilizes general-purpose pretrained language models to transform text into in arbitrary styles. in our experiments, we use our method to demonstrate that off-the-shelf, pretrained "small" language models, such as gpt-2, can perform arbitrary textual style transfer, without any additional model fine-tuning or prompt-tuning. additionally, we conduct an extensive investigation prompt phrasing and delimiter choice on transfer quality. in total, we hope that our work makes further research in this area more accessible to a broad set of researchers, both by alleviating the computational constraints of hundred-billion-parameter language models and by establishing a standard set of clean datasets for arbitrary text style transfer.