Multi-Head Attention: Collaborate Instead of Concatenate

Jean-Baptiste Cordonnier, Andreas Loukas, Martin Jaggi
6/29/2020
208 citations
cs.LGcs.CLstat.ML
transformer-attention

Official code: epfml/collaborative-attention (152 stars, Python, Apache-2.0, last commit 2023-06-12).

Abstract

Attention layers are widely used in natural language processing (NLP) and are beginning to influence computer vision architectures. Training very large transformer models allowed significant improvement in both fields, but once trained, these networks show symptoms of over-parameterization.

Show full abstract

For instance, it is known that many attention heads can be pruned without impacting accuracy. This work aims to enhance current understanding on how multiple heads interact. Motivated by the observation that attention heads learn redundant key/query projections, we propose a collaborative multi-head attention layer that enables heads to learn shared projections. Our scheme decreases the number of parameters in an attention layer and can be used as a drop-in replacement in any transformer architecture. Our experiments confirm that sharing key/query dimensions can be exploited in language understanding, machine translation and vision. We also show that it is possible to re-parametrize a pre-trained multi-head attention layer into our collaborative attention layer. Collaborative multi-head attention reduces the size of the key and query projections by 4 for same accuracy and speed. Our code is public.

View on arXivView PDF

Code Implementations(1)

Apache-2.0

Code for Multi-Head Attention: Collaborate Instead of Concatenate

15222PythonJun 2, 20203 years agoApache-2.0

Similar Papers

Cite this paper

@article{cordonnier2020multihead,
  title  = {Multi-Head Attention: Collaborate Instead of Concatenate},
  author = {Jean-Baptiste Cordonnier and Andreas Loukas and Martin Jaggi},
  year   = {2020},
  eprint = {2006.16362},
  archivePrefix = {arXiv},
  url    = {https://arxiv.org/abs/2006.16362}
}

Add a badge to your README

Shows whether official code is linked for this paper.

Code of Paper badge
[![Code of Paper](https://codeofpaper.com/badge/2006.16362.svg)](https://codeofpaper.com/paper/2006.16362)

Discussion