« home

Self Attention

Creator: Petar Veličković (original)

Attention as a weighted sum over a set. Each input embedding ei\vec e_i is scored against the query ej\vec e_j by the attention function aφa_\varphi, giving the weight αij\alpha_{ij}, while fψf_\psi maps the same input to the value being weighted. Multiplying and summing over ii yields the updated embedding ej\vec e_j'. The sum is permutation-invariant, which is why the mechanism applies to unordered sets as readily as to sequences. From arxiv:1706.03762.


Self Attention

  Download

PNGPDFSVG

  Code

  self-attention.typ (157 lines)