Profile

Settings

Loading…

← Papers

Help

FAQ

Which features require signing in?

You can read the commentary, paper info, Model Structure and related papers of public papers without signing in. Sign in to manage your account or contact us about your inquiries.

Can I upload a PDF file?

Upload papers with an arXiv or DOI link; the commentary is public to everyone. Papers whose source and terms of use can't be verified, so the commentary can't be made public, can't be uploaded. Uploading PDF files and keeping papers private are for subscribers only, and a paper uploaded as a file is saved as private only. Searching for official info by title runs only when you press the button.

Are the figures and AI commentary accurate?

Figures come only from the original paper, and only those whose terms of use are verified are shown. The commentary is written by AI and may be wrong. Check important claims, numbers and figure context against the evidence in the original paper.

I want to report a copyright issue.

Terms of use and the source of the original paper are on the Paper info tab. If there's a problem, choose "Paper content, figures and copyright" under Contact us and send the paper link, the part in question, and evidence that you hold the rights. Receiving your report doesn't confirm any rights or remove anything right away. You can see the result of the review under My inquiries.

I forgot my password.

If you signed up with email, use Forgot password in the sign-in window to reset it with your verified email. If you signed up with Google, Naver or Kakao, change your password with that service.

What should I include in an inquiry?

Tell us which screen you were on and what you were doing when the problem happened, along with the paper link. Don't include personal information such as passwords, API keys, verification codes or phone numbers. Inquiries and replies are stored in Refivu and you can see them under My inquiries.

How do I delete my account?

In Settings, under My account, press Delete account. Review what will be deleted and complete identity verification to delete your account. For other requests, choose "Account" under Contact us.

Paper commentary

Attention Is All You Need

  • Problem Recurrent sequence models process positions one after another, which blocks parallel training and makes long-range dependencies harder to learn.
  • Method The Transformer drops recurrence and convolution and builds encoder and decoder stacks from multi-head self-attention and position-wise feed-forward layers, with sinusoidal positional encodings added to the embeddings.
  • Results The big Transformer reached 28.4 BLEU on the WMT 2014 English-to-German newstest2014 task.

Why recurrence limits parallel training

Recurrent models compute hidden states one position at a time, with each state built from the previous state and the current input. That chain of dependencies prevents computation from being spread across the positions of one training example, and long sequences make this worse because memory limits how many examples fit in a batch.

Convolutional models such as ByteNet and ConvS2S compute all positions in parallel, but the number of operations needed to relate two positions grows with the distance between them: linearly for ConvS2S and logarithmically for ByteNet. Long paths between positions make distant dependencies harder to learn, so the cost matters for translation quality as well as for speed.

Attention already lets a model relate distant positions, but in nearly all earlier work it sits on top of a recurrent network. The paper asks whether attention alone can carry the whole mapping from input to output, and proposes the Transformer as its answer.

Encoder and decoder stacks

The Transformer is an encoder-decoder model in which the encoder turns the input symbols into a sequence of continuous representations. The decoder then emits output symbols one at a time, and each step consumes the symbols already produced as extra input, which makes it auto-regressive. The overall layout places the encoder on the left and the decoder on the right of the architecture figure.

The encoder stacks six identical layers, and each layer has a multi-head self-attention sub-layer followed by a position-wise feed-forward sub-layer. Each sub-layer is wrapped in a residual connection and then layer normalization, so its output is the following, with Sublayer(x) standing for whatever that sub-layer computes on x. \[ \mathrm{LayerNorm}(x + \mathrm{Sublayer}(x)) \] Every sub-layer and the embedding layers output vectors of size d_model = 512, which keeps the residual additions aligned.

The decoder also has six layers, with a third sub-layer that applies multi-head attention over the encoder output. Its self-attention is masked so that the prediction at position i depends only on known outputs before i; together with offsetting the output embeddings by one position, this keeps generation auto-regressive.

Scaled dot-product and multi-head attention

An attention layer maps queries and key-value pairs to an output, where each output is a weighted sum of the values. In scaled dot-product attention, query-key dot products are divided by the square root of d_k, and a softmax turns them into weights over the values; all queries are processed together as the matrix Q. \[ \mathrm{Attention}(Q,K,V)=\mathrm{softmax}\left(\frac{QK^{T}}{\sqrt{d_k}}\right)V \] Figure 2 shows the single attention computation alongside the multi-head arrangement of parallel attention layers.

The two common choices are additive attention, which scores with a feed-forward network with one hidden layer, and dot-product attention, which matches the paper's method apart from the scaling factor. In practice the dot-product form runs far faster and uses less memory, because it maps onto optimized matrix multiplication. Additive attention performs better than unscaled dot-product attention when d_k is large.

The scaling follows from a variance argument: if the query and key components are independent with mean 0 and variance 1, their dot product has variance d_k, which pushes the softmax into regions with very small gradients for large d_k.

Instead of one attention function over d_model-dimensional vectors, queries, keys and values are projected h times with learned linear maps to d_k, d_k and d_v dimensions, and attention runs on each projection in parallel. \[ \mathrm{MultiHead}(Q,K,V)=\mathrm{Concat}(\mathrm{head}_1,\ldots,\mathrm{head}_h)W^{O}, \quad \mathrm{head}_i=\mathrm{Attention}(QW_i^{Q},KW_i^{K},VW_i^{V}) \] The model uses h = 8 heads with d_k = d_v = d_model/h = 64, so the total cost stays similar to a single head with full dimensionality.

Multi-head attention appears in three places: encoder-decoder attention, where queries come from the decoder and keys and values come from the encoder output; encoder self-attention, where all three come from the previous encoder layer; and decoder self-attention, which is masked. Masking sets the softmax inputs for illegal connections to minus infinity, so those positions receive zero weight.

Feed-forward layers, embeddings and positional signals

Each layer also has a feed-forward network applied to every position separately and identically: two linear maps with a ReLU between them. \[ \mathrm{FFN}(x)=\max(0,\,xW_1+b_1)W_2+b_2 \] Input and output have dimension 512 and the inner layer has dimension 2048. The weights change from layer to layer, and the authors describe the operation as two convolutions with kernel size 1.

Input and output tokens are mapped to d_model vectors by learned embeddings, and the decoder output passes through a learned linear map and softmax to give next-token probabilities.

With no recurrence or convolution, order information has to be injected explicitly, so sine and cosine encodings are added to the embeddings at the bottoms of both stacks. \[ PE_{(pos,2i)}=\sin\left(pos/10000^{2i/d_{model}}\right), \quad PE_{(pos,2i+1)}=\cos\left(pos/10000^{2i/d_{model}}\right) \] Each dimension of the encoding is one sinusoid, and the wavelengths span a geometric range from 2π up to 10000·2π.

The authors hypothesize that, because PE at pos+k is a linear function of PE at pos for any fixed offset k, the model could learn to attend by relative position. Learned positional embeddings gave nearly identical results, and the authors chose the sinusoidal form partly because it may extrapolate to sequences longer than those seen in training.

Per-layer cost and path length

The authors compare three properties per layer: computational complexity, the number of operations that must run in sequence, and the maximum path length between positions.

Self-attention is faster than a recurrent layer when the sequence length n is smaller than the representation dimension d, which the authors note is the usual case for sentence representations in machine translation. A restricted variant would look only at a neighborhood of size r around each output position, giving O(r·n·d) cost and O(n/r) maximum path length; the authors plan to investigate this in future work.

A single convolution with kernel width k < n does not connect every pair of positions; connecting all pairs takes O(n/k) stacked layers for contiguous kernels, or O(log_k(n)) layers for dilated convolutions. Separable convolutions reduce the cost to O(k·n·d + n·d^2), and with k = n this equals a self-attention layer combined with a point-wise feed-forward layer, which is the combination the paper uses.

The authors also report that inspected attention heads appear to learn different tasks and to relate to the syntactic and semantic structure of sentences, with examples given in the appendix.

Training data, hardware and schedule

The English-German models were trained on the WMT 2014 English-German set of about 4.5 million sentence pairs, encoded with byte-pair encoding into a shared vocabulary of about 37000 tokens. The English-French models used the larger WMT 2014 set of 36M sentences, split into a 32000 word-piece vocabulary. Batches contained approximately 25000 source tokens and 25000 target tokens each.

Training ran on one machine with 8 NVIDIA P100 GPUs. A base-model step took about 0.4 seconds, and the base models trained for 100,000 steps, or 12 hours. A big-model step took 1.0 seconds, and the big models trained for 300,000 steps, or 3.5 days.

Label smoothing with value 0.1 is applied during training; the authors say it hurts perplexity but improves accuracy and BLEU.

Translation results against prior systems

On WMT 2014 English-to-German, the big Transformer reaches 28.4 BLEU on newstest2014, which the authors report as more than 2.0 BLEU above the previous best results, including ensembles. Training that model took 3.5 days on 8 P100 GPUs. Training costs are estimated by multiplying training time, GPU count and a sustained FLOPS value for each GPU, using 2.8, 3.7, 6.0 and 9.5 TFLOPS for K80, K40, M40 and P100.

For English-to-French, the abstract gives a single-model BLEU of 41.8 after 3.5 days on eight GPUs, and Table 2 also lists 41.8 for the big model. The results text, however, gives 41.0 BLEU for the big model, and the paper does not reconcile the two values. The English-to-French big model used residual dropout 0.1 instead of 0.3.

Each base model is a single model averaging the last 5 checkpoints, written at 10-minute intervals, and each big model averages the last 20 checkpoints. Decoding uses beam search with beam size 4 and length penalty α = 0.6, with the maximum output length set to input length plus 50 and early termination when possible; these settings were chosen on the development set.

What the variation study changes

The variants alter the base model on the English-to-German development set newstest2013, evaluated with beam search and without checkpoint averaging. The base model reaches 25.8 BLEU with a per-wordpiece perplexity of 4.92; that perplexity uses the authors' byte-pair encoding and is not comparable with per-word perplexity.

In the rows where dropout is 0.0, development BLEU is 24.6 and 25.3, below the 25.8 of the base model with dropout 0.1, which the authors read as dropout helping to avoid over-fitting.

Constituency parsing without task-specific design

A 4-layer Transformer with d_model = 1024 is trained using the WSJ split of the Penn Treebank, about 40K training sentences, and also in a semi-supervised setting with larger corpora of approximately 17M sentences. The vocabulary has 16K tokens for the WSJ-only setting and 32K tokens for the semi-supervised setting. Dropout, learning rates and beam size were chosen after a small number of experiments on the Section 22 development set, and other parameters stayed as in the English-to-German base model.

Inference uses a beam size of 21 and α = 0.3, with the maximum output length increased to input length plus 300.

On Section 23 of WSJ, the 4-layer Transformer reaches 91.3 F1 when trained on WSJ only and 92.7 F1 in the semi-supervised setting. The WSJ-only score is above the 90.4 entries of Petrov et al. (2006) and Zhu et al. (2013), and below the 91.7 discriminative result of Dyer et al. (2016). Table 4 also lists Luong et al. (2015) multi-task at 93.0 F1, which is above the 92.7 semi-supervised score, so the exception named in the text is not the only one in the table.

Limitations

The parsing settings rest on only a small number of experiments on the Section 22 development set. Restricted self-attention for very long inputs is proposed as future work and is not evaluated in the paper.

The English-to-French big-model score appears as 41.8 in the abstract and Table 2 but as 41.0 in the results text, and the paper does not reconcile the two. The translation experiments cover only English-to-German and English-to-French, and the authors list other input and output modalities, local attention for large inputs, and less sequential generation as future directions.

The benefit of sinusoidal encodings for longer sequences is offered as a possibility, and the variant table reports only newstest2013 results without testing sequences longer than those seen in training.

Paper info

Authors
Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N. Gomez, Lukasz Kaiser, Illia Polosukhin
Venue
arXiv · Preprint
First published
2017-6-12
Added
2026-10-20
Updated
2023-8-2
Version
v7
arXiv
1706.03762
Category
cs.CL · cs.LG
Original paper terms
arXiv non-exclusive 1.0
What we show
Paper info and commentary

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

Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N. Gomez, Lukasz Kaiser, Illia Polosukhin (2017). Attention Is All You Need. arXiv:1706.03762v7. https://arxiv.org/abs/1706.03762v7

BibTeX
@misc{vaswani2017attention,
  title = {{Attention Is All You Need}},
  author = {Ashish Vaswani and Noam Shazeer and Niki Parmar and Jakob Uszkoreit and Llion Jones and Aidan N. Gomez and Lukasz Kaiser and Illia Polosukhin},
  year = {2017},
  eprint = {1706.03762},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1706.03762v7}
}

See related papersBrowse other papers

Paper preview
Account security

Connect Google account

If you connect a Google account, you can sign in with it too.

Refivu

Delete account

Refivu
Refivu

Sign up