# On the Relationship between Self-Attention and Convolutional Layers

**Authors:** Jean-Baptiste Cordonnier, Andreas Loukas, Martin Jaggi

arXiv: 1911.03584 · 2020-01-13

## TL;DR

This paper investigates the relationship between self-attention and convolutional layers, demonstrating that attention layers can perform convolution and often learn to do so, challenging the traditional view of convolutional layers as primary in vision models.

## Contribution

It proves that multi-head self-attention layers with enough heads are at least as expressive as convolutional layers and shows they learn similar pixel-grid patterns in practice.

## Key findings

- Self-attention layers can perform convolution.
- Attention layers often learn to mimic convolutional operations.
- Attention layers attend to pixel-grid patterns similar to CNNs.

## Abstract

Recent trends of incorporating attention mechanisms in vision have led researchers to reconsider the supremacy of convolutional layers as a primary building block. Beyond helping CNNs to handle long-range dependencies, Ramachandran et al. (2019) showed that attention can completely replace convolution and achieve state-of-the-art performance on vision tasks. This raises the question: do learned attention layers operate similarly to convolutional layers? This work provides evidence that attention layers can perform convolution and, indeed, they often learn to do so in practice. Specifically, we prove that a multi-head self-attention layer with sufficient number of heads is at least as expressive as any convolutional layer. Our numerical experiments then show that self-attention layers attend to pixel-grid patterns similarly to CNN layers, corroborating our analysis. Our code is publicly available.

## Full text

_Full body text omitted from this summary view._ Fetch the complete paper as Markdown: https://tomesphere.com/paper/1911.03584/full.md

## Figures

22 figures with captions in the complete paper: https://tomesphere.com/paper/1911.03584/full.md

## References

25 references — full list in the complete paper: https://tomesphere.com/paper/1911.03584/full.md

---
Source: https://tomesphere.com/paper/1911.03584