Length generalization, defined as the ability to extrapolate from shorter training sequences to longer test ones, is a significant challenge for language models. This issue persists even with large-scale Transformers handling relatively straightforward tasks. In this paper, we test the Transformer's ability of length generalization using the task of addition of two integers. We show that the success of length generalization is intricately linked to the data format and the type of position encoding. Using the right combination of data format and position encodings, we show for the first time that standard Transformers can extrapolate to a sequence length that is 2.5x the input length. Nevertheless, unlike in-distribution generalization, length generalization remains fragile, significantly influenced by factors like random weight initialization and training data order, leading to large variances across different random seeds.
翻译:长度泛化,即从较短训练序列外推至较长测试序列的能力,是语言模型面临的重大挑战。即使处理相对简单任务的大规模Transformer也未能解决该问题。本文通过两个整数相加任务测试Transformer的长度泛化能力,证明其成功与否与数据格式和位置编码类型密切相关。采用适当的数据格式与位置编码组合,我们首次证明标准Transformer可外推至输入长度2.5倍的序列。然而,与分布内泛化不同,长度泛化仍显脆弱,显著受随机权重初始化及训练数据顺序等因素影响,导致不同随机种子间存在较大差异。