Text Style Transferring via Adversarial Masking and Styled Filling (2022)

Abstract: Text style transfer is an important task in natural language processing with broad applications. Existing models following the masking and filling scheme suffer two challenges: the word masking procedure may mistakenly remove unexpected words and the selected words in the word filling procedure may lack diversity and semantic consistency. To tackle both challenges, in this study, we propose a style transfer model, with an adversarial masking approach and a styled filling technique (AMSF). Specifically, AMSF first trains a mask predictor by adversarial training without manual configuration. Then two additional losses, i.e. an entropy maximization loss and a consistency regularization loss, are introduced in training the word filling module to guarantee the diversity and semantic consistency of the transferred texts. Experimental results and analysis on two benchmark text style transfer data sets demonstrate the effectiveness of the proposed approaches.

## introduction stylistic attributes of natural language text have intrigued researchers in natural language processing (nlp) for a long time. text style transfer aims to convert the text into a target style while preserving the content of the source text, which has broad industrial applications such as computer-aided writing (klahold and fathi, 2020) and advertising systems @xcite . due to the lack of parallel data, text style transfer is usually treated as an unsupervised learning task. one of the mainstream approaches is to exploit the autoencoder to disentangle the style and content representation of the source text, then use the decoder to generate a transferred text with the disentangled content representation and the target style @xcite @xcite . the weakness of such * corresponding author a sequence-to-sequence manner is that the model usually performs poorly on content preservation because the intrinsic of generative models bring a significant difference between source and target text. another branch of models follows the masking and filling scheme @xcite @xcite , which first explicitly masks out the stylistic words of the source style in the text and then replaces them with words from the target style. these models usually use either average attention scores @xcite or the higher frequency ratio as criteria to select the stylistic words in the word masking procedure. however, these masking approaches may mistakenly remove the non-stylistic words when the attention distribution is insignificant @xcite . when filling the masked words, previous works utilize bert @xcite to fill the masked positions with the supervision from the style classifier @xcite or retrieve words with similar attributes @xcite from the target domain. the limitation of these filling approaches is that the diversity and semantic consistency of filled words are not guaranteed. we argue that diversity and semantic consistency are significant in text style transfer. an ideal style transfer model should replace source stylistic words with their semantically-consistent counterpart in the target domain. for example, in sentiment transfer task, it is more reasonable to transfer "fast" to "slow" rather than "poor", and "worst" is preferred to be transferred from "best" instead of "good". to overcome the imprecise word masking and the limitation of lacking diversity and consistency in word filling, in this study, we propose an adversarial masking approach and a styled filling technique for the text style transfer task. specifically, to improve the word masking quality, we introduce an adversarial gating strategy in training the mask predictor. the mask predictor is trained as a gen-erator in an adversarial way with a discriminator identifying the source style from the masked sequence. in addition, the number of masked words is also restricted to prevent the mask predictor from sacrificing non-stylistic words. the mask predictor trained with an adversarial gating strategy is experimentally shown to be effective in selecting stylistic words and flexible in controlling of masked ratio without additional statistical or manually labelled information. to improve the diversity and consistency of the filled words, we develop a styled filling approach based on bert masked language model to predict the substituting vocabulary distribution. this approach introduces an entropy-based diversity loss and a semantic-based consistency loss to encourage the word-level language diversity and semantic consistency. language diversity of styled filling is realized by punishing the low diversity of generated target stylistic words. the motivation to incorporate consistency loss is that source stylistic words usually share similar context with their antonyms and have closer word embedding vectors compared to other words in the target domain. the designed consistency loss can shorten the distance between transferred word embedding and source stylistic word embedding as the guidance for our model to predict the antonyms. empirical studies show that our model amsf outperforms existing approaches in terms of the overall score of content preservation and transfer accuracy. in addition, further comprehensive analysis of the diversity and the semantic consistency of generated text confirms the effectiveness of the proposed approach. in summary, the contributions of this study are as follows: ## related work due to the scarcity of parallel data in text style transfer, the mainstream recent research has regarded the task of text style transfer as an unsupervised learning task. in recent works, one category of the methods aims to first implicitly filter out the style-related words in the text by learning a latent representation of content and style and then generating new text of the target style. @xcite learns the latent representation of text utilizing variational autoencoder (vae) (kingma and welling, 2013) framework and utilizes a style classifier to learn a style attribute vector. @xcite leverages an adversarial network to train a content encoder, the encoded content vector is then transferred by the style-specific decoder. @xcite adopts vae to separate the style representation and content representation, with the decoder directly taking the concatenation of the encoded content representation and target style representation as input. there is a branch of study that performs text style transfer task without disentangling the source text into the style and content. for instance, the dual structure, which learns the source-to-target and target-to-source mappings, is applied to achieve the goal. one of the works @xcite trains the transfer models in the way of training de-noising autoencoders (dae) @xcite with noisy text using neighbourhood sampling approach and the models are trained cyclically to reconstruct origin text from noisy input. another mainstream of the works attempts to explicitly replace the keywords and generate a text of the target style. identifying style-related words in the given text is of great importance in this method. while @xcite selects the stylistic words according to their frequency in text from a specific style, most early works utilize the attention mechanism as an indicator of stylistic words. @xcite and @xcite take the average attention score as the threshold for filtering out the style-related words. @xcite calculates attention on each (layer, head) pair of transformer @xcite and selects one pair with the highest score. @xcite also leverages attention score as style information, but the reversed attention is taken as weights on content representation instead of masking words directly in this work. ## conclusion in this paper, we proposed adversarial masking and styled filling model amsf to address the problem of text style transfer with unparalleled corpus. amsf improves the word masking quality by training the mask predictor in an adversarial way and promotes the diversity and semantic consistency of generated sentences by regularization losses. the experimental results on yelp and imdb data sets demonstrate that our model is competitive in terms of content consistency and transfer strength. human evaluation results further corroborate our style transfer model's superiority as well as competitiveness in fluency. the effectiveness of our proposed approach in promoting language diversity and semantic consistency is also verified by the ablation study.