AI Logic

Data Augmentation

Back-translation

Updated:

Back-translation diagram. Left: the flow for augmenting machine translation parallel data (train a German→English model on parallel data, translate German-only sentences into English to build synthetic pairs, and mix them with real pairs to train an English→German model). Center: the flow for paraphrase augmentation (translate into another language, translate back into the original language, attach the original label, and train). Right: an example paraphrase of a sentence from the paper (input sentence, French translation, and paraphrased sentence).

What is back-translation?

Back-translation is a data augmentation technique that creates new training data by translating sentences with a translation model. It is used in two ways.

  • Augmenting machine translation parallel data: Sentences available only in the target language (monolingual data) are translated into the source language with a reverse-direction translation model, producing pairs of "machine-translated source" and "genuine target" (synthetic parallel data). Sennrich et al. proposed this for neural machine translation in 2016.
  • Augmenting with paraphrases: Training sentences are translated into another language and then back into the original language, producing sentences with nearly the same meaning but different wording. QANet for reading comprehension (2018) and UDA for semi-supervised learning (2019) used this.

Both use an existing translation model as "a tool for generating sentences," increasing training data without new human labeling.

As an analogy, imagine creating a foreign-language textbook by machine-translating Japanese passages at hand into the foreign language, producing large numbers of pairs of "foreign-language exercise" and "Japanese model answer." Even if the exercises are slightly unnatural because of machine translation, the model answers are natural text written by people, so they serve as practice for writing natural sentences.

In back-translation for machine translation, only the source (input) side is synthetic; the target (output) side is genuine text written by people. Because the sentences the model learns to output remain natural, errors in the machine translation are less likely to hurt the fluency of the output.

Procedure

Augmenting machine translation parallel data

To build an English-to-German model, the procedure of Sennrich et al. is as follows (left of the top figure).

  1. Train a reverse-direction (German→English) translation model on human-translated parallel data (pairs of English and German sentences).
  2. Translate German-only sentences (news articles and the like, available in far greater quantity than parallel data) into English with this model.
  3. Pair the machine-translated English sentences with the original German sentences to build synthetic parallel data.
  4. Mix the synthetic pairs with the real parallel data and, without distinguishing them, train a model in the desired direction (English→German). The model architecture is unchanged.

In formulas, from a German sentence yy, a synthetic source sentence x^\hat{x} is generated by the reverse model prevp_{\mathrm{rev}}, and the pair (x^,y)(\hat{x}, y) is added to the training data.

x^∼prev(x∣y),D←Dparallel∪{(x^,y)}\hat{x} \sim p_{\mathrm{rev}}(x \mid y), \qquad \mathcal{D} \leftarrow \mathcal{D}_{\text{parallel}} \cup \{(\hat{x}, y)\}

Augmenting with paraphrases

To augment data for classification or reading comprehension, proceed as follows (center and right of the top figure).

  1. Translate a training sentence xx into another language (the pivot language) with a translation model.
  2. Translate it back into the original language with a reverse-direction model to produce a paraphrase x^\hat{x}.
  3. Give the paraphrase the same label as the original sentence, and train on it mixed with the original sentences.
x^=gB→A(fA→B(x))\hat{x} = g_{B \to A}\bigl(f_{A \to B}(x)\bigr)

fA→Bf_{A \to B} is translation from language A to B, and gB→Ag_{B \to A} is the reverse. The QANet paper generated kk translations with English→French beam search, translated each back, and obtained k2k^2 paraphrases (25 with k=5k = 5). For reading comprehension data, only the passage is paraphrased while the question is kept, and the phrase in the paraphrased passage closest to the original answer is taken as the new answer.

Choosing how to translate (beam search or sampling)

The effect of back-translation depends heavily on how the synthetic sentences are generated.

Sennrich et al. translated with beam search, which searches for the most likely translation. Edunov et al. (2018) compared several generation methods for large-scale English–German translation and showed that sampling at random according to the probabilities, or adding noise to beam search outputs, works better than plain beam search. The noise consists of three operations: deleting each word with probability 0.1, replacing each word with a filler token with probability 0.1, and shuffling word order within a range of up to 3 words.

How the synthetic source is generatedBLEU (average of 5 test sets)
Parallel data only (5.2M sentences)31.00
+ beam search31.78
+ greedy (always pick the most probable word)31.96
+ sampling from the top 10 words (top-k sampling)32.94
+ sampling33.51
+ beam search + noise33.43

(WMT English–German, 5.2M parallel sentences plus 24M synthetic pairs)

The paper's analysis is that beam search outputs are always "the safest translation," lack diversity, and are too easy for the model to learn much from. Indeed, the training loss on beam-search synthetic data dropped quickly.

UDA, for the same reason, translates with temperature sampling rather than beam search. A temperature of 0 is equivalent to greedy decoding and yields the same paraphrase every time, while 1 is so diverse that unreadable sentences appear, so UDA reports that a temperature of 0.7–0.9 worked best.

When parallel data is very scarce, beam search does better instead. In the experiments of Edunov et al., with only 80K parallel sentences (reverse model BLEU of 13.5), beam search was more effective, while sampling was better at 640K sentences or more. A weak reverse model makes the noise from sampling harmful.

Why it works

Sennrich et al. explain why back-translation works for machine translation as follows.

  • The model learns from many target-language sentences: The decoder of an encoder-decoder translation model is a language model conditioned on the source sentence. Training it to output target-language-only sentences improves its ability to produce natural sentences (fluency). In fact, models trained with synthetic data more often produced real, natural words when forming German compounds not seen in the training parallel data.
  • The model keeps attending to the source: They also tried pairing target-language-only sentences with an empty token instead of a source sentence (a dummy source), but increasing its proportion made the model produce outputs without looking at the source. With a synthetic source, the model keeps learning to translate by attending to the source.
  • Overfitting is delayed and the domain can be matched: For Turkish→English, with little parallel data, the parallel-only model quickly overfit, but adding synthetic data delayed overfitting and also lowered the validation loss. Back-translating sentences from the same domain as the test set also adapts the model to domain differences.

Back-translation as paraphrasing works because the translation model changes word choice and word order while preserving the meaning of the sentence. The UDA paper notes that back-translation can produce diverse paraphrases while keeping the original meaning. Compared with methods that randomly modify words, such as EDA, its distinguishing feature is that the results tend to be natural sentences.

Results reported in the papers

Results of Sennrich et al. on WMT 15 English–German translation (BLEU, newstest2015, single model).

Training dataEN→DEDE→EN
Parallel only22.826.7
+ German-only sentences (dummy source)23.2−
+ back-translated synthetic pairs25.730.4

Back-translation improved EN→DE by 2.8–3.4 BLEU and DE→EN by 3.6–3.7 BLEU (newstest2014 and 2015). For Turkish→English, with only 320K parallel sentences, it improved the average over four test sets by 2.7 BLEU. Simply back-translating the target side of the parallel data and mixing it in raised scores by 1.7 on average, but back-translating new monolingual data had a larger effect.

The impact of back-translation quality was also examined. Comparing three sets of synthetic data whose reverse models differed by 6 BLEU, the final EN→DE models differed by only 0.6–0.7 BLEU.

Edunov et al. scaled sampled synthetic data to hundreds of millions of sentences and reached 35 BLEU on WMT'14 English–German.

For back-translation as paraphrasing, QANet added EN→FR→EN and EN→DE→EN paraphrases for reading comprehension on SQuAD (validation set, EM / F1).

Training data (ratio of original : EN-FR-EN : EN-DE-EN)EMF1
Original data only73.682.7
+ EN-FR-EN paraphrases (1:1:0)74.583.2
+ EN-FR-EN and EN-DE-EN paraphrases (1:1:1)74.883.4
More paraphrases (1:2:1)74.383.1
More original data (3:1:1)75.183.8

On Yelp-5 (5-level rating classification) in the UDA paper, back-translation reduced the supervised error rate from 38.36% to 36.71%, and the semi-supervised error rate with 2,500 labels from 50.80% to 41.35%. A method that replaces words with random words (Switchout) achieved 37.24% and 43.38%, respectively.

Practical considerations

  • Preparing translation models takes effort and computation. Sennrich et al. spent about a week on a GPU back-translating 3.6M German sentences. Paraphrasing requires translation models in both directions.
  • Paraphrases are noisier than the originals, so avoid using them much more than the original data. In QANet, raising the proportion of paraphrases lowered accuracy, and using more original data (3:1:1) worked best.
  • Meaning or labels can change. Translation errors can drop a negation or change a proper noun. Sampling produces diverse sentences but can add words not in the source (in an example from Edunov et al., "Mr President," which was not in the source, appeared in the translation).
  • Auxiliary information such as answer positions breaks after translating back. For reading comprehension data, as in QANet, the answer must be located again in the paraphrased passage.
  • Use paraphrases only during training. For evaluation and inference, feed the original sentences as is.

When using back-translation for machine translation, the monolingual data must be target-language (output-side) sentences. In the method of Sennrich et al., only the source side is synthetic, and the target side the model learns to output is genuine human-written text. This is different from translating source-language sentences with a forward model and adding them (which makes the output side machine-translated), so do not mix up the direction.

Comparison with other methods and how to choose

The following table compares ways of using monolingual data and text data augmentation methods from the same perspectives.

MethodWhat is addedRequirementsGenerated sentencesComputational cost
Back-translation (machine translation)Synthetic parallel dataReverse translation model, target-language monolingual dataSource is machine-translated, target is genuineHigh
Dummy sourceParallel data with empty sourceTarget-language monolingual dataNo sourceLow
Language model fusionNothing (a separately trained language model is integrated into translation)Language model−Language model also runs at inference
Back-translation (paraphrasing)Paraphrased sentencesTranslation models in both directionsTend to be natural paraphrasesHigh
EDASentences with modified wordsSynonym dictionaryMay produce unnatural sentencesVery low

Guidelines for choosing are as follows.

  • Machine translation with abundant target-language text: Use back-translation. In the experiments of Sennrich et al., it raised BLEU far more than a dummy source or language model fusion (deep fusion).
  • Augmenting classification or reading comprehension data with natural paraphrases: Use back-translation as paraphrasing, and translate with sampling (e.g., temperature 0.7–0.9) for diversity.
  • Translation models are unavailable, or a quick try is wanted: Use EDA.

The translation models used for back-translation are built with sequence-to-sequence models such as the Transformer.

PyTorch example

Show code
python
import torch
from transformers import MarianMTModel, MarianTokenizer

"""
Augment text classification training data by paraphrasing sentences with back-translation
Uses public Hugging Face translation models (English→French, French→English)
"""

# Hyperparameters
num_paraphrases = 3   # number of paraphrases to generate per sentence
temperature = 0.8     # sampling temperature (0.7–0.9 worked best in the UDA paper)

# 'cuda' if CUDA is available, 'mps' on Apple Silicon, otherwise 'cpu'
device = 'cuda' if torch.cuda.is_available() else 'mps' if torch.backends.mps.is_available() else 'cpu'

forward_name = 'Helsinki-NLP/opus-mt-en-fr'   # English → French (pivot language)
backward_name = 'Helsinki-NLP/opus-mt-fr-en'  # French → English
fwd_tok = MarianTokenizer.from_pretrained(forward_name)
fwd = MarianMTModel.from_pretrained(forward_name).to(device).eval()
bwd_tok = MarianTokenizer.from_pretrained(backward_name)
bwd = MarianMTModel.from_pretrained(backward_name).to(device).eval()


@torch.no_grad()
def translate(texts, tokenizer, model, sample, n=1):
  batch = tokenizer(texts, return_tensors='pt', padding=True, truncation=True).to(device)
  if sample:
    # Sampling: produce diverse translations (Edunov et al., UDA). Returns n per input
    out = model.generate(**batch, do_sample=True, temperature=temperature, top_k=0, num_return_sequences=n, max_new_tokens=128)
  else:
    # Beam search: produce the single most likely translation (Sennrich et al.)
    out = model.generate(**batch, num_beams=5, max_new_tokens=128)
  return tokenizer.batch_decode(out, skip_special_tokens=True)


def back_translate(texts, n=num_paraphrases):
  pivot = translate(texts, fwd_tok, fwd, sample=True, n=1)         # English → French
  return translate(pivot, bwd_tok, bwd, sample=True, n=n)          # French → English (n per sentence)


train_data = [
  ('Given the low budget and production limitations, this movie is very good.', 1),
  ('The plot was dull and the acting felt forced.', 0),
]
texts = [t for t, _ in train_data]
paraphrases = back_translate(texts)

# Add the paraphrases to the training data with the same labels as the originals (not used for evaluation data)
augmented = list(train_data)
for i, (_, label) in enumerate(train_data):
  for p in paraphrases[i * num_paraphrases:(i + 1) * num_paraphrases]:
    augmented.append((p, label))
for text, label in augmented:
  print(label, text)

# For back-translation in machine translation (Sennrich et al.):
#   translate target-language-only sentences y (French here) with the reverse model (French → English) to get synthetic sources x̂,
#   then mix the (x̂, y) pairs with real parallel data and train an English → French model
mono_fr = ['Autrefois, le thé avait été utilisé surtout pour les moines bouddhistes.']
synthetic_pairs = list(zip(translate(mono_fr, bwd_tok, bwd, sample=True), mono_fr))
print(synthetic_pairs)

FAQ

Q. Which pivot language should be chosen?
A.

Choose a language pair with high translation quality. QANet and UDA used English and French, a pair with abundant training data and high-quality translation models. In QANet, adding paraphrases via German on top of French raised F1 by a further 0.2. Going through different languages is thought to increase the diversity of paraphrases.

Q. Is synthetic parallel data as useful as real parallel data?
A.

If the domain matches, it comes fairly close. In the experiments of Edunov et al., synthetic pairs made by back-translating the target side of parallel data achieved 83% of the improvement obtained by adding real parallel data. Real parallel data is still better, so prefer it when available.

Q. Which should be used, EDA or back-translation?
A.

EDA for convenience, back-translation for natural paraphrases. EDA works with just a synonym dictionary but can produce unnatural sentences. Back-translation requires translation models in both directions and more computation, but tends to produce natural paraphrases that preserve meaning, and is also used in semi-supervised UDA.

References

  1. R. Sennrich, B. Haddow, and A. Birch, "Improving Neural Machine Translation Models with Monolingual Data," ACL, 2016.
  2. S. Edunov, M. Ott, M. Auli, and D. Grangier, "Understanding Back-Translation at Scale," EMNLP, 2018.
  3. A. W. Yu, D. Dohan, M.-T. Luong, R. Zhao, K. Chen, M. Norouzi, and Q. V. Le, "QANet: Combining Local Convolution with Global Self-Attention for Reading Comprehension," ICLR, 2018.
  4. Q. Xie, Z. Dai, E. Hovy, M.-T. Luong, and Q. V. Le, "Unsupervised Data Augmentation for Consistency Training," NeurIPS, 2020.