# Effective Approaches to Attention-based Neural Machine Translation

Local attention lets translation models read only part of the source

Minh-Thang Luong, Hieu Pham, Christopher D. Manning · arXiv · 2015-8-17

- **Problem** Global attention reads every source word for each output word, which is costly on long inputs.
- **Method** Local attention reads a window of source states around one aligned position instead of all of them. Local-p learns that position with a sigmoid and reweights nearby states with a Gaussian, so it stays differentiable.
- **Results** An ensemble of 8 models scored 25.9 NIST BLEU on newstest2015, compared to 24.9 for the top WMT'15 entry.

## Why one source summary is not enough

Neural machine translation reads a source sentence to its end and then writes the target one word at a time. Earlier systems used the source representation once, to start the decoder state, so the decoder worked from a single summary. Attention lets the decoder look back at a set of source hidden states at every step instead. That fix has a cost: every target word is scored against every source position, which gets expensive for long inputs such as paragraphs.

Hard attention picks a single position and is cheaper, but it is non-differentiable and needs techniques such as reinforcement learning to train. Soft attention spreads weight over every position and is easy to train, but it keeps the full cost. The open question is whether a model can keep soft attention's trainability while reading only part of the source at each step.

## A global and a local attention

The key idea is to keep attention differentiable while limiting how many source positions it reads at each step. The authors build two variants: a global one that reads all source states, and a local one that reads a window around one aligned position. Both start from the top layer of a stacked LSTM and share the same steps after the context vector is formed.

The global model compares the current target hidden state with each source hidden state and turns the scores into alignment weights. With \\(h\_t\\) the target state and \\(\\bar h\_s\\) a source state, the dot score is \\(h\_t^\\top \\bar h\_s\\) and the general score is \\(h\_t^\\top W\_a \\bar h\_s\\). A softmax over all source positions gives the weights \\(a\_t(s)=\\exp(\\mathrm{score}(h\_t,\\bar h\_s))/\\sum\_{s'}\\exp(\\mathrm{score}(h\_t,\\bar h\_{s'}))\\), and the context vector is their weighted average.

The authors also test a location-based score, \\(a\_t=\\mathrm{softmax}(W\_a h\_t)\\), which ignores the source states. The context vector then gives \\(\\tilde h\_t=\\tanh(W\_c\[c\_t; h\_t\])\\), and a softmax of \\(W\_s \\tilde h\_t\\) yields the word distribution.

The local model first chooses an aligned position \\(p\_t\\) and reads only the window \\(\[p\_t-D, p\_t+D\]\\). Its alignment vector has a fixed size of \\(2D+1\\), so it doesn't grow with the sentence. Local-m simply sets \\(p\_t = t\\), which assumes that source and target are roughly monotonic.

## How local-p places its window

Local-p learns the position instead of assuming monotonic alignment. It computes \\(p\_t = S \\cdot \\mathrm{sigmoid}(v\_p^\\top \\tanh(W\_p h\_t))\\), where \\(S\\) is the source sentence length. The sigmoid keeps \\(p\_t\\) in \\(\[0, S\]\\), as a real number. Because \\(p\_t\\) is real, a Gaussian centred at \\(p\_t\\) reshapes the alignment scores so that positions near \\(p\_t\\) count more.

Each weight becomes \\(a\_t(s)=\\mathrm{align}(h\_t,\\bar h\_s)\\exp(-(s-p\_t)^2/(2\\sigma^2))\\). The authors use the same align function as the global model and set \\(\\sigma\\) empirically from \\(D\\). Gradients reach \\(W\_p\\) and \\(v\_p\\) through \\(p\_t\\), so the model stays differentiable almost everywhere. For the local models the window size is set empirically to \\(D = 10\\).

## Feeding attentional vectors forward

The input-feeding approach concatenates each attentional vector \\(\\tilde h\_t\\) with the inputs of the next time steps. Without it, each alignment decision is made on its own, even though a coverage record of past translation would help. Feeding past decisions forward lets the model see its earlier alignments, and it also makes the network deeper in both directions.

The reported models pair feeding with both global and local attention. The authors note that feeding is general and can be applied to stacked recurrent models without attention too.

## Training setup

All models train on WMT'14 English-German data of 4.5M sentence pairs. Each language keeps its top 50K words as vocabulary, and other words map to a unk token. The stacked LSTM has 4 layers with 1000 cells each and 1000-dimensional embeddings. Sentence pairs longer than 50 words are filtered out during training.

Hyperparameters are selected on newstest2013 with 3000 sentences. Reported results use newstest2014 with 2737 sentences and newstest2015 with 2169 sentences. The LSTMs use dropout with probability 0.2, and dropout models train for 12 epochs. A single Tesla K40 GPU processes 1K target words per second, so one model takes 7-10 days to train.

## English-German gains step by step

Table 1 builds the system up one change at a time, so each gain can be traced. Reversing the source sentence added 1.3 BLEU, and dropout added 1.4 more. Global attention then reached 16.8, which is 2.8 above the dropout model at 14.0. Adding input-feeding raised the global model from 16.8 to 18.1.

Local-p with feeding reached 19.0, which is 0.9 above the global model with feeding. Measured against the non-attentional dropout model at 14.0, this is a gain of 5.0 BLEU, the headline number. Unk replace then added 1.9 BLEU, moving local-p from 19.0 to 20.9. The authors read this as evidence that the learned alignments help with rare words.

An ensemble of 8 models with different attention types and dropout settings reached 23.0 BLEU. That is 1.4 above the ensemble from Jean et al. at 21.6. On newstest2015 the ensemble with unk replace reached 25.9 NIST BLEU, compared to 24.9 for the top WMT'15 entry. The authors note that their models were trained on WMT'14 data, slightly less than the winning entry used.

## Which alignment function works

Table 4 compares score functions by perplexity before unk replacement and BLEU after it.

The authors read this as the location-based score not learning good alignments. Concat scoring didn't perform well in their implementation, and the authors leave the reason for further analysis. Among these models, local-p is best in both perplexity and BLEU.

## Long sentences and alignment quality

Sentences were grouped by length and BLEU was computed per group. The authors report that quality of the attentional models doesn't degrade as sentences get longer, unlike the non-attentional model. The best model outperformed all other systems in every length bucket.

For alignment, the authors compared learned alignments with gold alignments from 508 English-German Europarl sentences using AER. They forced the models to produce the reference translations and kept, for each target word, the source word with the highest weight. Local-m with general scoring reached an AER of 0.34, lower than the 0.39 of the global location model.

The Berkeley aligner scored 0.32, and local-p reached 0.36. Because AER and translation quality correlate poorly, a lower AER doesn't guarantee better translation.

## Limits of the reported gains

German-English translation didn't reach the state of the art, which is 29.2 for the phrase-based Edinburgh system. Global attention added 2.2 BLEU over the base model at 16.9, and input-feeding added 1.0 more. Dot scoring with dropout added 2.7, and unk replacement added 2.1 more.

The analysis uses only English-German results on newstest2014. Because of limited resources, not every combination of attention type and alignment function was run. Lower AER doesn't imply better translation, so the alignment result remains a separate check.

## Paper info

- **Authors**: Minh-Thang Luong, Hieu Pham, Christopher D. Manning
- **Venue**: arXiv · Preprint
- **First published**: 2015-8-17
- **Added**: 2026-11-11
- **Updated**: 2015-9-20
- **Version**: v5
- **arXiv**: 1508.04025
- **Category**: cs.CL
- **Original paper terms**: [arXiv non-exclusive 1.0](https://arxiv.org/licenses/nonexclusive-distrib/1.0/)
- **What we show**: Paper info and commentary

[Original paper ↗](https://arxiv.org/abs/1508.04025v5) · [PDF ↗](https://arxiv.org/pdf/1508.04025v5)

AI commentary is a separate explanation from the original paper and may contain errors. The original paper and figures follow each source's terms of use and any rights noted separately.

## Quote from the paper

Minh-Thang Luong, Hieu Pham, Christopher D. Manning (2015). Effective Approaches to Attention-based Neural Machine Translation. arXiv:1508.04025v5. https://arxiv.org/abs/1508.04025v5

**BibTeX**

```
@misc{luong2015effective,
  title = {{Effective Approaches to Attention-based Neural Machine Translation}},
  author = {Minh-Thang Luong and Hieu Pham and Christopher D. Manning},
  year = {2015},
  eprint = {1508.04025},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1508.04025v5}
}
```

## Other paper commentary

- [Natural TTS Synthesis by Conditioning WaveNet on Mel Spectrogram Predictions](https://refivu.com/en/papers/596b5353-6c04-4ada-a92e-25d0fee13147-natural-tts-synthesis-by-conditioning-wavenet-on-mel.md)
- [Universal Language Model Fine-tuning for Text Classification](https://refivu.com/en/papers/f2470a4a-1c9b-423c-8757-ba73cfe37b54-universal-language-model-fine-tuning-for-text-classification.md)
- [BART: Denoising Sequence-to-Sequence Pre-training for Natural Language Generation, Translation, and Comprehension](https://refivu.com/en/papers/13b055d5-7dcd-422f-b6d8-3704e3d48533-bart-denoising-sequence-to-sequence-pre-training-for.md)
- [Prefix-Tuning: Optimizing Continuous Prompts for Generation](https://refivu.com/en/papers/01cf041e-b71c-444b-8b44-e94ac976a9db-prefix-tuning-optimizing-continuous-prompts-for-generation.md)
- [Neural Machine Translation of Rare Words with Subword Units](https://refivu.com/en/papers/0950e659-f6cc-4852-b244-bbb2742bf059-neural-machine-translation-of-rare-words-with-subword.md)
- [SQuAD: 100,000+ Questions for Machine Comprehension of Text](https://refivu.com/en/papers/b88d7f5b-b008-4a74-a452-4513427bbf9f-squad-100-000-questions-for-machine-comprehension-of.md)
- [DeepLab: Semantic Image Segmentation with Deep Convolutional Nets, Atrous Convolution, and Fully Connected CRFs](https://refivu.com/en/papers/e76226cf-6d58-4173-918d-455579e5374d-deeplab-semantic-image-segmentation-with-deep-convolutional.md)
- [Rich feature hierarchies for accurate object detection and semantic segmentation](https://refivu.com/en/papers/0abb1ab7-a65a-475d-b57e-af628d8620f3-rich-feature-hierarchies-for-accurate-object-detection-and.md)
- [GloVe: Global Vectors for Word Representation](https://refivu.com/en/papers/d4308808-78ba-4fc7-a70c-6e67f906e337-glove-global-vectors-for-word-representation.md)
- [Off-Policy Deep Reinforcement Learning without Exploration](https://refivu.com/en/papers/997f4405-73fe-49b5-a89f-243df2c90604-off-policy-deep-reinforcement-learning-without-exploration.md)
- [Large Scale GAN Training for High Fidelity Natural Image Synthesis](https://refivu.com/en/papers/93f6ad29-8cca-4630-9a3b-d12f9ad91854-large-scale-gan-training-for-high-fidelity-natural.md)
- [Decoupled Weight Decay Regularization](https://refivu.com/en/papers/19eca1c5-1291-475b-a58c-daedbe769654-decoupled-weight-decay-regularization.md)

## Terms in this paper

- [dropout](https://refivu.com/en/terms/db73f75bbdd3-dropout)
- [LSTM](https://refivu.com/en/terms/ba10547646d9-lstm)
- [BLEU](https://refivu.com/en/terms/42cd9b97719e-bleu)
- [attention mechanism](https://refivu.com/en/terms/977ee0201459-attention-mechanism)
- [newstest2014](https://refivu.com/en/terms/4ef4de9dc349-newstest2014)
- [Neural Machine Translation](https://refivu.com/en/terms/17d91eb90f6d-neural-machine-translation)
- [Global Attention](https://refivu.com/en/terms/0331716cfe41-global-attention)
- [newstest2015](https://refivu.com/en/terms/773c03240f97-newstest2015)
- [RNNsearch](https://refivu.com/en/terms/83d9bbdf5979-rnnsearch)
- [local attention](https://refivu.com/en/terms/a310e53f9ebe-local-attention)

---

AI-written text can contain mistakes. [Refivu](https://refivu.com/en/papers/58ab56a7-1cd5-4c5e-be62-69ff9c1387c7-effective-approaches-to-attention-based-neural-machine)
