Attention Is All You Need
Vaswani et al., 2017, Attention Is All You Need (Advances in Neural Information Processing Systems 30 (NIPS 2017))
Subscriber deck — free during early access
2 cards in “3.5 Positional Encoding” · whole deck
3.5 Positional Encoding
- Why does the Transformer need positional encodings, and what are they?Without recurrence or convolution the model has no notion of order, so encodings are added to the input embeddings: \(PE_{(pos, 2i)} = \sin(pos / 10000^{2i/d_{\text{model}}})\), \(PE_{(pos, 2i+1)} = \cos(pos / 10000^{2i/d_{\text{model}}})\), sinusoids with wavelengths from \(2\pi\) to \(10000 \cdot 2\pi\).
- Vaswani et al., 2017, Attention Is All You Need (Advances in Neural Information Processing Systems 30 (NIPS 2017)), §3.5
- Why sinusoidal rather than learned positional encodings?For any fixed offset \(k\), \(PE_{pos+k}\) is a linear function of \(PE_{pos}\), which may help attend by relative position, and sinusoids may extrapolate to sequences longer than those seen in training. Learned embeddings gave nearly identical results.
- Vaswani et al., 2017, Attention Is All You Need (Advances in Neural Information Processing Systems 30 (NIPS 2017)), §3.5
Source
- Ashish Vaswani, Noam Shazeer, Niki Parmar, Jakob Uszkoreit, Llion Jones, Aidan N. Gomez, Łukasz Kaiser and Illia Polosukhin. 2017. Attention Is All You Need. In Advances in Neural Information Processing Systems 30 (NIPS 2017). https://papers.nips.cc/paper/2017/hash/3f5ee243547dee91fbd053c1c4a845aa-Abstract.html