Our new X account is live! Follow @wizwand_team for updates
WorkDL logo mark

Randomized Positional Encodings Boost Length Generalization of Transformers

About

Transformers have impressive generalization capabilities on tasks with a fixed context length. However, they fail to generalize to sequences of arbitrary length, even for seemingly simple tasks such as duplicating a string. Moreover, simply training on longer sequences is inefficient due to the quadratic computation complexity of the global attention mechanism. In this work, we demonstrate that this failure mode is linked to positional encodings being out-of-distribution for longer sequences (even for relative encodings) and introduce a novel family of positional encodings that can overcome this problem. Concretely, our randomized positional encoding scheme simulates the positions of longer sequences and randomly selects an ordered subset to fit the sequence's length. Our large-scale empirical evaluation of 6000 models across 15 algorithmic reasoning tasks shows that our method allows Transformers to generalize to sequences of unseen length (increasing test accuracy by 12.0% on average).

Anian Ruoss, Gr\'egoire Del\'etang, Tim Genewein, Jordi Grau-Moya, R\'obert Csord\'as, Mehdi Bennani, Shane Legg, Joel Veness• 2023

Related benchmarks

TaskDatasetResultRank
Mathematical ReasoningGSM8K
Accuracy56.1
983
Code GenerationHumanEval
Pass@124.8
850
Language UnderstandingMMLU
Accuracy65.7
756
Long-context UnderstandingLongBench
Overall Average Score27.9
115
Language ModelingGovReport
Perplexity3.6
50
Long-context UnderstandingRULER
Score71.5
45
Language ModelingProof-pile
Perplexity5.8
37
Multi-needle retrievalNIAH (M)
Accuracy (NIAH M)73.7
35
Algorithmic ReasoningAlgorithmic Reasoning Suite Unseen Length (test)
Even Pairs100
11
Showing 9 of 9 rows

Other info

Code

Follow for update