Share your thoughts, 1 month free Claude Pro on usSee more
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
1424
Code GenerationHumanEval
Pass@124.8
1048
Language UnderstandingMMLU
Accuracy65.7
844
Long-context UnderstandingLongBench
Overall Average Score27.9
143
Language ModelingProof-pile
Perplexity5.8
130
Long-context UnderstandingRULER
Score71.5
66
Language ModelingGovReport
Perplexity3.6
50
Multi-needle retrievalNIAH (M)
Accuracy (NIAH M)73.7
35
Long-context ReasoningBABILong
Err (2k Context)82.9
16
Algorithmic ReasoningAlgorithmic Reasoning Suite Unseen Length (test)
Even Pairs100
11
Showing 10 of 19 rows

Other info

Code

Follow for update