LGAICLMLMay 26, 2023

Randomized Positional Encodings Boost Length Generalization of Transformers

arXiv:2305.16843v1277 citations
Originality Incremental advance
AI Analysis

This addresses a critical limitation in Transformers for tasks requiring length generalization, such as algorithmic reasoning, though it is an incremental improvement over existing positional encoding methods.

The paper tackles the problem of Transformers failing to generalize to sequences of arbitrary length, such as in string duplication tasks, by linking this to out-of-distribution positional encodings and introducing a randomized positional encoding scheme that simulates longer sequences. The result is a 12.0% average increase in test accuracy across 15 algorithmic reasoning tasks, enabling generalization to unseen lengths.

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).

Code Implementations1 repo
Foundations

The foundational work for this paper's niche, ranked by how specifically the neighbourhood builds on it — not by global fame.

Your Notes