Search

Search papers and lessons

Google's Neural Machine Translation System: Bridging the Gap between Human and

Yonghui Wu, Mike Schuster, Zhifeng Chen et al. · 2016

Wu et al. (2016) describe GNMT, a deep LSTM translator with attention, residual connections and wordpieces, which matches or beats phrase-based systems on benchmarks and in human side-by-side tests.

On this page

  • Colour = topic mix
  • Calculus
  • Discrete math
  • Neural network basics
  • Linear algebra
  • Probability
  • Architectures
  • ReadReady to readNot yet

TL;DR

Neural machine translation (NMT) reads a sentence in one language and writes one in another with a single learned network. Until this paper it was usually less accurate than phrase-based systems on large data, and it was slow. Wu et al. (2016) describe GNMT, Google's production system: a deep Long Short-Term Memory encoder and decoder with Attention Mechanism, Residual Connection links, and a shared vocabulary of subword pieces called wordpieces. On WMT benchmarks it matches or beats phrase-based systems, and in human side-by-side tests it closes much of the gap to human translators.

Builds on: Encoder-Decoder Architecture, Attention Mechanism, Beam Search · Leads to: Subword Tokenization, BLEU Score

Why it mattered

GNMT showed that a neural translator could run as a production service at scale. The paper reports that human evaluations found GNMT reduced translation errors by 60% compared with Google's previous phrase-based system on many language pairs. The per-language numbers are in the Results section below.

The paper's design choices are concrete answers to the problems that had blocked NMT in practice: the wordpiece vocabulary, a shared source and target vocabulary, residual connections between stacked LSTM layers, and quantized inference address rare words, copying, depth and slow inference.

The problem

Before GNMT, the paper says, NMT had three weaknesses that kept it behind phrase-based systems, especially on very large training sets. Training took a long time and a lot of compute, which slowed research. Inference was much slower than phrase-based decoding, because the models had many parameters. And NMT handled rare words badly: names, numbers and unusual word forms could be dropped or garbled. Earlier fixes, such as copy mechanisms and attention-based copying, helped, but they were not enough to beat production phrase-based systems across the board.

There was also a depth problem. The paper's experience is that stacked LSTM layers work well up to about 4 layers, barely work with 6, and perform very poorly beyond 8. Translation needs deep networks to capture irregularities in both languages, so depth had to be made trainable.

How it works

GNMT is an encoder-decoder with attention. Here is one short sentence traced through the system, using the paper's wordpiece example.

flowchart LR
  A[Source sentence] --> B[Wordpiece split]
  B --> C[Bidirectional bottom encoder layer]
  C --> D[Stacked unidirectional encoder layers]
  D --> E[Attention over encoder states]
  E --> F[Decoder layers emit wordpieces]
  F --> G[Beam search with length normalization]
  G --> H[Detokenize to words]
  1. Start with the English words "Jet makers feud over seat width with big orders at stake." The wordpiece model, trained on the training data, splits the words into pieces: "_J et _makers _fe ud _over _seat _width _with _big _orders _at _stake". The underscore marks the start of a word, so the original spacing can be recovered.
  2. The bottom encoder layer reads these pieces in both directions at once, so each piece gets context from the words before and after it. The layers above read left to right only.
  3. Residual connections start from the third layer from the bottom, so each deeper layer adds to the signal rather than replacing it. This is what lets the stack reach 8 layers.
  4. At each output step, attention computes a weighted sum of the encoder states, with weights that depend on the decoder's current state. This lets the decoder look at "Jet" or "feud" when it needs them.
  5. The decoder predicts the next target wordpiece from the attention context and the pieces written so far, and it stops at an end-of-sentence symbol.
  6. Beam search keeps several candidate outputs. Length normalization and a coverage penalty stop it from favouring short outputs or dropping source words.
  7. The chosen wordpieces are joined back into words using the underscore markers. Optional reinforcement-learning refinement can run before this step, but the production system does not use it.

The math

The paper's math is a sequence probability, an attention rule and a length-normalised score. Symbols are named in words the first time they appear.

Step 2 in symbols: the sentence probability

Let X=x1,…,xMX = x_1, \ldots, x_M be the source wordpieces and Y=y1,…,yNY = y_1, \ldots, y_N the target wordpieces. The model factorises the probability of the whole output with the chain rule:

P(Y∣X)=∏i=1NP(yi∣y0,y1,…,yi−1; x1,…,xM),P(Y \mid X) = \prod_{i=1}^{N} P(y_i \mid y_0, y_1, \ldots, y_{i-1};\, x_1, \ldots, x_M),

where y0y_0 is a special beginning-of-sentence symbol. Each factor is the probability of the next target piece given the source and the pieces so far.

Step 4 in symbols: attention

Let yi−1\mathbf{y}_{i-1} be the decoder's output from the previous step, and let xt\mathbf{x}_t be the encoder vector for source position tt. The attention score is st=AttentionFunction(yi−1,xt)s_t = \text{AttentionFunction}(\mathbf{y}_{i-1}, \mathbf{x}_t), which the paper implements as a feedforward network with one hidden layer. The weights and context are

pt=exp⁡(st)∑t′=1Mexp⁡(st′),ai=∑t=1Mpt xt.p_t = \frac{\exp(s_t)}{\sum_{t'=1}^{M} \exp(s_{t'})}, \qquad \mathbf{a}_i = \sum_{t=1}^{M} p_t \, \mathbf{x}_t.

The weights ptp_t are positive and sum to 1, and the context ai\mathbf{a}_i is their weighted average of the encoder vectors.

Step 6 in symbols: the length-normalised beam score

Beam search ranks full candidate outputs YY for a source XX with

s(Y,X)=log⁡P(Y∣X)lp(Y)+cp(X;Y),lp(Y)=(5+∣Y∣)α6α.s(Y, X) = \frac{\log P(Y \mid X)}{lp(Y)} + cp(X; Y), \qquad lp(Y) = \frac{(5 + \lvert Y \rvert)^{\alpha}}{6^{\alpha}}.

Here ∣Y∣\lvert Y \rvert is the number of output pieces, α\alpha controls the strength of the length normalisation, and cpcp is the coverage penalty, which rewards outputs whose attention covers each source word. The weight β\beta sets how strongly the coverage penalty counts. With α=0\alpha = 0 and β=0\beta = 0 the decoder falls back to plain beam search.

Worked examples

Example
Tiny: attention weights
  1. Three source positions have scores s=(1,2,3)s = (1, 2, 3).
  2. Exponentiate each: e1≈2.718e^1 \approx 2.718, e2≈7.389e^2 \approx 7.389, e3≈20.086e^3 \approx 20.086.
  3. Their sum is about 30.193.
  4. The weights are p≈(0.090,0.245,0.665)p \approx (0.090, 0.245, 0.665), which add to 1.
  5. Suppose the three encoder vectors are the numbers (10,20,30)(10, 20, 30). The context is 0.090⋅10+0.245⋅20+0.665⋅30≈25.750.090 \cdot 10 + 0.245 \cdot 20 + 0.665 \cdot 30 \approx 25.75.
  6. The context sits closest to the position with the highest score, because the weights favour it.
Example
Standard: length normalisation flips a ranking
  1. Set α=0.5\alpha = 0.5.
  2. A one-piece output has ∣Y∣=1\lvert Y \rvert = 1, so lp=(6/6)0.5=1lp = (6 / 6)^{0.5} = 1. Suppose its log probability is −1.6-1.6. Its score is −1.6-1.6.
  3. A five-piece output has ∣Y∣=5\lvert Y \rvert = 5, so lp=(10/6)0.5≈1.291lp = (10 / 6)^{0.5} \approx 1.291. Suppose its log probability is −2.0-2.0. Its score is −2.0/1.291≈−1.549-2.0 / 1.291 \approx -1.549.
  4. Without normalisation, −1.6-1.6 beats −2.0-2.0, so the one-piece output wins.
  5. With normalisation, −1.549-1.549 beats −1.6-1.6, so the five-piece output wins.
  6. Length normalisation therefore stops the decoder from preferring short outputs just because each extra piece costs some log probability.
Example
Realistic: the wordpiece gain on WMT En to Fr and En to De
  1. On WMT En to Fr, the word-based single model scores 37.90 BLEU, and the best wordpiece model, WPM-32K, scores 38.95.
  2. On WMT En to De, the word-based model scores 23.12 BLEU, and WPM-32K scores 24.61.
  3. Compute the BLEU gain of WPM-32K over the word model on En to Fr. The answer is 38.95−37.90=1.0538.95 - 37.90 = 1.05 points.
  4. Compute the same gain on En to De.

Try it: what is the En to De gain? Answer: 24.61−23.12=1.4924.61 - 23.12 = 1.49 points. The best wordpiece model is ahead of the word model on both pairs, though not every wordpiece size beats it (WPM-16K scores 37.60 on En to Fr).

Results

Single-model BLEU. On WMT En to Fr (newstest2014), the best single wordpiece model reaches 38.95 BLEU, averaged over 8 trained models, and the best individual run reaches 39.37. Phrase-based PBMT scores 37.0. The paper's table also lists Deep-Att with PosUnk at 39.2, which is higher than the single-model GNMT number, so GNMT does not win every single-model comparison. On WMT En to De, WPM-32K scores 24.61, against 20.7 for PBMT.

Ensembles and RL refinement. An ensemble of 8 RL-refined models reaches 41.16 BLEU on En to Fr, above the 40.4 of an ensemble of 8 Deep-Att with PosUnk models. RL refinement lifts En to Fr from 38.95 to 39.92 for single models, but on En to De it moves 24.67 to 24.60, a slight drop on test.

Human side-by-side. On 500 sentences for En to Fr, raters scored PBMT at 3.87, NMT before RL at 4.46, NMT after RL at 4.44, and human translations at 4.82, on a 0 to 6 scale. The paper's reading is that RL improves BLEU but barely changes the human impression.

Production data. On Google's production corpora, the paper reports mean side-by-side scores for PBMT, GNMT and humans. For English to French the scores are 4.932, 5.295 and 5.496, a relative improvement of 64% over PBMT on the paper's measure. The paper reports similar gains for other pairs, from 58% to 87%.

Speed. On CPU, the WPM-32K model decodes a sentence in 0.2118 seconds on the En to Fr test set, against 1.0530 seconds for the pure character model.

Limits. The authors say the human test used only 500 side-by-side examples, and that BLEU may not track human quality well. They list testing on particularly hard cases and longer inputs as future work. RL refinement is not used for the production models.

Common mistakes

It is tempting to think that a higher BLEU score always means a better translation. In fact the paper says BLEU does not fully capture translation quality, and that RL raises BLEU by about a point on En to Fr while changing human ratings very little.

It is tempting to think that wordpieces are just characters. In fact they are learned from the data, so common words stay whole and rare words are split into meaningful pieces. The character model is also trained, but the paper finds it much slower at decoding.

It is tempting to think that residual connections are only a training trick. In fact the paper's depth finding is what makes them necessary: plain stacked LSTMs work well only up to about 4 layers, and GNMT uses 8 encoder and 8 decoder layers.

It is tempting to think that quantization is free. In fact the paper notes that quantization errors can be amplified after many unrolled steps or through a deep LSTM stack, which is why its quantizable model needed special handling.

When to use it: for a large, parallel-corpus translation service where a deep encoder-decoder with attention can be trained. When not to use it: when training data is small, when latency must be very low without quantization, or when BLEU alone is taken as proof of quality. Alternatives: the phrase-based system the paper compares against, and earlier sequence-to-sequence models such as Sequence to Sequence Learning with Neural Networks.

Reading guide

Check yourself

QuestionWhat is the purpose of the shared wordpiece vocabulary across source and target languages, according to the paper?Show answer

It makes the same string segment the same way in source and target, so names and numbers that should be copied from source to target are easier for the model to copy. The paper notes that this shared model makes copying tokens easier to learn.

QuestionA hypothetical output has 4 pieces, and α=0.5\alpha = 0.5. What is its length penalty factor lp(Y)lp(Y)?Show answer

Apply lp(Y)=(5+∣Y∣)α/6αlp(Y) = (5 + \lvert Y \rvert)^{\alpha} / 6^{\alpha} with ∣Y∣=4\lvert Y \rvert = 4. This gives (9/6)0.5=1.50.5≈1.22(9 / 6)^{0.5} = 1.5^{0.5} \approx 1.22.

QuestionThe paper reports that RL refinement improves BLEU on En to Fr but barely changes human side-by-side ratings. What three explanations does the paper give?Show answer

The paper gives three: the relatively small side-by-side sample of 500 examples, the small BLEU gain of about 0.81 after ensembling, which may be below what human raters can detect, and a possible mismatch between BLEU and the translation quality humans perceive.

QuestionA team wants to run GNMT-style inference on cheaper hardware using quantized arithmetic. Using the paper's warning, what should it check before trusting the output quality?Show answer

It should check that the quantization error does not grow too much. The paper warns that errors can be amplified after many unrolled steps or through a deep LSTM stack, so quality must be measured on the deployed quantized model, not assumed from the CNN results in earlier quantization studies, which used models with far fewer layers.

Sources

Read the full paper

Yonghui Wu, Mike Schuster, Zhifeng Chen et al., 2016. arXiv:1609.08144