Transformer知道的比它们能表达的更多——学习考拉兹序列
Transformers know more than they can tell -- Learning the Collatz sequence
AI总结:
本文研究Transformer对长考拉兹步的预测,发现其准确率受编码基数影响,学习模式与考拉兹序列的循环长度数学性质相关,误差多为循环长度估计错误,为理解语言模型提供了新思路。
摘要:
我们研究了Transformer对长考拉兹步的预测能力,考拉兹步是一种复杂算术函数,可将奇数映射到其在考拉兹序列中的远端后继项(序列规则为:若$u_n$为偶数,则$u_{n+1}=u_n/2$;若$u_n$为奇数,则$u_{n+1}=(3u_n+1)/2$)。模型准确率随输入输出编码所用的基数变化:采用基数24和32时准确率最高可达99.7%,采用基数11和3时准确率分别低至37%和25%。但所有模型无论采用何种基数,都遵循共同的学习模式:随着训练推进,它们会依次学习模$2^p$余数相同的输入类别,在这些类别上达到接近完美的准确率,而在其余所有输入上准确率不足1%。这对应考拉兹序列的一项数学性质:长考拉兹步计算涉及的循环长度可由输入的二进制表示推导得出,该学习模式反映模型正在学习预测与递增循环长度相关的输入。对失败案例的分析显示,几乎所有模型误差都遵循可预测模式,大语言模型常见的幻觉现象几乎从未出现;超过90%的失败案例中,模型完成了正确计算,但错误估计了循环长度。我们的观察完整阐释了模型学到的算法,表明学习这类复杂算术函数的难点在于弄清计算的控制结构——即循环长度。我们认为本文提出的以数学问题为工具理解、解释甚至改进语言模型的方法,可应用于广泛问题并取得丰硕成果。
英文摘要:
We investigate transformer prediction of long Collatz steps, a complex arithmetic function that maps odd integers to their distant successors in the Collatz sequence ( $u_{n+1}=u_n/2$ if $u_n$ is even, $u_{n+1}=(3u_n+1)/2$ if $u_n$ is odd). Model accuracy varies with the base used to encode input and output. It can be as high as $99.7\%$ for bases $24$ and $32$, and as low as $37$ and $25\%$ for bases $11$ and $3$. Yet, all models, no matter the base, follow a common learning pattern. As training proceeds, they learn a sequence of classes of inputs that share the same residual modulo $2^p$. Models achieve near-perfect accuracy on these classes, and less than $1\%$ for all other inputs. This maps to a mathematical property of Collatz sequences: the length of the loops involved in the computation of a long Collatz step can be deduced from the binary representation of its input. The learning pattern reflects the model learning to predict inputs associated with increasing loop lengths. An analysis of failure cases reveals that almost all model errors follow predictable patterns. Hallucination, a common feature of large language models, almost never happens. In over $90\%$ of failures, the model performs the correct calculation, but wrongly estimates loop lengths. Our observations give a full account of the algorithms learned by the models. They suggest that the difficulty of learning such complex arithmetic function lies in figuring the control structure of the computation -- the length of the loops. We believe that the approach outlined here, using mathematical problems as tools for understanding, explaining, and perhaps improving language models, can be applied to a broad range of problems and bear fruitful results.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。