SlowGuess/ACL_2020_OCR huggingface dataset:
Aman Madaan *, Amrith Setlur *, Tanmay Parekh *, Barnabas Poczos, Graham Neubig, Yiming Yang, Ruslan Salakhutdinov, Alan W Black, Shrimai Prabhumoye
{amadaan, asetlur, tparekh}@cs.cmu.edu
This paper introduces a new task of politeness transfer which involves converting non-polite sentences to polite sentences while preserving the meaning. We also provide a dataset of more than 1.39 million instances automatically labeled for politeness to encourage benchmark evaluations on this new task. We design a tag and generate pipeline that identifies stylistic attributes and subsequently generates a sentence in the target style while preserving most of the source content. For politeness as well as five other transfer tasks, our model outperforms the state-of-the-art methods on automatic metrics for content preservation, with a comparable or better performance on style transfer accuracy. Additionally, our model surpasses existing methods on human evaluations for grammaticality, meaning preservation and transfer accuracy across all the six style transfer tasks. The data and code is located at https://github.com/tag-and-generate/
Politeness plays a crucial role in social interaction, and is closely tied with power dynamics, social distance between the participants of a conversation, and gender (Brown et al., 1987; Danescu-Niculescu-Mizil et al., 2013). It is also imperative to use the appropriate level of politeness for smooth communication in conversations (Coppock, 2005), organizational settings like emails (Peterson et al., 2011), memos, official documents, and many other settings. Notably, politeness has also been identified as an interpersonal style which can be decoupled from content (Kang and Hovy, 2019). Motivated by its central importance, in this paper we study the task of converting non-polite sentences to polite sentences while preserving the meaning.
Prior work on text style transfer (Shen et al., 2017; Li et al., 2018; Prabhumoye et al., 2018;
Rao and Tetreault, 2018; Xu et al., 2012; Jhamtani et al., 2017) has not focused on politeness as a style transfer task, and we argue that defining it is cumbersome. While native speakers of a language and cohabitants of a region have a good working understanding of the phenomenon of politeness for everyday conversation, pinning it down as a definition is non-trivial (Meier, 1995). There are primarily two reasons for this complexity. First, as noted by (Brown et al., 1987), the phenomenon of politeness is rich and multifaceted. Second, politeness of a sentence depends on the culture, language, and social structure of both the speaker and the addressed person. For instance, while using "please" in requests made to the closest friends is common amongst the native speakers of North American English, such an act would be considered awkward, if not rude, in the Arab culture (Kádár and Mills, 2011).
We circumscribe the scope of politeness for the purpose of this study as follows: First, we adopt the data driven definition of politeness proposed by (Danescu-Niculescu-Mizil et al., 2013). Second, we base our experiments on a dataset derived from the Enron corpus (Klimt and Yang, 2004) which consists of email exchanges in an American corporation. Thus, we restrict our attention to the notion of politeness as widely accepted by the speakers of North American English in a formal setting.
Even after framing politeness transfer as a task, there are additional challenges involved that differentiate politeness from other styles. Consider a common directive in formal communication, "send me the data". While the sentence is not impolite, a rephrasing "could you please send me the data" would largely be accepted as a more polite way of phrasing the same statement (Danescu-Niculescu-Mizil et al., 2013). This example brings out a distinct characteristic of politeness. It is easy to pinpoint the signals for politeness. However,
* authors contributed equally to this work.
Proceedings of the 58th Annual Meeting of the Association for Computational Linguistics, pages 1869-1881 July 5 - 10, 2020. ©2020 Association for Computational Linguistics
cues that signal the absence of politeness, like direct questions, statements and factuality (Danescu-Niculescu-Mizil et al., 2013), do not explicitly appear in a sentence, and are thus hard to objectify. Further, the other extreme of politeness, impolite sentences, are typically riddled with curse words and insulting phrases. While interesting, such cases can typically be neutralized using lexicons. For our study, we focus on the task of transferring the non-polite sentences to polite sentences, where we simply define non-politeness to be the absence of both politeness and impoliteness. Note that this is in stark contrast with the standard style transfer tasks, which involve transferring a sentence from a well-defined style polarity to the other (like positive to negative sentiment).
We propose a tag and generate pipeline to overcome these challenges. The tagger identifies the words or phrases which belong to the original style and replaces them with a tag token. If the sentence has no style attributes, as in the case for politeness transfer, the tagger adds the tag token in positions where phrases in the target style can be inserted. The generator takes as input the output of the tagger and generates a sentence in the target style. Additionally, unlike previous systems, the outputs of the intermediate steps in our system are fully realized, making the whole pipeline interpretable. Finally, if the input sentence is already in the target style, our model won't add any stylistic markers and thus would allow the input to flow as is.
We evaluate our model on politeness transfer as well as 5 additional tasks described in prior work (Shen et al., 2017; Prabhumoye et al., 2018; Li et al., 2018) on content preservation, fluency and style transfer accuracy. Both automatic and human evaluations show that our model beats the state-of-the-art methods in content preservation, while either matching or improving the transfer accuracy across six different style transfer tasks(§5). The results show that our technique is effective across a broad spectrum of style transfer tasks. Our methodology is inspired by Li et al. (2018) and improves upon several of its limitations as described in (§2).
Our main contribution is the design of politeness transfer task. To this end, we provide a large dataset of nearly 1.39 million sentences labeled for politeness (https://github.com/tag-and-generate/politeness-dataset). Additionally, we hand curate a test set of 800 samples (from Enron emails) which are annotated as requests. To the best of our
knowledge, we are the first to undertake politeness as a style transfer task. In the process, we highlight an important class of problems wherein the transfer involves going from a neutral style to the target style. Finally, we design a "tag and generate" pipeline that is particularly well suited for tasks like politeness, while being general enough to match or beat the performance of the existing systems on popular style transfer tasks.
Politeness and its close relation with power dynamics and social interactions has been well documented (Brown et al., 1987). Recent work (Danescu-Niculescu-Mizil et al., 2013) in computational linguistics has provided a corpus of requests annotated for politeness curated from Wikipedia and StackExchange. Niu and Bansal (2018) uses this corpus to generate polite dialogues. Their work focuses on contextual dialogue response generation as opposed to content preserving style transfer, while the latter is the central theme of our work. Prior work on Enron corpus (Yeh and Harnly, 2006) has been mostly from a socio-linguistic perspective to observe social power dynamics (Bramsen et al., 2011; McCallum et al., 2007), formality (Peterson et al., 2011) and politeness (Prabhakaran et al., 2014). We build upon this body of work by using this corpus as a source for the style transfer task.
Prior work on style transfer has largely focused on tasks of sentiment modification (Hu et al., 2017; Shen et al., 2017; Li et al., 2018), caption transfer (Li et al., 2018), persona transfer (Chandu et al., 2019; Zhang et al., 2018), gender and political slant transfer (Reddy and Knight, 2016; Prabhumoye et al., 2018), and formality transfer (Rao and Tetreault, 2018; Xu et al., 2019). Note that formality and politeness are loosely connected but independent styles (Kang and Hovy, 2019). We focus our efforts on carving out a task for politeness transfer and creating a dataset for such a task.
Current style transfer techniques (Shen et al., 2017; Hu et al., 2017; Fu et al., 2018; Yang et al., 2018; John et al., 2019) try to disentangle source style from content and then combine the content with the target style to generate the sentence in the target style. Compared to prior work, "Delete, Retrieve and Generate" (Li et al., 2018) (referred to as DRG henceforth) and its extension (Sudhakar et al., 2019) are effective methods to generate out-
puts in the target style while having a relatively high rate of source content preservation. However, DRG has several limitations: (1) the delete module often marks content words as stylistic markers and deletes them, (2) the retrieve step relies on the presence of similar content in both the source and target styles, (3) the retrieve step is time consuming for large datasets, (4) the pipeline makes the assumption that style can be transferred by deleting stylistic markers and replacing them with target style phrases, (5) the method relies on a fixed corpus of style attribute markers, and is thus limited in its ability to generalize to unseen data during test time. Our methodology differs from these works as it does not require the retrieve stage and makes no assumptions on the existence of similar content phrases in both the styles. This also makes our pipeline faster in addition to being robust to noise.
Wu et al. (2019) treats style transfer as a conditional language modelling task. It focuses only on sentiment modification, treating it as a cloze form task of filling in the appropriate words in the target sentiment. In contrast, we are capable of generating the entire sentence in the target style. Further, our work is more generalizable and we show results on five other style transfer tasks.
3.1 Politeness Transfer Task
For the politeness transfer task, we focus on sentences in which the speaker communicates a requirement that the listener needs to fulfill. Common examples include imperatives "Let's stay in touch" and questions that express a proposal "Can you call me when you get back?" Following Jurafsky et al. (1997), we use the umbrella term "action-directives" for such sentences. The goal of this task is to convert action-directives to polite requests. While there can be more than one way of making a sentence polite, for the above examples, adding gratitude ("Thanks and let's stay in touch") or counterfactuals ("Could you please call me when you get back?") would make them polite (Danescu-Niculescu-Mizil et al., 2013).
Data Preparation The Enron corpus (Klimt and Yang, 2004) consists of a large set of email conversations exchanged by the employees of the Enron corporation. Emails serve as a medium for exchange of requests, serving as an ideal application for politeness transfer. We begin by pre-processing
the raw Enron corpus following Shetty and Adibi (2004). The first set of pre-processing<sup>1</sup> steps and de-duplication yielded a corpus of roughly 2.5 million sentences. Further pruning<sup>2</sup> led to a cleaned corpus of over 1.39 million sentences. Finally, we use a politeness classifier (Niu and Bansal, 2018) to assign politeness scores to these sentences and filter them into ten buckets based on the score  $(\mathrm{P}_0 - \mathrm{P}_9)$ ; Fig. 1). All the buckets are further divided into train, test, and dev splits (in a 80:10:10 ratio).
For our experiments, we assumed all the sentences with a politeness score of over  $90\%$  by the classifier to be polite, also referred as the  $\mathrm{P_9}$  bucket (marked in green in Fig. 1). We use the train-split of the  $\mathrm{P_9}$  bucket of over 270K polite sentences as the training data for the politeness transfer task. Since the goal of the task is making action directives more polite, we manually curate a test set comprising of such sentences from test splits across the buckets. We first train a classifier on the switchboard corpus (Jurafsky et al., 1997) to get dialog state tags and filter sentences that have been labeled as either action-directive or quotation. Further, we use human annotators to manually select the test sentences. The annotators had a Fleiss's Kappa score  $(\kappa)$  of  $0.77^4$  and curated a final test set of 800 sentences.
Figure 1: Distribution of Politeness Scores for the Enron Corpus
In Fig. 2, we examine the two extreme buckets with politeness scores of  $< 10\%$ $\mathrm{(P_0}$  bucket) and  $>90\%$ $\mathrm{(P_9}$  bucket) from our corpus by plotting
1Pre-processing also involved steps for tokenization (done using spacy (Honnibal and Montani, 2017)) and conversion to lower case.
2We prune the corpus by removing the sentences that 1) were less than 3 words long, 2) had more than  $80\%$  numerical tokens, 3) contained email addresses, or 4) had repeated occurrences of spurious characters.
3We used AWD-LSTM based classifier for classification of action-directive.
4The score was calculated for 3 annotators on a sample set of 50 sentences.
10 of the top 30 words occurring in each bucket. We clearly notice that words in the  $\mathrm{P_9}$  bucket are closely linked to polite style, while words in the  $\mathrm{P_0}$  bucket are mostly content words. This substantiates our claim that the task of politeness transfer is fundamentally different from other attribute transfer tasks like sentiment where both the polarities are clearly defined.
Figure 2: Probability of occurrence for 10 of the most common 30 words in the  $\mathbf{P}_0$  and  $\mathbf{P}_9$  data buckets
3.2 Other Tasks
The Captions dataset (Gan et al., 2017) has image captions labeled as being factual, romantic or humorous. We use this dataset to perform transfer between these styles. This task parallels the task of politeness transfer because much like in the case of politeness transfer, the captions task also involves going from a style neutral (factual) to a style rich (humorous or romantic) parlance.
For sentiment transfer, we use the Yelp restaurant review dataset (Shen et al., 2017) to train, and evaluate on a test set of 1000 sentences released by Li et al. (2018). We also use the Amazon dataset of product reviews (He and McAuley, 2016). We use the Yelp review dataset labelled for the Gender of the author, released by Prabhumoye et al. (2018) compiled from Reddy and Knight (2016). For the Political slant task (Prabhumoye et al., 2018), we use dataset released by Voigt et al. (2018).
We are given non-parallel samples of sentences  $\mathbf{X_1} = \{\mathbf{x}_1^{(1)}\ldots \mathbf{x}_n^{(1)}\}$  and  $\mathbf{X_2} = \{\mathbf{x}_1^{(2)}\ldots \mathbf{x}_m^{(2)}\}$  from styles  $S_{1}$  and  $S_{2}$  respectively. The objective of the task is to efficiently generate samples  $\hat{\mathbf{X}}_1 = \{\hat{\mathbf{x}}_1^{(2)}\ldots \hat{\mathbf{x}}_n^{(2)}\}$  in the target style  $S_{2}$ , conditioned on samples in  $\mathbf{X_1}$ . For a style  $S_{v}$  where  $v\in \{1,2\}$ , we begin by learning a set of phrases  $(\Gamma_v)$  which characterize the style  $S_{v}$ . The presence of phrases from  $\Gamma_v$  in a sentence  $\mathbf{x}_i$  would asso
ciate the sentence with the style  $S_{v}$  .For example, phrases like "pretty good" and "worth every penny" are characteristic of the "positive" style in the case of sentiment transfer task.
We propose a two staged approach where we first infer a sentence  $z(\mathbf{x}_i)$  from  $\mathbf{x}_i^{(1)}$  using a model, the tagger. The goal of the tagger is to ensure that the sentence  $z(\mathbf{x}_i)$  is agnostic to the original style  $(S_1)$  of the input sentence. Conditioned on  $z(\mathbf{x}_i)$ , we then generate the transferred sentence  $\hat{\mathbf{x}}_i^{(2)}$  in the target style  $S_2$  using another model, the generator. The intermediate variable  $z(\mathbf{x}_i)$  is also seen in other style-transfer methods. Shen et al. (2017); Prabhumoye et al. (2018); Yang et al. (2018); Hu et al. (2017) transform the input  $\mathbf{x}_i^{(v)}$  to a latent representation  $z(\mathbf{x}_i)$  which (ideally) encodes the content present in  $\mathbf{x}_i^{(v)}$  while being agnostic to style  $S_v$ . In these cases  $z(\mathbf{x}_i)$  encodes the input sentence in a continuous latent space whereas for us  $z(\mathbf{x}_i)$  manifests in the surface form. The ability of our pipeline to generate observable intermediate outputs  $z(\mathbf{x}_i)$  makes it somewhat more interpretable than those other methods.
We train two independent systems for the tagger & generator which have complimentary objectives. The former identifies the style attribute markers  $a(x_{i}^{(1)})$  from source style  $S_{1}$  and either replaces them with a positional token called [TAG] or merely adds these positional tokens without removing any phrase from the input  $x_{i}^{(1)}$ . This particular capability of the model enables us to generate these tags in an input that is devoid of any attribute marker (i.e.  $a(x_{i}^{(1)}) = \{\}$ ). This is one of the major differences from prior works which mainly focus on removing source style attributes and then replacing them with the target style attributes. It is especially critical for tasks like politeness transfer where the transfer takes place from a non-polite sentence. This is because in such cases we may need to add new phrases to the sentence rather than simply replace existing ones. The generator is trained to generate sentences  $\hat{\mathbf{x}}_{i}^{(2)}$  in the target style by replacing these [TAG] tokens with stylistically relevant words inferred from target style  $S_{2}$ . Even though we have non-parallel corpora, both systems are trained in a supervised fashion as sequence-to-sequence models with their own distinct pairs of inputs & outputs. To create parallel training data, we first estimate the style markers  $\Gamma_{v}$  for a given style  $S_{v}$  & then use these to curate style free sentences with [TAG]
Figure 3: Our proposed approach: tag and generate. The tagger infers the interpretable style free sentence  $z(\mathbf{x}_i)$  for an input  $\mathbf{x}_i^{(1)}$  in source style  $S_1$ . The generator transforms  $\mathbf{x}_i^{(1)}$  into  $\hat{\mathbf{x}}_i^{(2)}$  which is in target style  $S_2$ .
tokens. Training data creation details are given in sections  $\S 4.2, \S 4.3$ .
Fig. 3 shows the overall pipeline of the proposed approach. In the first example  $\mathbf{x}_1^{(1)}$ , where there is no clear style attribute present, our model adds the [TAG] token in  $z(\mathbf{x}_1)$ , indicating that a target style marker should be generated in this position. On the contrary, in the second example, the terms "ok" and "bland" are markers of negative sentiment and hence the tagger has replaced them with [TAG] tokens in  $z(\mathbf{x}_2)$ . We can also see that the inferred sentence in both the cases is free of the original and target styles. The structural bias induced by this two staged approach is helpful in realizing an interpretable style free tagged sentence that explicitly encodes the content. In the following sections we discuss in detail the methodologies involved in (1) estimating the relevant attribute markers for a given style, (2) tagger, and (3) generator modules of our approach.
4.1 Estimating Style Phrases
Drawing from Li et al. (2018), we propose a simple approach based on n-gram tf-ids to estimate the set  $\Gamma_v$ , which represents the style markers for style  $v$ . For a given corpus pair  $\mathbf{X}_1, \mathbf{X}_2$  in styles  $S_1, S_2$  respectively we first compute a probability distribution  $p_1^2(w)$  over the n-grams  $w$  present in both the corpora (Eq. 2). Intuitively,  $p_1^2(w)$  is proportional to the probability of sampling an n-gram present in both  $\mathbf{X}_1, \mathbf{X}_2$  but having a much higher tfidf value in  $\mathbf{X}_2$  relative to  $\mathbf{X}_1$ . This is how we define the impactful style markers for style  $S_2$ .
$$
\eta_ {1} ^ {2} (w) = \frac {\frac {1}{m} \sum_ {i = 1} ^ {m} \operatorname {t f - i d f} \left(w , \mathbf {x} _ {i} ^ {(2)}\right)}{\frac {1}{n} \sum_ {j = 1} ^ {n} \operatorname {t f - i d f} \left(w , \mathbf {x} _ {j} ^ {(1)}\right)} \tag {1}
$$
$$
p _ {1} ^ {2} (w) = \frac {\eta_ {1} ^ {2} (w) ^ {\gamma}}{\sum_ {w ^ {\prime}} \eta_ {1} ^ {2} \left(w ^ {\prime}\right) ^ {\gamma}} \tag {2}
$$
where,  $\eta_1^2 (w)$  is the ratio of the mean tf-idsf for a given n-gram  $w$  present in both  $\mathbf{X}_1,\mathbf{X}_2$  with
$\left|\mathbf{X}_1\right| = n$  and  $\left|\mathbf{X}_2\right| = m$ . Words with higher values for  $\eta_1^2 (w)$  have a higher mean tfidf in  $\mathbf{X}_2$  vs  $\mathbf{X}_1$ , and thus are more characteristic of  $S_{2}$ . We further smooth and normalize  $\eta_1^2 (w)$  to get  $p_1^2 (w)$ . Finally, we estimate  $\Gamma_{2}$  by
$$
\Gamma_ {2} = \{w: p _ {1} ^ {2} (w) \geq k \}
$$
In other words,  $\Gamma_{2}$  consists of the set of phrases in  $\mathbf{X}_2$  above a given style impact  $k$ .  $\Gamma_{1}$  is computed similarly where we use  $p_2^1 (w),\eta_2^1 (w)$ .
4.2 Style Invariant Tagged Sentence
The tagger model (with parameters  $\theta_{t}$ ) takes as input the sentences in  $\mathbf{X}_1$  and outputs  $\{z(\mathbf{x}_i):$ $\mathbf{x}_i^{(1)}\in \mathbf{X}_1\}$ . Depending on the style transfer task, the tagger is trained to either (1) identify and replace style attributes  $a(\mathbf{x}_i^{(1)})$  with the token tag [TAG] (replace-tags) or (2) add the [TAG] token at specific locations in  $\mathbf{x}_i^{(1)}$  (add-tags). In both the cases, the [TAG] tokens indicate positions where the generator can insert phrases from the target style  $S_{2}$ . Finally, we use the distribution  $p_1^2 (w) / p_2^1 (w)$  over  $\Gamma_2 / \Gamma_1$  (§4.1) to draw samples of attribute-markers that would be replaced with the [TAG] token during the creation of training data.
The first variant, replace-tagsger, is suited for a task like sentiment transfer where almost every sentence has some attribute markers  $a(\mathbf{x}_i^{(1)})$  present in it. In this case the training data comprises of pairs where the input is  $\mathbf{X}_1$  and the output is  $\{z(\mathbf{x}_i):\mathbf{x}_i^{(1)}\in \mathbf{X}_1\}$ . The loss objective for replace-tagsger is given by  $\mathcal{L}_r(\theta_t)$  in Eq. 3.
$$
\mathcal {L} _ {r} \left(\theta_ {t}\right) = - \sum_ {i = 1} ^ {\left| \mathbf {X} _ {1} \right|} \log P _ {\theta_ {t}} \left(z \left(\mathbf {x} _ {i}\right) \mid \mathbf {x} _ {i} ^ {(1)}; \theta_ {t}\right) \tag {3}
$$
The second variant, add-tags, is designed for cases where the transfer needs to happen from style neutral sentences to the target style. That is,  $\mathbf{X}_1$  consists of style neutral sentences whereas  $\mathbf{X}_2$  consists of sentences in the target style. Examples of
such a task include the tasks of politeness transfer (introduced in this paper) and caption style transfer (used by Li et al. (2018)). In such cases, since the source sentences have no attribute markers to remove, the tagger learns to add [TAG] tokens at specific locations suitable for emanating style words in the target style.
Figure 4: Creation of training data for add-tags.