Mega: Moving Average Equipped Gated Attention

The design choices in the Transformer attention mechanism, including weak inductive bias and quadratic computational complexity, have limited its application for modeling long sequences. In this paper, we introduce Mega, a simple, theoretically grounded, single-head gated attention mechanism equipped with (exponential) moving average to incorporate inductive bias of position-aware local dependencies into the position-agnostic attention mechanism. We further propose a variant of Mega that offers linear time and space complexity yet yields only minimal quality loss, by efficiently splitting the whole sequence into multiple chunks with fixed length. Extensive experiments on a wide range of sequence modeling benchmarks, including the Long Range Arena, neural machine translation, auto-regressive language modeling, and image and speech classification, show that Mega achieves significant improvements over other sequence models, including variants of Transformers and recent state space models.

PDF Abstract

Results from the Paper


Task Dataset Model Metric Name Metric Value Global Rank Result Benchmark
Image Classification ImageNet Mega Top 1 Accuracy 82.4% # 491
Number of params 90M # 847
Long-range modeling LRA Mega ListOps 63.14 # 1
Text 90.43 # 1
Retrieval 91.25 # 3
Image 90.44 # 1
Pathfinder 96.01 # 3
Avg 88.21 # 1
Pathfinder-X 97.98 # 3
Long-range modeling LRA Mega-chunk ListOps 58.76 # 11
Text 90.19 # 2
Retrieval 90.97 # 8
Image 85.8 # 11
Pathfinder 94.41 # 7
Avg 85.66 # 8
Pathfinder-X 93.81 # 8
Language Modelling WikiText-103 Mega Test perplexity 18.07 # 30
Number of params 252M # 17
Machine Translation WMT2014 English-German Mega BLEU score 29.01 # 34
SacreBLEU 27.96 # 7
Number of Params 67M # 11
Machine Translation WMT2014 German-English Mega BLEU score 33.12 # 4

Methods