Formality Style Transfer with Shared Latent Space (2020)

Abstract: Conventional approaches for formality style transfer borrow models from neural machine translation, which typically requires massive parallel data for training. However, the dataset for formality style transfer is considerably smaller than translation corpora. Moreover, we observe that informal and formal sentences closely resemble each other, which is different from the translation task where two languages have different vocabularies and grammars. In this paper, we present a new approach, Sequence-to-Sequence with Shared Latent Space (S2S-SLS), for formality style transfer, where we propose two auxiliary losses and adopt joint training of bi-directional transfer and auto-encoding. Experimental results show that S2S-SLS (with either RNN or Transformer architectures) consistently outperforms baselines in various settings, especially when we have limited data.

## introduction the formality analysis of text plays an important role in natural language processing (nlp)-related applications, such as style analysis and human-computer interaction @xcite . with the advance of neural networks for sentence generation, it is possible to synthesize a new sentence, changing the formality style of an input sentence while retaining its meaning. this is referred to as formality style transfer in @xcite . @xcite in the meantime constructed the gyafc 2 dataset, where they make crowdsourcing efforts to manually write 119k formal sentences from informal ones (examples shown in in previous work, researchers have applied machine translation frameworks to style transfer when parallel data are available. for example, @xcite adopt phrase-based statistical machine translation, and @xcite employ sequence-to-sequence (seq2seq) neural networks. formality style transfer, however, is different from rich-resource machine translation mainly in two aspects. first, machine translation systems usually require massive parallel data for training, whereas the parallel corpus for formality style transfer is much smaller. the wmt-17 english-chinese corpus, for example, has 25m pairs @xcite , but gyafc has only ∼50k for each domain. second, a formality-transferred sentence closely resembles the original one. as shown in as a result, directly applying a sequence-to-sequence (seq2seq) model not only has the risk of overfitting to the training set, but also may fail to fully utilize the nature of informal and formal sentences. to tackle these problems, we propose a novel model s2s-sls, a sequence-to-sequence model with a shared latent space, for formality style transfer. in s2s-sls, we have a single encoder for both this work is licensed under a creative commons attribution 4.0 international license. license details: http:// creativecommons.org/licenses/by/4.0/ . informal sentence: formal sentence: i do not know are u ready for one ? i do not know. are you ready for one? sounds like a rhetorical question :) ## related work style transfer has drawn considerable attention in the past few years. it can be generally categorized into three settings: (1) with fully unlabeled data, (2) with style-labeled data, and (3) with parallel data. with fully unlabeled data. in this setting, the data are unlabeled, which could be raw text or images per se, and style transfer is accomplished in an unsupervised manner. for example, auxiliary losses of orthogonality and mutual information could help to learn independent features @xcite ; they have been shown to successfully disentangle features of color, rotation, etc. in image processing. in nlp applications, @xcite capture the most salient feature by detecting the global variance, and perform unsupervised style transfer of sentiment. however, such approach hardly works for the intriguing formality style. with non-parallel labeled data. by non-parallel labeled data, we mean that each data sample is annotated with its style label only. the content of different styles is generally the same in the corpus level, but for an individual data point, we do not have a style-transferred sentence with the same content. in sentiment-transfer sentence generation @xcite , for example, a sentence is labeled with its sentiment tag (positive vs. negative). however, there is no alignment between a positive sentence and a negative one for the same content (subject). with supervision signals of style labels, it is possible to learn style and/or content spaces. adversarial training @xcite ensures that a certain latent space is indistinguishable in different styles, facilitating style-transfer generation @xcite . @xcite use real-valued embedding to represent styles explicitly. @xcite and @xcite extend such approach by encoding both style and content spaces in a disentangled way. @xcite propose an editing-based approach bi-directional transfer figure 1: overview of our approach. our s2s-sls model has one encoder for all sentences, but two decoders for informal and formal styles, respectively. as also seen, our model has auxiliary matching losses in the shared latent space, and can be trained jointly with bi-directional tranfer and auto-encoding. to style transfer. in @xcite , a cycled reinforcement learning method is used to balance fluency and sentiment on unpaired data. our joint training is inspired by cycled training, but works in a different way with a paralleled corpus. recently, researchers propose to synthesize pseudo-parallel data for style transfer. zhang et al. (2018) build a word translation table by cross-domain word embeddings, and then use a phrased-based machine translation (pbmt) model to translate from one style to another. @xcite propose a denoising auto-encoding loss with online back-translation to generate pseudo-parallel data. with parallel data. if we have sentences of different styles for the same content, we call it a parallel dataset. in this case, the machine translation framework (phrase-based or neural method) can be adopted to transfer one style to another. @xcite transfer modern english to shakespeare's style. @xcite create the gyafc formality style transfer dataset, and have introduced several strong baselines by adopting phrase-based and neural machine translation with data augmentation techniques. @xcite and @xcite tackle the formality style transfer problem with a multitask learning framework. our paper follows the setting with parallel data, and extend the translation framework with a shared latent space for different styles and several matching losses. ## problem formulation suppose we have a parallel dataset d @xmath0, y i )} n @xmath1, where x @xmath2,1 , • • • , x i,s i ) is an informal sentence, and y @xmath3,1 , • • • , y i,t i ) is a formal sentence expressing the same meaning as x i . n is the number of pairs; s i and t i are the lengths of the respective sentence. the goal of formality style transfer is to train a generation model, transferring a sentence in one style to another. this includes transferring an unseen informal sentence x * to its formal expression y * , and vice versa. in real nlp tools such as writing assistants, it appears that informal-to-formal transfer makes more sense than formal-to-informal transfer. we follow @xcite and regard the informal-to-formal transfer as the major goal of formality style transfer. ## our approach our method generally follows the sequence-to-sequence (seq2seq) framework, but explores the shared latent space for both formal and informal sentences. we call our method seq2seq with shared latent space (s2s-sls). figure 1 depicts the overall framework of s2s-sls. it has a shared encoder f enc , but two decoders f i dec and f f dec for the informal and formal styles, respectively. we will then describe our matching losses in detail. they ensure that the shared latent space of formal and informal styles does capture semantic information while eliminating the style. we also introduce the joint training of informal-to-formal and formal-to-informal transfer, as well as auto-encoding training; they serve as a regularization for the model, which is important to formality style transfer when the data are limited. our method is applicable to different neural architectures, for example, recurrent neural networks (rnns) with the attention mechanism and transformer architectures, as used in our experiments. due to space limit, we will describe the details in appendix a. ## conclusion in this paper, we propose a novel sequence-to-sequence model with shared latent space for formality style transfer, called s2s-sls. we observe that the formality style transfer task is different from machine translation in the size of data and the relationship between source and target sequences. to address these issues, our s2s-sls model uses a single encoder to capture sentences of different formality styles, and our matching losses ensure that the latent space captures semantic information while eliminating style. experimental results show that our approach significantly improves baseline models in the data-limited setting. in the data-augmentation and pre-training scenarios where a large scale non-parallel corpus is used to augment the model, our approach still outperforms the baseline methods. the experiments also show that our method can be adapted to different neural architectures. the ablation test and case study provide further analysis of our s2s-sls model, showing the effect of our auxiliary matching losses, joint training, and auto-encoding training.