Attention (machine learning)

{{Short description|Machine learning technique}}

{{Machine learning}}

File:Attention_mechanism_overview.svg

Attention is a machine learning method that determines the importance of each component in a sequence relative to the other components in that sequence. In natural language processing, importance is represented by [https://pmc.ncbi.nlm.nih.gov/articles/PMC9007265/ "soft"] weights assigned to each word in a sentence. More generally, attention encodes vectors called token embeddings across a fixed-width sequence that can range from tens to millions of tokens in size.

Unlike "hard" weights, which are computed during the backwards training pass, "soft" weights exist only in the forward pass and therefore change with every step of the input. Earlier designs implemented the attention mechanism in a serial recurrent neural network (RNN) language translation system, but a more recent design, namely the transformer, removed the slower sequential RNN and relied more heavily on the faster parallel attention scheme.

Inspired by ideas about attention in humans, the attention mechanism was developed to address the weaknesses of leveraging information from the hidden layers of recurrent neural networks. Recurrent neural networks favor more recent information contained in words at the end of a sentence, while information earlier in the sentence tends to be attenuated. Attention allows a token equal access to any part of a sentence directly, rather than only through the previous state.

History

{{See also|Timeline of machine learning}}

Academic reviews of the history of the attention mechanism are provided in Niu et al.{{Cite journal |last1=Niu |first1=Zhaoyang |last2=Zhong |first2=Guoqiang |last3=Yu |first3=Hui |date=2021-09-10 |title=A review on the attention mechanism of deep learning |url=https://www.sciencedirect.com/science/article/pii/S092523122100477X |journal=Neurocomputing |volume=452 |pages=48–62 |doi=10.1016/j.neucom.2021.03.091 |issn=0925-2312|url-access=subscription }} and Soydaner.{{Cite journal |last=Soydaner |first=Derya |date=August 2022 |title=Attention mechanism in neural networks: where it comes and where it goes |url=https://link.springer.com/10.1007/s00521-022-07366-3 |journal=Neural Computing and Applications |language=en |volume=34 |issue=16 |pages=13371–13385 |arxiv=2204.13154 |doi=10.1007/s00521-022-07366-3 |issn=0941-0643}}

class="wikitable"

|1950s 1960s

|Psychology biology of attention. cocktail party effect{{cite journal |vauthors=Cherry EC |year=1953 |title=Some Experiments on the Recognition of Speech, with One and with Two Ears |url=http://www.ee.columbia.edu/~dpwe/papers/Cherry53-cpe.pdf |journal=The Journal of the Acoustical Society of America |volume=25 |issue=5 |pages=975–79 |bibcode=1953ASAJ...25..975C |doi=10.1121/1.1907229 |issn=0001-4966 |hdl-access=free |hdl=11858/00-001M-0000-002A-F750-3}} - focusing on content by filtering out background noise. filter model of attention,{{cite book |last=Broadbent |first=D |author-link=Donald Broadbent |title=Perception and Communication |publisher=Pergamon Press |year=1958 |location=London}} partial report paradigm, and saccade control.{{Cite journal |last1=Kowler |first1=Eileen |last2=Anderson |first2=Eric |last3=Dosher |first3=Barbara |last4=Blaser |first4=Erik |date=1995-07-01 |title=The role of attention in the programming of saccades |url=https://dx.doi.org/10.1016/0042-6989%2894%2900279-U |journal=Vision Research |volume=35 |issue=13 |pages=1897–1916 |doi=10.1016/0042-6989(94)00279-U |issn=0042-6989 |pmid=7660596|url-access=subscription }}

1980s

|sigma pi units, higher order neural networks{{Cite journal |last1=Giles |first1=C. Lee |last2=Maxwell |first2=Tom |date=1987-12-01 |title=Learning, invariance, and generalization in high-order neural networks |url=https://opg.optica.org/abstract.cfm?URI=ao-26-23-4972 |journal=Applied Optics |language=en |volume=26 |issue=23 |pages=4972–4978 |doi=10.1364/AO.26.004972 |issn=0003-6935 |pmid=20523475|url-access=subscription }}

1990s

|fast weight controller.Christoph von der Malsburg: The correlation theory of brain function. Internal Report 81-2, MPI Biophysical Chemistry, 1981. http://cogprints.org/1380/1/vdM_correlation.pdf See Reprint in Models of Neural Networks II, chapter 2, pages 95-119. Springer, Berlin, 1994.Jerome A. Feldman, "Dynamic connections in neural networks," Biological Cybernetics, vol. 46, no. 1, pp. 27-39, Dec. 1982.{{Cite journal |last1=Hinton |first1=Geoffrey E. |last2=Plaut |first2=David C. |date=1987 |title=Using Fast Weights to Deblur Old Memories |url=https://escholarship.org/uc/item/0570j1dp |journal=Proceedings of the Annual Meeting of the Cognitive Science Society |language=en |volume=9}} Neuron weights generate fast "dynamic links" similar to keys & values.

2014

|

seq2seq with RNN + Attention. Attention mechanism was added onto RNN encoder-decoder architecture to improve language translation of long sentences. See Overview section.

2015

|Attention applied to images {{Cite web |last1=Vinyals |first1=Oriol |last2=Toshev |first2=Alexander |last3=Bengio |first3=Samy |last4=Erhan |first4=Dumitru |date=2015 |title=Show and Tell: A Neural Image Caption Generator |url=https://www.cv-foundation.org/openaccess/content_cvpr_2015/html/Vinyals_Show_and_Tell_2015_CVPR_paper.html |pages=3156–3164}}{{Cite journal |last1=Xu |first1=Kelvin |last2=Ba |first2=Jimmy |last3=Kiros |first3=Ryan |last4=Cho |first4=Kyunghyun |last5=Courville |first5=Aaron |last6=Salakhudinov |first6=Ruslan |last7=Zemel |first7=Rich |last8=Bengio |first8=Yoshua |date=2015-06-01 |title=Show, Attend and Tell: Neural Image Caption Generation with Visual Attention |url=https://proceedings.mlr.press/v37/xuc15.html |journal=Proceedings of the 32nd International Conference on Machine Learning |language=en |publisher=PMLR |pages=2048–2057}}{{cite arXiv |eprint=1409.0473 |class=cs.CL |first1=Dzmitry |last1=Bahdanau |first2=Kyunghyun |last2=Cho |title=Neural Machine Translation by Jointly Learning to Align and Translate |date=19 May 2016 |last3=Bengio |first3=Yoshua}} (orig-date 1 Sep 2014)

2017

|Transformers {{cite journal |last1=Vaswani |first1=Ashish |author1-link= Ashish Vaswani |last2=Shazeer |first2=Noam |last3=Parmar |first3=Niki |last4=Uszkoreit |first4=Jakob |last5=Jones |first5=Llion |last6=Gomez |first6=Aidan N |author6-link= Aidan Gomez |last7=Kaiser |first7=Łukasz |last8=Polosukhin |first8=Illia |title=Attention is All you Need |journal=Advances in Neural Information Processing Systems |date=2017 |volume=30 |url=https://proceedings.neurips.cc/paper/2017/file/3f5ee243547dee91fbd053c1c4a845aa-Paper.pdf |publisher=Curran Associates, Inc.}} = Attention + position encoding + MLP + skip connections. This design improved accuracy and removed the sequential disadvantages of the RNN.

{{See also|Transformer (deep learning architecture)#History}}

Overview

The modern era of machine attention was revitalized by grafting an attention mechanism (Fig 1. orange) to an Encoder-Decoder.

class="wikitable"

|+

| File:Attention-animated.webm

| {{plain image with caption|File:attention-1-sn.png|Fig 1. Encoder-decoder with attention. Numerical subscripts (100, 300, 500, 9k, 10k) indicate vector sizes while lettered subscripts i and i − 1 indicate time steps. Pinkish regions in H matrix and w vector are zero values. See Legend for details.|align=none|width=500px}}

{| class="wikitable mw-collapsible mw-collapsed"

|+Legend

!Label

!Description

100

|Max. sentence length

300

|Embedding size (word dimension)

500

|Length of hidden vector

9k, 10k

|Dictionary size of input & output languages respectively.

x, Y

|9k and 10k 1-hot dictionary vectors. x → x implemented as a lookup table rather than vector multiplication. Y is the 1-hot maximizer of the linear Decoder layer D; that is, it takes the argmax of D's linear layer output.

x

|300-long word embedding vector. The vectors are usually pre-calculated from other projects such as GloVe or Word2Vec.

h

|500-long encoder hidden vector. At each point in time, this vector summarizes all the preceding words before it. The final h can be viewed as a "sentence" vector, or a thought vector as Hinton calls it.

s

|500-long decoder hidden state vector.

E

|500 neuron recurrent neural network encoder. 500 outputs. Input count is 800–300 from source embedding + 500 from recurrent connections. The encoder feeds directly into the decoder only to initialize it, but not thereafter; hence, that direct connection is shown very faintly.

D

|2-layer decoder. The recurrent layer has 500 neurons and the fully-connected linear layer has 10k neurons (the size of the target vocabulary). The linear layer alone has 5 million (500 × 10k) weights – ~10 times more weights than the recurrent layer.

score

|100-long alignment score

w

|100-long vector attention weight. These are "soft" weights which changes during the forward pass, in contrast to "hard" neuronal weights that change during the learning phase.

A

|Attention module – this can be a dot product of recurrent states, or the query-key-value fully-connected layers. The output is a 100-long vector w.

H

|500×100. 100 hidden vectors h concatenated into a matrix

c

|500-long context vector = H * w. c is a linear combination of h vectors weighted by w.

|}

Figure 2 shows the internal step-by-step operation of the attention block (A) in Fig 1.

{{Image frame|content=700px|width=700|align=center|caption=Figure 2. The diagram shows the attention forward pass calculating correlations of the word "that" with other words in "See that girl run." Given the right weights from training, the network should be able to identify "girl" as a highly correlated word. Some things to note:

  • This example focuses on the attention of a single word "that". In practice, the attention of each word is calculated in parallel to speed up calculations. Simply changing the lowercase "x" vector to the uppercase "X" matrix will yield the formula for this.
  • Softmax scaling {{math|qWkT}} / {{radic|100}} prevents a high variance in {{math|qWkT}} that would allow a single word to excessively dominate the softmax resulting in attention to only one word, as a discrete hard max would do.
  • Notation: the commonly written row-wise {{math|softmax}} formula above assumes that vectors are rows, which runs contrary to the standard math notation of column vectors. More correctly, we should take the transpose of the context vector and use the column-wise {{math|softmax}}, resulting in the more correct form

\begin{align} (XW_v)^T * {[ (W_k X^T) * { (\underline{x}W_q)^T } ]_{sm} } \end{align}.}}

This attention scheme has been compared to the Query-Key analogy of relational databases. That comparison suggests an asymmetric role for the Query and Key vectors, where one item of interest (the Query vector "that") is matched against all possible items (the Key vectors of each word in the sentence). However, both Self and Cross Attentions' parallel calculations matches all tokens of the K matrix with all tokens of the Q matrix; therefore the roles of these vectors are symmetric. Possibly because the simplistic database analogy is flawed, much effort has gone into understanding attention mechanisms further by studying their roles in focused settings, such as in-context learning, masked language tasks, stripped down transformers, bigram statistics, N-gram statistics, pairwise convolutions, and arithmetic factoring.

= Interpreting attention weights =

In translating between languages, alignment is the process of matching words from the source sentence to words of the translated sentence. Networks that perform verbatim translation without regard to word order would show the highest scores along the (dominant) diagonal of the matrix. The off-diagonal dominance shows that the attention mechanism is more nuanced.

Consider an example of translating I love you to French. On the first pass through the decoder, 94% of the attention weight is on the first English word I, so the network offers the word je. On the second pass of the decoder, 88% of the attention weight is on the third English word you, so it offers t'. On the last pass, 95% of the attention weight is on the second English word love, so it offers aime.

In the I love you example, the second word love is aligned with the third word aime. Stacking soft row vectors together for je, t', and aime yields an alignment matrix:

class="wikitable"

!

!I

!love

!you

je

| style="background-color:black; color:white;" |0.94

|0.02

|0.04

t'

|0.11

|0.01

| style="background-color:grey ; color:white;" |0.88

aime

|0.03

| style="background-color:black; color:white;" |0.95

|0.02

Sometimes, alignment can be multiple-to-multiple. For example, the English phrase look it up corresponds to cherchez-le. Thus, "soft" attention weights work better than "hard" attention weights (setting one attention weight to 1, and the others to 0), as we would like the model to make a context vector consisting of a weighted sum of the hidden vectors, rather than "the best one", as there may not be a best hidden vector.

Variants

File:Self-attention_in_CNN,_RNN,_and_self-attention.svg

Many variants of attention implement soft weights, such as

  • fast weight programmers, or fast weight controllers (1992). A "slow" neural network outputs the "fast" weights of another neural network through outer products. The slow network learns by gradient descent. It was later renamed as "linearized self-attention".
  • Bahdanau-style attention, also referred to as additive attention,
  • Luong-style attention, which is known as multiplicative attention,
  • highly parallelizable self-attention introduced in 2016 as decomposable attention{{cite arXiv |eprint=1601.06733 |class=cs.CL |first1=Jianpeng |last1=Cheng |first2=Li |last2=Dong |title=Long Short-Term Memory-Networks for Machine Reading |date=2016-09-20 |last3=Lapata |first3=Mirella}} and successfully used in transformers a year later,
  • positional attention and factorized positional attention.

For convolutional neural networks, attention mechanisms can be distinguished by the dimension on which they operate, namely: spatial attention, channel attention, or combinations.

These variants recombine the encoder-side inputs to redistribute those effects to each target output. Often, a correlation-style matrix of dot products provides the re-weighting coefficients. In the figures below, W is the matrix of context attention weights, similar to the formula in Core Calculations section above.

class="wikitable"
1. encoder-decoder dot product

! 2. encoder-decoder QKV

! 3. encoder-only dot product

! 4. encoder-only QKV

! 5. Pytorch tutorial

File:attn-xy-dot.png

| File:attn-xy-qkv.png

| File:attn-xx-dot.png

| File:attn-xx-qkv.png

| File:attn-pytorch-tutorial.png

class="wikitable mw-collapsible mw-collapsed"

|+ Legend

LabelDescription
Variables X, H, S, TUpper case variables represent the entire sentence, and not just the current word. For example, H is a matrix of the encoder hidden state—one word per column.
S, TS, decoder hidden state; T, target word embedding. In the Pytorch Tutorial variant training phase, T alternates between 2 sources depending on the level of teacher forcing used. T could be the embedding of the network's output word; i.e. embedding(argmax(FC output)). Alternatively with teacher forcing, T could be the embedding of the known correct word which can occur with a constant forcing probability, say 1/2.
X, HH, encoder hidden state; X, input word embeddings.
WAttention coefficients
Qw, Kw, Vw, FCWeight matrices for query, key, value respectively. FC is a fully-connected weight matrix.
⊕, ⊗⊕, vector concatenation; ⊗, matrix multiplication.
corrColumn-wise softmax(matrix of all combinations of dot products). The dot products are xi * xj in variant #3, hi* sj in variant 1, and column i ( Kw * H ) * column j ( Qw * S ) in variant 2, and column i ( Kw * X ) * column j ( Qw * X ) in variant 4. Variant 5 uses a fully-connected layer to determine the coefficients. If the variant is QKV, then the dot products are normalized by the {{math|{{radic|d}}}} where {{math|d}} is the height of the QKV matrices.

Optimizations

= Flash attention =

The size of the attention matrix is proportional to the square of the number of input tokens. Therefore, when the input is long, calculating the attention matrix requires a lot of GPU memory. Flash attention is an implementation that reduces the memory needs and increases efficiency without sacrificing accuracy. It achieves this by partitioning the attention computation into smaller blocks that fit into the GPU's faster on-chip memory, reducing the need to store large intermediate matrices and thus lowering memory usage while increasing computational efficiency.{{Cite web |last=Mittal |first=Aayush |date=2024-07-17 |title=Flash Attention: Revolutionizing Transformer Efficiency |url=https://www.unite.ai/flash-attention-revolutionizing-transformer-efficiency/ |access-date=2024-11-16 |website=Unite.AI |language=en-US}}

= Flex Attention =

Flex Attention https://pytorch.org/blog/flexattention/ is an attention kernel developed by Meta that allows users to modify attention scores prior to softmax and dynamically chooses the optimal attention algorithm.

Self-Attention and Transformers

The major breakthrough came with self-attention, where each element in the input sequence attends to all others, enabling the model to capture global dependencies. This idea was central to the Transformer architecture, which replaced recurrence entirely with attention mechanisms. As a result, Transformers became the foundation for models like BERT, GPT, and T5 (Vaswani et al., 2017).

Applications

Attention is widely used in natural language processing, computer vision, and speech recognition. In NLP, it improves context understanding in tasks like question answering and summarization. In vision, visual attention helps models focus on relevant image regions, enhancing object detection and image captioning.

Mathematical representation

= Standard Scaled Dot-Product Attention =

For matrices: \mathbf{Q}\in\mathbb{R}^{m\times d_k}, \mathbf{K}\in\mathbb{R}^{n\times d_k} and \mathbf{V}\in\mathbb{R}^{n\times d_v}, the scaled dot-product, or QKV attention is defined as:

\text{Attention}(\mathbf{Q}, \mathbf{K}, \mathbf{V}) = \text{softmax}\left(\frac{\mathbf{Q}\mathbf{K}^T}{\sqrt{d_k}}\right)\mathbf{V}\in\mathbb{R}^{m\times d_v}

where {}^T denotes transpose and the softmax function is applied independently to every row of its argument. The matrix \mathbf{Q} contains m queries, while matrices \mathbf{K}, \mathbf{V} jointly contain an unordered set of n key-value pairs. Value vectors in matrix \mathbf{V} are weighted using the weights resulting from the softmax operation, so that the rows of the m-by-d_v output matrix are confined to the convex hull of the points in \mathbb{R}^{d_v} given by the rows of \mathbf{V}.

To understand the permutation invariance and permutation equivariance properties of QKV attention,{{cite arXiv |last1=Lee |first1=Juho |last2=Lee |first2=Yoonho |last3=Kim |first3=Jungtaek |last4=Kosiorek |first4=Adam R |last5=Choi |first5=Seungjin |last6=Teh |first6=Yee Whye |title=Set Transformer: A Framework for Attention-based Permutation-Invariant Neural Networks |date=2018 |class=cs.LG |eprint=1810.00825 }} let \mathbf{A}\in\mathbb{R}^{m\times m} and \mathbf{B}\in\mathbb{R}^{n\times n} be permutation matrices; and \mathbf{D}\in\mathbb{R}^{m\times n} an arbitrary matrix. The softmax function is permutation equivariant in the sense that:

:

\text{softmax}(\mathbf{A}\mathbf{D}\mathbf{B}) = \mathbf{A}\,\text{softmax}(\mathbf{D})\mathbf{B}

By noting that the transpose of a permutation matrix is also its inverse, it follows that:

:

\text{Attention}(\mathbf{A}\mathbf{Q}, \mathbf{B}\mathbf{K}, \mathbf{B}\mathbf{V}) = \mathbf{A}\,\text{Attention}(\mathbf{Q}, \mathbf{K}, \mathbf{V})

which shows that QKV attention is equivariant with respect to re-ordering the queries (rows of \mathbf{Q}); and invariant to re-ordering of the key-value pairs in \mathbf{K},\mathbf{V}. These properties are inherited when applying linear transforms to the inputs and outputs of QKV attention blocks. For example, a simple self-attention function defined as:

:

\mathbf{X}\mapsto\text{Attention}(\mathbf{X}\mathbf{T}_q, \mathbf{X}\mathbf{T}_k, \mathbf{X}\mathbf{T}_v)

is permutation equivariant with respect to re-ordering the rows of the input matrix X in a non-trivial way, because every row of the output is a function of all the rows of the input. Similar properties hold for multi-head attention, which is defined below.

= Masked Attention =

When QKV attention is used as a building block for an autoregressive decoder, and when at training time all input and output matrices have n rows, a masked attention variant is used:

\text{Attention}(\mathbf{Q}, \mathbf{K}, \mathbf{V}) = \text{softmax}\left(\frac{\mathbf{Q}\mathbf{K}^T}{\sqrt{d_k}}+\mathbf{M}\right)\mathbf{V}

where the mask, \mathbf{M}\in\mathbb{R}^{n\times n} is a strictly upper triangular matrix, with zeros on and below the diagonal and -\infty in every element above the diagonal. The softmax output, also in \mathbb{R}^{n\times n} is then lower triangular, with zeros in all elements above the diagonal. The masking ensures that for all 1\le i, row i of the attention output is independent of row j of any of the three input matrices. The permutation invariance and equivariance properties of standard QKV attention do not hold for the masked variant.

= Multi-Head Attention =

File:Encoder cross-attention, multiheaded version.png

Multi-head attention

\text{MultiHead}(\mathbf{Q}, \mathbf{K}, \mathbf{V}) = \text{Concat}(\text{head}_1, ..., \text{head}_h)\mathbf{W}^O

where each head is computed with QKV attention as:

\text{head}_i = \text{Attention}(\mathbf{Q}\mathbf{W}_i^Q, \mathbf{K}\mathbf{W}_i^K, \mathbf{V}\mathbf{W}_i^V)

and \mathbf{W}_i^Q, \mathbf{W}_i^K, \mathbf{W}_i^V, and \mathbf{W}^O are parameter matrices.

The permutation properties of (standard, unmasked) QKV attention apply here also. For permutation matrices, \mathbf{A}, \mathbf{B}:

:

\text{MultiHead}(\mathbf{A}\mathbf{Q}, \mathbf{B}\mathbf{K}, \mathbf{B}\mathbf{V}) = \mathbf{A}\,\text{MultiHead}(\mathbf{Q}, \mathbf{K}, \mathbf{V})

from which we also see that multi-head self-attention:

:

\mathbf{X}\mapsto\text{MultiHead}(\mathbf{X}\mathbf{T}_q, \mathbf{X}\mathbf{T}_k, \mathbf{X}\mathbf{T}_v)

is equivariant with respect to re-ordering of the rows of input matrix X.

= Bahdanau (Additive) Attention =

\text{Attention}(\mathbf{Q}, \mathbf{K}, \mathbf{V}) = \text{softmax}(\tanh(\mathbf{W}_Q\mathbf{Q} + \mathbf{W}_K\mathbf{K})\mathbf{V})

where \mathbf{W}_Q and \mathbf{W}_K are learnable weight matrices.

= Luong Attention (General) =

\text{Attention}(\mathbf{Q}, \mathbf{K}, \mathbf{V}) = \text{softmax}(\mathbf{Q}\mathbf{W}\mathbf{K}^T)\mathbf{V}

where \mathbf{W} is a learnable weight matrix.

= Self Attention =

Self-attention is essentially the same as cross-attention, except that query, key, and value vectors all come from the same model. Both encoder and decoder can use self-attention, but with subtle differences.

For encoder self-attention, we can start with a simple encoder without self-attention, such as an "embedding layer", which simply converts each input word into a vector by a fixed lookup table. This gives a sequence of hidden vectors h_0, h_1, \dots . These can then be applied to a dot-product attention mechanism, to obtain\begin{aligned}

h_0' &= \mathrm{Attention}(h_0 W^Q, HW^K, H W^V) \\

h_1' &= \mathrm{Attention}(h_1 W^Q, HW^K, H W^V) \\

&\cdots

\end{aligned} or more succinctly, H' = \mathrm{Attention}(H W^Q, HW^K, H W^V) . This can be applied repeatedly, to obtain a multilayered encoder. This is the "encoder self-attention", sometimes called the "all-to-all attention", as the vector at every position can attend to every other.

= Masking =

File:Decoder self-attention with causal masking, detailed diagram.pngFor decoder self-attention, all-to-all attention is inappropriate, because during the autoregressive decoding process, the decoder cannot attend to future outputs that has yet to be decoded. This can be solved by forcing the attention weights w_{ij} = 0 for all i < j , called "causal masking". This attention mechanism is the "causally masked self-attention".

See also

References

{{Reflist|refs=

{{ cite web | url = https://pytorch.org/tutorials/intermediate/seq2seq_translation_tutorial.html | title = Pytorch.org seq2seq tutorial | access-date=December 2, 2021 }}

{{Cite book| publisher = MIT Press | isbn = 978-0-262-68053-0 |editor1-last=Rumelhart | editor1-first = David E. |editor2-last=Hinton |editor2-first=G. E. | editor3=PDP Research Group |last1=Rumelhart | first1 = David E. |last2=Hinton |first2=G. E. | last3 = Mcclelland| first3 = James L. |chapter=A General Framework for Parallel Distributed Processing | title = Parallel Distributed Processing, Volume 1: Explorations in the Microstructure of Cognition: Foundations | location = Cambridge, Massachusetts | date = 1987-07-29|chapter-url = https://stanford.edu/~jlmcc/papers/PDP/Chapter2.pdf| language = en}}

{{Cite journal |last1=Schmidhuber|first1=Jürgen|author-link1=Jürgen Schmidhuber|date=1992|title=Learning to control fast-weight memories: an alternative to recurrent nets.|journal=Neural Computation|volume=4|issue=1 |pages=131–139|doi=10.1162/neco.1992.4.1.131 |s2cid=16683347 }}

{{Cite conference | last1=Schlag|first1=Imanol| last2=Irie|first2=Kazuki| last3=Schmidhuber|first3=Jürgen|author-link1=Juergen Schmidhuber|title= Linear Transformers Are Secretly Fast Weight Programmers|publisher=Springer|date=2021 |pages=9355–9366 |book-title= ICML 2021}}

{{ cite arXiv |eprint=2407.12034 |last1=Nguyen |first1=Timothy |title=Understanding Transformers via N-gram Statistics |date=2024 |class=cs.CL }}

{{cite arXiv|last1=Britz|first1=Denny|last2=Goldie|first2=Anna|last3=Luong|first3=Minh-Thanh|last4=Le|first4=Quoc|date=2017-03-21|title=Massive Exploration of Neural Machine Translation Architectures|class=cs.CV|eprint=1703.03906}}

{{ cite arXiv|last1=Luong|first1=Minh-Thang| date=2015-09-20 |title=Effective Approaches to Attention-Based Neural Machine Translation |class=cs.CL| eprint=1508.04025v5}}

{{cite AV media |people = Neil Rhodes |date=2021 |title= CS 152 NN—27: Attention: Keys, Queries, & Values | url=https://www.youtube.com/watch?v=rA28vBqN4RM | access-date=2021-12-22 | time=06:30 }}

{{cite AV media |people = Alfredo Canziani & Yann Lecun |date=2021 |title= NYU Deep Learning course, Spring 2020 | url=https://www.youtube.com/watch?v=f01J0Dri-6k | access-date=2021-12-22 | time=05:30 }}

{{cite AV media |people = Alfredo Canziani & Yann Lecun |date=2021 |title= NYU Deep Learning course, Spring 2020 | url=https://www.youtube.com/watch?v=f01J0Dri-6k | access-date=2021-12-22 | time=20:15 }}

{{ cite web|url=https://pytorch.org/tutorials/intermediate/seq2seq_translation_tutorial.html | title = NLP From Scratch: Translation With a Sequence To Sequence Network and Attention | last=Robertson|first=Sean| website=pytorch.org|access-date=2021-12-22 }}

{{cite arXiv |last1=Bahdanau |first1=Dzmitry |last2=Cho |first2=Kyunghyun |last3=Bengio |first3=Yoshua |title=Neural Machine Translation by Jointly Learning to Align and Translate |date=2014 |class=cs.CL |eprint=1409.0473}}

{{Cite arXiv |last1=Woo |first1=Sanghyun |last2=Park |first2=Jongchan |last3=Lee |first3=Joon-Young |last4=Kweon |first4=In So |date=2018-07-18 |title=CBAM: Convolutional Block Attention Module |class=cs.CV |eprint=1807.06521 }}

{{Cite arXiv|last1=Georgescu |first1=Mariana-Iuliana |last2=Ionescu |first2=Radu Tudor |last3=Miron |first3=Andreea-Iuliana |last4=Savencu |first4=Olivian |last5=Ristea |first5=Nicolae-Catalin |last6=Verga |first6=Nicolae |last7=Khan |first7=Fahad Shahbaz |date=2022-10-12 |title=Multimodal Multi-Head Convolutional Attention with Various Kernel Sizes for Medical Image Super-Resolution |class=eess.IV |eprint=2204.04218 }}

{{Cite book |last1=Hu |first1=Jie |last2=Shen |first2=Li |last3=Sun |first3=Gang |title=2018 IEEE/CVF Conference on Computer Vision and Pattern Recognition |chapter=Squeeze-and-Excitation Networks |year=2018 |chapter-url=https://ieeexplore.ieee.org/document/8578843 |pages=7132–7141 |doi=10.1109/CVPR.2018.00745|arxiv=1709.01507 |isbn=978-1-5386-6420-9 |s2cid=206597034 }}

{{Cite book |last1=Zhu |first1=Xizhou |last2=Cheng |first2=Dazhi |last3=Zhang |first3=Zheng |last4=Lin |first4=Stephen |last5=Dai |first5=Jifeng |title=2019 IEEE/CVF International Conference on Computer Vision (ICCV) |chapter=An Empirical Study of Spatial Attention Mechanisms in Deep Networks |year=2019 |chapter-url=https://ieeexplore.ieee.org/document/9009578 |pages=6687–6696 |doi=10.1109/ICCV.2019.00679|arxiv=1904.05873 |isbn=978-1-7281-4803-8 |s2cid=118673006 }}

{{Cite web|url=https://www.catalyzex.com/paper/learning-positional-attention-for-sequential|title=Learning Positional Attention for Sequential Recommendation

|website=catalyzex.com}}

{{cite journal |last1=Zhang |first1=Ruiqi |title= Trained Transformers Learn Linear Models In-Context

|journal=Journal of Machine Learning Research 1-55 |date=2024 |volume=25 |arxiv=2306.09927 |url=https://jmlr.org/papers/volume25/23-1042/23-1042.pdf}}

{{cite journal|arxiv=2304.07235|last1=Rende |first1=Riccardo |title=Mapping of attention mechanisms to a generalized Potts model |journal=Physical Review Research |year=2024 |volume=6 |issue=2 |page=023057 |doi=10.1103/PhysRevResearch.6.023057 |bibcode=2024PhRvR...6b3057R }}

{{cite arXiv|eprint=2311.01906|last1=He |first1=Bobby |title=Simplifying Transformers Blocks |year=2023 |class=cs.LG }}

{{ cite web|url=https://transformer-circuits.pub | title = Transformer Circuits |website=transformer-circuits.pub }}

{{cite arXiv|eprint=2308.15594|last1=Charton |first1=François |title=Learning the Greatest Common Divisor: Explaining Transformer Predictions |year=2023 |class=cs.LG }}

{{cite AV media |date=2023 |title=Transformer Neural Network Derived From Scratch | url=https://www.youtube.com/watch?v=kWLed8o5M2Y&t=330s | access-date=2024-04-07 | time=05:30 }}

}}