Paper · 2020-04-29 · cs.CL
Politeness Transfer: A Tag and Generate Approach
Rewrites non-polite sentences as polite ones. A tagger inserts position-tagged [TAG] slots where polite phrases may go, trained add-only on polite text; a generator fills the slots. Four-layer transformers with beam 5. Author-reported: politeness BLEU-self 70.44 against 11.83 for DRG, with classifier accuracy 89.50 against 90.25.
Text style transferControllable text generationSequence-to-sequence learningtext-style-transferpolitenesstagginggeneration
arXivPDFCodeMarkdown13 min read
AI-compiled by claude-haiku-5-5 on 2026-11-13, not yet reviewed by a human. Every claim cites its source; check it when a detail matters.
In plain words
The paper asks a practical question: can a program take a plain, neutral email request, such as "send me the data", and rewrite it so it sounds polite, while keeping the same meaning? Most earlier style-transfer work assumed both the input and the target had clear opposite styles, like positive and negative reviews. Politeness is harder, because "not polite" is not a style of its own. It is just the absence of polite markers, so there is often nothing to swap out.
The authors split the job into two steps. The first step, the tagger, reads the plain sentence and marks spots where a polite phrase could be added. It does not write any words, it only places marker slots. The second step, the generator, reads the marked-up sentence and fills each slot with wording that fits the spot. Because the intermediate marked-up sentence is ordinary text, a person can see exactly where the change was made.
The idea is worth knowing because it lets a system only add words, so it can handle sentences that contain no style markers at all. It also keeps the original content in place, which the authors argue is the weak point of older methods.
TL;DR
- Task: transfer non-polite requests to polite ones while preserving meaning; the paper also releases a politeness dataset built from Enron emails §1 §3.1.
- Method: a tagger inserts
[TAG]position tokens into the source sentence, and a generator replaces them with target-style phrases §4 fig. 3. - Politeness tagger is trained add-only on polite sentences with phrases removed §4.2 eq. 4.
- Author-reported: higher BLEU-self and ROUGE than DRG, BST and CAE on politeness, with classifier accuracy within about 1 point of DRG tab. 1 §5.
- The released code is MIT-licensed and differs from the paper in several places (see Paper vs code).
Problem
Standard style-transfer tasks move between two defined poles, such as positive and negative sentiment §1. Non-parallel methods usually remove source-style words and insert target-style words. For politeness, the source side is "neutral": it has no polite markers to delete. The transfer must therefore add phrases, and the paper argues that defining politeness is itself hard, because its signals are rich and culture-dependent §1. The authors restrict the scope to requests in North American English email, using a data-driven politeness score §1 §3.1.
Prior systems such as Delete, Retrieve and Generate (DRG) need a retrieval step that finds similar sentences in the other style, assume that style can be transferred by deletion and replacement, and rely on a fixed marker list §2. The paper also reports that automatic metrics can be fooled, for example by appending "but overall it sucked" to a positive review to change the classifier's verdict, so metric scores alone may not show task success §5.
Method
The approach runs in two stages §4:
- Style phrase estimation §4.1. For each style, score each n-gram by how much more characteristic it is of the target corpus than of the source corpus, using mean tf-idf per corpus, and keep the high scorers as the style phrases Γ.
- Tagger §4.2. Map the source sentence to a tagged sentence
z(x)in which style phrases are replaced by a position token, or, for politeness, positions where phrases can be inserted are marked with a tag. The tagger is a sequence-to-sequence model trained with the loss in eq. 3 (replace variant) or eq. 4 (add variant). - Generator §4.3. Map
z(x)to a sentence in the target style with the loss in eq. 5. Training pairs are built from target-style sentences only, so the generator never sees the source style.
The replace and add variants differ only in the tagger's training data §4.2; the authors compare them in tab. 5. For politeness the authors use the add variant, because the source side is neutral and has no phrases to delete §4.2.
Equations, as printed in the paper:
- eq. 1
η(w) = mean over m target sentences of tf-idf(w) / mean over n source sentences of tf-idf(w), for n-grams w present in both corpora §4.1. - eq. 2
p(w) = η(w)^γ / Σ_w' η(w')^γ, with smoothing exponent γ §4.1. - eq. 3 replace-tagger loss:
L_r = −Σ_i log P(z(x_i) | x_i^(1))§4.2. - eq. 4 add-tagger loss:
L_a = −Σ_i log P(z(x_i) | x_i^(2) minus a(x_i^(2))), wherea(·)are style phrases §4.2. - eq. 5 generator loss:
L = −Σ_i log P(x_i^(v) | z(x_i))§4.3. - Set Γ_2 is defined as the n-grams with
p(w) ≥ k, with k = 0.9 for most datasets and 0.97 for Yelp §4.1 §5. See Paper vs code for how the released code implements this.
Pseudocode for phrase scoring follows eq. 1 and eq. 2:
# Score n-grams by target-over-source tf-idf [§4.1] [eq. 1] [eq. 2]
# Input: source_sents, target_sents (lists of strings); gamma = 0.75
# Output: dict phrase -> normalised score p
def score_style_phrases(source_sents, target_sents, gamma):
# tf-idf of each n-gram, averaged over all sentences of each corpus [§4.1]
tfidf_src = mean_tfidf_per_ngram(source_sents)
tfidf_tgt = mean_tfidf_per_ngram(target_sents)
# Keep only n-grams that occur in both corpora [§4.1]
shared = set(tfidf_src) & set(tfidf_tgt)
# Ratio of target to source mean tf-idf [eq. 1]
eta = {w: tfidf_tgt[w] / tfidf_src[w] for w in shared}
# Power gamma, then normalise to sum to one [eq. 2]
powered = {w: eta[w] ** gamma for w in shared}
total = sum(powered.values())
return {w: powered[w] / total for w in shared}Tagging of one source sentence, as the released code does it style_tags.py. The paper describes the sampling only in words §4.1 §4.2:
# Replace sampled style phrases with position tags [§4.2]
# [code: style_tags.py#L84-L136]
# Input: tokens (list of str); scores (phrase -> prob); label (str)
# Output: list of str with [label<pos>] tags in place of phrases
def tag_sentence(tokens, scores, label):
tagged = []
i = 0
while i < len(tokens):
# Position bin of this token, capped [code: style_tags.py#L106]
pos = min(i // 3, 20)
# Try 4-, 3-, 2-, then 1-token phrases, each with its own draw
# [code: style_tags.py#L109-L131]
span = longest_match_with_draw(tokens, i, scores)
if span > 0:
tagged.append(f"[{label}{pos}]")
i += span
else:
tagged.append(tokens[i])
i += 1
return " ".join(tagged)longest_match_with_draw is a helper that returns the length of the longest phrase starting at i that is in scores and passes a random draw against its score; it returns 0 otherwise. Consecutive matches are merged into one tag by the code style_tags.py.
Add-tagger training pairs for politeness §4.2 fig. 4:
# Build add-tagger pairs from target-style sentences only [§4.2] [eq. 4]
# Input: polite_sents (list of str); phrases (set of str)
# Output: list of (source, target) string pairs
def build_add_tagger_pairs(polite_sents, phrases, label):
pairs = []
for sent in polite_sents:
# Source: the sentence with its style phrases deleted [§4.2]
source = delete_phrases(sent, phrases)
# Target: the same sentence with [TAG] slots at those phrases [§4.2]
target = insert_tags(sent, phrases, label)
pairs.append((source, target))
return pairsGenerator training pairs §4.3 eq. 5:
# Build generator pairs: tagged sentence in, polite sentence out [§4.3]
# Input: polite_sents (list of str); tagger_outputs (list of str)
# Output: list of (tagged_source, target) pairs
def build_generator_pairs(polite_sents, tagger_outputs):
# Each target is the original polite sentence; its source is the tagged form
return [
(tagged, sent)
for tagged, sent in zip(tagger_outputs, polite_sents)
]Inference at test time §4.2 §4.3 inference.sh:
# Two-pass inference: tagger, then generator [§4.2] [§4.3]
# Input: source_sent (str); tagger, generator (seq2seq models)
# Output: transferred sentence (str)
def transfer(source_sent, tagger, generator):
# Tagger: beam search of width 5, rerank to prefer more tags [§5]
tagged = beam_search(tagger, source_sent, beam=5, prefer_tags=True)
# Generator: beam search of width 5, no tag reranking [§5]
return beam_search(generator, tagged, beam=5, prefer_tags=False)Figures are described in words only; see fig. 1 for the politeness-score histogram and fig. 2 for the top words in the two extreme buckets §3.1. fig. 3 is the overall pipeline §4. fig. 4 shows add-tagger data creation, where style phrases are removed from polite sentences and replaced with tags §4.2.
Hyperparameters
| Name | Value | Where | Notes |
|---|---|---|---|
| Transformer layers | 4 | §5 train_tagger.sh | same for generator |
| Attention heads | 4 | §5 train_tagger.sh | |
| Embedding and hidden size | 512 | §5 train_tagger.sh | |
| Dropout (each layer) | 0.3 | §5 train_tagger.sh | |
| Word-level augmentation | shuffle, drop, replace | §5 | politeness generator only §5; rates not stated in paper |
| BPE vocabulary | 16000 (Captions: 4000) | §5 prepare_bpe.sh | the code file has only 16000; the 4000 setting for Captions is not in the repository |
| Smoothing exponent γ | 0.75 | §5 eq. 2 style_tags.py | |
| Threshold k | 0.9 (Yelp 0.97) | §5 §4.1 | semantics differ in code, see Paper vs code |
| Beam size | 5 | §5 inference.sh | |
| Tagger reranking | prefer more [TAG] tokens | §5 decoding.py | |
| Politeness split | 80:10:10 train/test/dev per bucket | §3.1 | |
| Politeness training set | "over 270K" polite sentences | §3.1 | the paper says the P9 train split is over 270K; the commented table in the source gives 273,772 for the whole P9 bucket |
| Politeness test set | 800 sentences | §3.1 | hand-annotated; Fleiss κ 0.77 on 50 sentences, 3 annotators |
| Politeness score threshold | above 90% = polite | §3.1 | from the classifier of Niu and Bansal (2018) |
| Learning rate | not stated | §5 | script value: 1e-3 train_tagger.sh |
| Epochs | not stated | §5 | script value: 5 train_tagger.sh |
| Batch size | not stated | §5 | script: 8000 tokens per batch train_tagger.sh; 128 samples max training.py |
| Optimizer | not stated | §5 | code: Adam, betas (0.9, 0.98) training.py |
| Gradient clipping | not stated | §5 | script value: 1.1 train_tagger.sh |
| n-gram range for phrases | not stated | §4.1 | code default (1, 2) run.py |
| Minimum phrase frequency | not stated | §4.1 | code: 2 in the main class style_tags.py |
| Tag position bins | not stated (t in 0..T) | §4.3 | code: 3 tokens per bin, capped at 20 style_tags.py |
| Random seed | not stated | §5 | code: 11731 training.py |
Results
Author-reported. Setup: test sets as described in §3 and §5; baselines are DRG, BST and CAE, using the settings of their papers §5. Acc is classifier accuracy (higher better), BL-s is BLEU against the input (content preservation), MET is METEOR and ROU is ROUGE §5.
Table 1, politeness, Gender and Political datasets tab. 1:
| Model | Pol. Acc | Pol. BL-s | Pol. MET | Pol. ROU | Gender Acc | Gender BL-s | Gender MET | Gender ROU | Political Acc | Political BL-s | Political MET | Political ROU |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| CAE | 99.62 | 6.94 | 10.73 | 25.71 | 65.21 | 9.25 | 14.72 | 42.42 | 77.71 | 3.17 | 7.79 | 27.17 |
| BST | 60.75 | 2.55 | 9.19 | 18.99 | 54.4 | 20.73 | 22.57 | 55.55 | 88.49 | 10.71 | 16.26 | 41.02 |
| DRG | 90.25 | 11.83 | 18.07 | 41.09 | 36.29 | 22.9 | 22.84 | 53.30 | 69.79 | 25.69 | 21.6 | 51.8 |
| This paper | 89.50 | 70.44 | 36.26 | 70.99 | 82.21 | 52.76 | 37.42 | 74.59 | 87.74 | 68.44 | 45.44 | 77.51 |
Each dataset group has the same four columns: Acc, BL-s, MET, ROU tab. 1. Text: the politeness BLEU-self gain over DRG is 58.61 points, and the politeness accuracy is within 1% of DRG §5.
Table 2, Yelp, Amazon and Captions tab. 2. Columns are Acc, BL-s, BL-r (BLEU against human references), MET, ROU:
| Model | Yelp Acc | BL-s | BL-r | MET | ROU | Amazon Acc | BL-s | BL-r | MET | ROU | Captions Acc | BL-s | BL-r | MET | ROU |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| CAE | 72.1 | 19.95 | 7.75 | 21.70 | 55.9 | 78 | 2.64 | 1.68 | 9.52 | 29.16 | 89.66 | 2.09 | 1.57 | 9.61 | 30.02 |
| DRG | 88.8 | 36.69 | 14.51 | 32.09 | 61.06 | 52.2 | 57.07 | 29.85 | 50.16 | 79.31 | 95.65 | 31.79 | 11.78 | 32.45 | 64.32 |
| This paper | 86.6 | 47.14 | 19.76 | 36.26 | 70.99 | 66.4 | 68.74 | 34.80 | 45.3 | 83.45 | 93.17 | 51.01 | 15.63 | 43.67 | 79.51 |
Text: BLEU-r rises by 5.25 (Yelp), 4.95 (Amazon) and 3.64 (Captions) §5. The table gives 3.85 for Captions (15.63 minus 11.78); see Pitfalls. Amazon accuracy is 14.2 points above DRG §5.
Table 3, human evaluation on a 1 to 5 scale, Con (content), Att (attribute match), Gra (grammar) tab. 3:
| Dataset | Con DRG | Con This | Att DRG | Att This | Gra DRG | Gra This |
|---|---|---|---|---|---|---|
| Politeness | 2.9 | 3.6 | 3.2 | 3.6 | 2.0 | 3.7 |
| Gender | 3.0 | 3.5 | - | - | 2.2 | 2.5 |
| Political | 2.9 | 3.2 | - | - | 2.5 | 2.7 |
| Yelp | 3.0 | 3.7 | 3 | 3.9 | 2.7 | 3.3 |
Ten raters; 200 politeness samples and 100 per other dataset. Attribute match was not rated for gender or political, where the authors used classifier scores instead §5.
Table 5, tagger variants on Yelp and Captions, Acc and BL-r tab. 5:
| Tagger | Yelp Acc | Yelp BL-r | Captions Acc | Captions BL-r |
|---|---|---|---|---|
| Add-tagger | 53.2 | 20.66 | 93.17 | 15.63 |
| Replace-tagger | 86.6 | 19.76 | 84.5 | 15.04 |
| Combined | 72.5 | 22.46 | 82.17 | 18.51 |
The Combined Captions BL-r reads "18.5" followed by a stray "1" in the source table; it is shown here as 18.51 tab. 5. The add-tagger reaches about 50% accuracy on Yelp, which the authors attribute to adding phrases of the opposite polarity §5.
Table 4 lists four qualitative politeness examples, each labelled with a strategy such as counterfactual modal ("could you please") or apologising tab. 4. Tables 6 and 7 in the appendix give further politeness and other-task examples tab. 6 tab. 7. The paper reports that changes to non-tagged words happened in 6.9% of sentences §5.
Paper vs code
Code: tag-and-generate organisation, repository tagger-generator, MIT license, commit 0059c49fd7df273be9421cb683c96f362663057d. The repository is linked from the paper and its owner is the authors' organisation §1. Discrepancies, each with both citations:
- Threshold semantics. The paper keeps n-grams with
p(w) ≥ k§4.1. The code ranks all candidates by a normalised score, keeps those at or above percentile 0.9, and rescales their scores to (0, 1] as tag-sampling probabilities style_tags.py. Becausepsums to one over all n-grams, a literalp ≥ 0.9would admit at most one n-gram, so the code's reading is the only workable one. - Exponent. Paper applies γ to η eq. 2; code raises the ratio to 0.75 before normalising style_tags.py. Same effect.
- Candidate filter. Code requires a phrase to occur at least twice in the main class style_tags.py. The paper states no minimum frequency §4.1.
- N-gram range. Code default is unigrams and bigrams run.py. The paper does not state a range §4.1.
- Tag positions. Paper uses one token per position
tin0..T§4.3. Code assigns a bin per three tokens and caps the bin at 20 style_tags.py. - Merged tags. Consecutive matched phrases collapse into one tag style_tags.py. The paper does not describe this.
- Stochastic tagging. Tagging draws against each phrase's score, so the same sentence can be tagged differently in different runs style_tags.py. The paper says the probabilities are used to "draw samples" §4.2 but does not describe a per-occurrence draw.
- Empty tagging dropped. Sentences with no tag are not written to the training files style_tags.py. The paper does not say so.
- Politeness reference set. For politeness, phrase scores are estimated from the polite bucket against the bucket labelled
P_0, excluding the test split run.py. The paper does not say which bucket serves as the reference class for politeness §4.1. - Learning schedule. Scripts use learning rate 1e-3 for 5 epochs train_tagger.sh. The code default is 4e-2 for 15 epochs training.py. The paper gives neither value §5.
- Plateau decay and checkpoint. After an epoch without a better dev perplexity, learning rate is multiplied by 0.8, and the best checkpoint by dev perplexity is saved training.py training.py.
- Inverse-square-root schedule is a no-op. The flag is parsed, but the schedule is never assigned to the training loop training.py.
- Augmentation is off in the shipped scripts. The paper says the politeness generator is trained with shuffle, drop and replace augmentation §5. Augmentation runs only with
--noisy-inputor--noisy-output, and the training scripts pass neither training.py train_generator.sh. When enabled, the rates are fixed in code at drop 0.025, substitution 0.075 and shuffle distance 2 training.py. The paper gives no rates. - Tag reranking matches. Tagger beams are sorted by the number of tag tokens and the top one kept decoding.py inference.sh, as the paper describes §5.
- Beam size, layers, heads, width, dropout, BPE size match §5 train_tagger.sh prepare_bpe.sh.
- Data preparation is not in the repository. The Enron cleaning, the politeness classifier scoring and the hand-curated test set are described in the paper §3.1. The repository provides a precomputed
politeness.tsvthrough a separate download, and the walkthrough runs the tagging step on it README.md.
Pitfalls
- Equation 4 index. The sum in eq. 4 runs to
|X_1|, but its data are drawn from the target-style setX_2. Use the size of the set actually iterated. - Equation numbering. Equation numbers in this card follow the source order of the printed equations; the text refers to them by label. Check against the PDF before quoting a number.
- Threshold trap. Implementing
p ≥ 0.9literally produces almost no phrases (see Paper vs code). Use the code's percentile rule or document the change. - Hidden training choices. The paper omits the learning rate, optimiser, batch size, epochs and clipping. Take them from
train_tagger.shandtrain_generator.sh, which both use lr 1e-3 for 5 epochs, 8000 tokens per batch and clip 1.1. Those scripts are the only source for these values. - Augmentation not active. The shipped scripts do not augment the generator, which differs from the paper's text. If you need it, pass the noise flags explicitly and expect the fixed rates from code.
- Random tagging. Tags are sampled, so training data differ from run to run unless the seed is fixed (seed 11731 is the default in
training.py). Tagging is not deterministic in the code. - Figure numbers. The README calls the add-tagger data creation "Figure 3"; the figure order in the LaTeX source gives Figure 4 for it. The card uses the source order because no PDF was available.
- Table 2 text mismatch. The Captions BLEU-r gain is 3.85 in the table and 3.64 in the text tab. 2 §5.
- Abstract typo. The arXiv abstract reads "1.39 instances"; the body says "1.39 million" §1. Use the body.
- Evaluation depends on external classifiers. Politeness accuracy uses the classifier of Niu and Bansal (2018), which was trained on the Danescu-Niculescu-Mizil et al. (2013) requests corpus §5. Accuracy numbers therefore inherit that classifier's biases and are not independent of the training labels.
- Metric caveat. The authors show a trivial "append a phrase" baseline scores 91.3% accuracy and BLEU 61.44 on Yelp §5. Treat BLEU and accuracy as weak evidence of task success; the human study in tab. 3 is small (100 to 200 samples).
- Costs not in the abstract. Training runs two transformers (tagger and generator) and beam search at inference, twice per sentence §4 inference.sh. Beam size 5 is fixed in the scripts.
- Yelp threshold. The Yelp value 0.97 is stated in the paper §5, but the repository does not include a Yelp run script, so the value cannot be confirmed in code.
Lineage
- Builds on: Delete, Retrieve and Generate (DRG, Li et al., 2018), which this method modifies by dropping the retrieval step and allowing add-only edits §2. The conclusion also names Li et al. (2018) and Sudhakar et al. (2019) as prior work it extends §6.
- Compared against: DRG; BST, the back-translation approach of Prabhumoye et al. (2018); and CAE, the cross-aligned autoencoder of Shen et al. (2017) §5.
- Superseded by: not stated.
Source and license
Adapted from “Politeness Transfer: A Tag and Generate Approach” by Aman Madaan, Amrith Setlur, Tanmay Parekh, Barnabas Poczos, Graham Neubig, Yiming Yang, Ruslan Salakhutdinov, Alan W Black, Shrimai Prabhumoye (arXiv:2004.14257), used under CC BY-SA 4.0. Changes: condensed and restructured for implementation, with tables, equations and algorithms taken from the paper and its code, each cited to its source. Not affiliated with or endorsed by the authors. This page is licensed under CC BY-SA 4.0. Code citations refer to https://github.com/tag-and-generate/tagger-generator at commit 0059c49fd7df (MIT). Any quoted code is shown under that license.