Transformer能预测伪随机数,且可泛化到未知模数。
(How) Can Transformers Predict Pseudo-Random Numbers?
- 用嵌入与注意力机制学习数列的算法结构。
- 在模数最大达2^32时仍可准确预测。
- 适合研究模型学习算法能力的研究者。
Transformer在序列建模中表现优异,但其学习机制仍待深入。本文研究Transformer学习线性同余生成器(LCG)生成的伪随机数序列的能力,该序列由递推式 $x_{t+1} = a x_t + c \;\mathrm{mod}\; m$ 定义。实验表明,在足够大的模型容量和多样化的训练数据下,Transformer可在上下文中对未见过的模数 $m$ 与参数 $(a,c)$ 进行预测。当模数固定而参数未知时,模型可成功学习至 $m = 2^{32}$,通过因子分解与按位数字表示实现预测。在更复杂场景下,面对未知模数,模型可泛化至 $m_{\text{test}} = 2^{16}$,采用两步策略:先从上下文估计模数,再利用质因数分解进行预测。我们观察到准确率在模型深度 $d=3$ 处出现显著跃迁,且达到高精度所需的上下文元素数量随模数呈亚线性增长。
原文摘要 · Abstract (English)
Transformers excel at discovering patterns in sequential data, yet their fundamental limitations and learning mechanisms remain crucial topics of investigation. In this paper, we study the ability of Transformers to learn pseudo-random number sequences from linear congruential generators (LCGs), defined by the recurrence relation $x_{t+1} = a x_t + c \;\mathrm{mod}\; m$. We find that with sufficient architectural capacity and training data variety, Transformers can perform in-context prediction of LCG sequences with unseen moduli ($m$) and parameters ($a,c$). By analyzing the embedding layers and attention patterns, we uncover how Transformers develop algorithmic structures to learn these sequences in two scenarios of increasing complexity. First, we investigate how Transformers learn LCG sequences with unseen ($a, c$) but fixed modulus; and demonstrate successful learning up to $m = 2^{32}$. We find that models learn to factorize $m$ and utilize digit-wise number representations to make sequential predictions. In the second, more challenging scenario of unseen moduli, we show that Transformers can generalize to unseen moduli up to $m_{\text{test}} = 2^{16}$. In this case, the model employs a two-step strategy: first estimating the unknown modulus from the context, then utilizing prime factorizations to generate predictions. For this task, we observe a sharp transition in the accuracy at a critical depth $d= 3$. We also find that the number of in-context sequence elements needed to reach high accuracy scales sublinearly with the modulus.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。