Recent work [1]} has shown that self-attention with sufficient number of heads and the right geometric biases can simulate convolutions, suggesting a deeper relationship between self-attention and convolutions. Self-attention has been viewed as a method to directly capture relationships between distant pixels [2]}, [3]}, [4]}.
It has also been interpreted as a specific instantiation of the classic technique of non-local means [5]}, [6]}.
The perspective that we discuss in this section is one that views self-attention as generating spatially varying filters, in contrast to the reuse of the same filter across every spatial location in standard convolutions [7]}.
To observe this, we write self-attention and convolution as specific instances of a general spatial pooling function.
Given an input \(x \in \mathcal {R}^{H \times W \times c_{in}}\) , where \(H\)  is the height, \(W\)  is the width, and \(c_{in}\)  is the number of input channels, we define a local 2D pooling function that computes an output at location \((i, j)\) , \(y_{ij} \in \mathcal {R}^{c_{out}}\)  as
\(y_{ij} = \sum _{a, b \in \mathcal {N}(i, j)} f(i, j, a, b) x_{ab}, \) 
