betaFeedback

WorksComputer Science

Exact-Solution Volume and Length Generalization in Transformers

Abstract

Research on transformer expressivity shows whether a transformer is capable of solving a given task, but gives little indication of whether the solution, if learned, is generalizable to longer input lengths. We study this question through normalized exact-solution volume (NESV): the fraction of a bounded parameter region that achieves an exact solution on every input of length nn. For fixed-width, single-layer transformers with log⁡n\log n-scaled attention, we establish asymptotic bounds on NESV for four tasks: FIRST (Θ(1)Θ(1)), MAJORITY (Θ(1/(nlog⁡n))Θ(1/(n\log n))), INDEX (Θ(1/n3)Θ(1/n^3)), and PARITY (00). These results are consistent with previous empirical results: the faster the exact-solution volume decays with input length, the harder it is to length-generalize on that task. Looking deeper into INDEX, our volume analysis reveals two error sources that grow with nn. Consequently, we study a transformer model that would structurally eliminate one of the terms, theoretically improving the NESV bound to Θ(n−1)Θ(n^{-1}), and empirically achieving 85% accuracy when tested at 10×10\times the training length, compared with the 60% accuracy of the original model. We conclude that volume analysis may be a useful approach to identify concrete sources of length sensitivity and thus provide insights into task-specific model refinements.

Introduction

Theoretical work on the expressivity of transformers ((cf. the survey by Strobl et al., 2024)) can be seen as a prelude to the study of learnability by transformers, since the existence of a transformer and parameters that solve a given problem is a prerequisite for a transformer to learn to solve the problem. But the existence of a single point in parameter space does not tell us much about whether that point is actually learnable. In this paper, following Kover et al. [11], we ask a more difficult question: given that a problem is solvable by a transformer with some parameters, how large is the set of successful parameters? While Kover et al. [11] arrived at somewhat pessimistic conclusions, we look at single-layer transformers with log nn-scaling and find that, the volume of the set of successful parameters, as a function of the sequence length nn, provides a way to quantify the difficulty of length-generalization in various problems.

The drive for looking beyond expressivity is also visible in experiments on simple sequence tasks. Chiang & Cholak [6] construct exact transformers for FIRST (whether the first symbol is a 1) and PARITY (whether the number of 1’s is odd), but report that standard training fails on PARITY, and that FIRST does not necessarily extrapolate to longer inputs without log nn-scaling. Hahn & Rofin [8] report that fitted PARITY solutions become much sharper as input length grows than fitted solutions for FIRST and MAJORITY (whether there are more 1’s than 0’s). Thus, tasks that are all expressible can behave differently under training and length extrapolation.

Such findings motivate examining the geometry of the parameter sets that implement a task. In related work on loss landscapes, Chiang et al. [7] argue that the geometry and volume of low-loss regions can explain part of neural-network generalization without relying entirely on the implicit bias of gradient descent. We study a related exact-solution quantity at each finite input length. For a fixed task and architecture, we restrict the trainable parameters to a bounded region and measure the fraction that correctly solves the task on every input of length nn. We call this quantity the normalized exact-solution volume (NESV). Its dependence on nn describes how the full set of exact solutions changes as the computation is required to handle longer inputs. With uniform sampling over the bounded parameter region, this is the probability of sampling an exact solution. Comparing this baseline with empirical training results can help distinguish the effects of initialization and optimization from the nature of the task and the selected transformer model in terms of learnability.

We consider four binary classification tasks on binary strings. FIRST returns the first input symbol, whereas INDEX returns the symbol at a position specified by one of the input tokens. MAJORITY returns whether more than half of input symbols are 1’s, whereas PARITY returns whether the number of 1’s is odd. We refer to the first pair as positional tasks, and the second pair as counting tasks.

We conduct our analyses on the simplest models suited to solve the corresponding problems. In all cases, we only consider single-layer transformers. For the positional tasks, we use a model with positional encoding (j,j2)(j, j^2) where the Query and Key maps only depend on token positions and the Value map only depends on the tokens themselves (following the form of the construction of Bhattamishra et al. [4]). For the counting tasks, the positions of the tokens are irrelevant, so we primarily use a model without positional encoding. We also examined a model with sinusoidal positional encoding (sin⁡(j),cos⁡(j))(\sin(j), \cos(j)).

See Table 1 for a summary of the asymptotic bounds obtained with respect to input length nn. Under the positional model Apos\mathcal{A}_{\mathrm{pos}}, the NESV for INDEX is Θ(n−3)\Theta(n^{-3}), while FIRST has constant NESV. The sinusoidal model Asin\mathcal{A}_{\mathrm{sin}} has volume 0 for both. Under the position-free model Agen\mathcal{A}_{\mathrm{gen}}, the NESV for MAJORITY is Θ(1/(nlog⁡n))\Theta(1/(n \log n)). Under the sinusoidal model Asin\mathcal{A}_{\mathrm{sin}}, the NESV for MAJORITY is instead Θ(1/(n3log⁡n))\Theta(1/(n^3 \log n)). PARITY has a zero NESV whenever n>h+1n > h + 1 for both models, hh being the width of the transformer. This is a direct consequence of the standard one-dimensional capacity of shallow ReLU networks (Arora et al. [1]) in the finite-length setting, and is consistent with the broader result that no one-layer, one-head transformer computes PARITY across all lengths (Kozachinskiy et al., [14]).

TaskPositional (Apos\mathcal{A}_{\mathrm{pos}}) NESVPositional (Apos\mathcal{A}_{\mathrm{pos}}) Acc. (%)General (Agen\mathcal{A}_{\mathrm{gen}}) NESVGeneral (Agen\mathcal{A}_{\mathrm{gen}}) Acc. (%)Sinusoidal (Asin\mathcal{A}_{\mathrm{sin}}) NESVSinusoidal (Asin\mathcal{A}_{\mathrm{sin}}) Acc. (%)Normalized (Anorm\mathcal{A}_{\mathrm{norm}}) NESVNormalized (Anorm\mathcal{A}_{\mathrm{norm}}) Acc. (%)
FIRSTΘ(1)\Theta(1)100.0051.12055.06Θ(1)\Theta(1)100.0
MAJORITY—92.7Θ((nlog⁡n)−1)\Theta((n \log n)^{-1})82.6Θ((n3log⁡n)−1)\Theta((n^3 \log n)^{-1})87.5—92.7
INDEXΘ(n−3)\Theta(n^{-3})59.6051.9050.2Θ(n−1)\Theta(n^{-1})85.1
PARITY0—0—0—0—

Table 1. NESV bounds and mean accuracy at 10× the maximum training length for the four tasks. The models Agen\mathcal{A}_{\mathrm{gen}}, Asin\mathcal{A}_{\mathrm{sin}}, and Apos\mathcal{A}_{\mathrm{pos}} are described in § 2.2, while Anorm\mathcal{A}_{\mathrm{norm}} is described in § 4.2.

We train those tasks under the same protocol. The empirical results are in line with our NESV analysis: the task-model pair whose NESV shrinks faster as nn grows shows worse length generalization. The only counterexample was that, under the general sinusoidal model, MAJORITY trains as well as under the position-free model Agen\mathcal{A}_{\mathrm{gen}}, although the former’s volume shrinks faster with nn.

Among the tasks we examine, INDEX demonstrates particularly bad length generalization (60% average accuracy at ten times training length) despite being expressible (Kozachinskiy et al., 2026a}). Our NESV analysis reveals the underlying mechanisms. Exact retrieval of a designated position kk requires that position to receive enough attention, so its attention score must remain within a constant of the maximum attention score. Expressing the difference in attention scores between neighboring positions as a function of kk reveals two key error components, one proportional to k2k^2 and another proportional to kk, which are the sources of failing length generalization.

Guided by this analysis, we modify the model so that the error term proportional to k2k^2 no longer grows with input length. This is called the normalized positional model. The NESV improves from Θ(n−3)\Theta(n^{-3}) to Θ(n−1)\Theta(n^{-1}). In our experiments, the modified model also generalizes substantially better on INDEX, achieving an average accuracy of 85% percent at ten times the training length.

Taken together, the results show that expressivity alone can conceal qualitatively different parameter-space behavior. Volume analysis, on the other hand, may offer another useful tool to further identify the computational constraints responsible for learning behaviors and offer insight for task-specific model refinements.

Setup

In this section, we describe the tasks to be analyzed and the transformers to be used in the analysis.

Tasks and exact-solution volume

For n≥1n \ge1, write [n]={1,…,n}[n] = \{1,\ldots,n\} and let w=(w1,…,wn)∈{0,1}nw = (w_1,\ldots,w_n) \in\{0,1\}^n. We study

FIRSTn(w)=w1INDEXn(w,k)=wk,k∈[n],MAJORITYn(w)=1{∑j=1nwj≥n+12}for odd n,PARITYn(w)=(∑j=1nwj) mod 2.\begin{aligned} \mathrm{FIRST}_n(w) &= w_1 \\ \mathrm{INDEX}_n(w,k) &= w_k,\quad k \in[n], \\ \mathrm{MAJORITY}_n(w) &= 1\left\{\sum_{j=1}^{n} w_j \ge\frac{n+1}{2}\right\}\quad\text{for odd }n, \\ \mathrm{PARITY}_n(w) &= \left(\sum_{j=1}^{n}w_j\right)\bmod2. \end{aligned}

For INDEX, the nn tokens w1,…,wnw_1,\ldots,w_n, which we call data tokens, are followed by a single token, which we call the index token, encoding kk. We refer to this as right-hand sequence INDEXing. For the other tasks, there is an index token for consistency’s sake, but it is fixed.

Definition 1 (Normalized exact-solution volume, NESV). For a task TT and transformer model A\mathcal{A}, let SnT,AS_n^{T,\mathcal{A}} be the parameters for which the output is strictly correct on every length-nn input, and on every index kk. For a fixed parameter bound B>0B>0, define

VBT,A(n)=λDA(SnT,A∩[−B,B]DA)(2B)DA.(1)V_B^{T,\mathcal{A}}(n)=\frac{\lambda_{D_{\mathcal{A}}}\left(S_n^{T,\mathcal{A}}\cap[-B,B]^{D_{\mathcal{A}}}\right)}{(2B)^{D_{\mathcal{A}}}}. \tag*{(1)}

Equivalently, (1) is the probability of obtaining a correct solution when each scalar parameter is sampled independently and uniformly from [−B,B][-B,B]. Unless stated otherwise, BB and the hidden width of the FFNN, hh, are fixed as nn grows. Throughout, log⁡\log denotes the natural logarithm; ∥⋅∥2\lVert\cdot\rVert_2 and ∥⋅∥∞\lVert\cdot\rVert_\infty denote the Euclidean and maximum-coordinate norms. Throughout, c,C>0c,C>0 and the constants implicit in the subscripted asymptotic notation such as ΘB,h\Theta_{B,h} may depend on BB and hh, but never on nn; c,Cc,C may change from line to line.

Transformer Models

We consider only single-layer transformers. Let xjx_j denote the jj-th data token and let zz denote the index token. The query, key, and value maps have the form Q(x)=WQx+bQQ(x)=W_Qx+b_Q, K(x)=WKx+bKK(x)=W_Kx+b_K, V(x)=WVx+bVV(x)=W_Vx+b_V. Writing q=Q(z)q=Q(z), kj=K(xj)k_j=K(x_j), vj=V(xj)v_j=V(x_j), the attention output is

αj=exp⁡((log⁡n)qTkj)∑i=1nexp⁡((log⁡n)qTki),A=∑j=1nαjuj.(2)\alpha_j=\frac{\exp((\log n)q^{\mathsf T}k_j)}{\sum_{i=1}^{n}\exp((\log n)q^{\mathsf T}k_i)},\qquad A=\sum_{j=1}^{n}\alpha_j u_j. \tag*{(2)}

The log⁡n\log n factor was proposed by Chiang & Cholak [6] and Nakanishi [16] and has been used in practice in Qwen (Bai et al., [2]). Chen et al. [5] provide additional theoretical justification for this choice. In this paper, this choice is natural since we study positional tasks such as INDEX, where attention must continue to select a particular position as the number of competing positions grows with the input length. We omit the 1/d1/\sqrt{d} factor in conventional log⁡n\log n scaling because dd is constant in nn and does not affect the asymptotic bounds in nn.

The self-attention is followed by a feed-forward network (FFNN) classifier with hidden width hh:

y=W2ReLU⁡(W1A+b1)+b2∈R2,(3)y=W_2\operatorname{ReLU}(W_1A+b_1)+b_2\in\mathbb{R}^2, \tag*{(3)}

where W1∈Rh×2W_1\in\mathbb{R}^{h\times2}, b1∈Rhb_1\in\mathbb{R}^h, W2∈R2×hW_2\in\mathbb{R}^{2\times h}, b2∈R2b_2\in\mathbb{R}^2.

The two coordinates of yy are indexed by the labels {0,1}\{0,1\}, and the predicted label is y^=argmax⁡c∈{0,1}(y)c\hat{y} = \operatorname*{argmax}_{c \in\{0,1\}}(y)_c. When the input needs to be explicit, we write A(w,k)A(w,k) and y(w,k)y(w,k).

We do not use residual connections or layer normalization. Adding them could alter the size and geometry of the exact-solution set; we leave this extension for future work.

In this paper, we consider four models. We describe three of them here; the fourth, Anorm\mathcal{A}_{\mathrm{norm}}, we leave for § 4.2.

In the general model Agen(h)\mathcal{A}_{\mathrm{gen}}(h), the data tokens are xj=ewj∈R2x_j=e_{w_j}\in\mathbb{R}^2, and the index token is z=02z=0_2. The maps Q,K,V:R2→R2Q,K,V:\mathbb{R}^2\to\mathbb{R}^2 are unrestricted affine maps, so q=Q(02)q=Q(0_2), kj=K(ewj)k_j=K(e_{w_j}), and vj=V(ewj)v_j=V(e_{w_j}). So Agen(h)\mathcal{A}_{\mathrm{gen}}(h) has Dcount=5h+20D_{\mathrm{count}}=5h+20 trainable scalar parameters.

We also examined a model, Asin(h)\mathcal{A}_{\mathrm{sin}}(h), with a sinusoidal positional encoding (sin⁡(j),cos⁡(j))(\sin(j),\cos(j)).

For the positional tasks, we use the positional model Apos(h)\mathcal{A}_{\mathrm{pos}}(h). The data token at position jj and the index token encoding kk are

References

  1. [1]Raman Arora, Amitabh Basu, Poorya Mianjy, and Anirbit Mukherjee. Understanding deep neural networks with rectified linear units. In Proceedings of the International Conference on Learning Representations (ICLR), 2018. URL https://openreview.net/pdf?id=B1J_rgRWR.
  2. [2]Jinze Bai, Shuai Bai, Yunfei Chu, Zeyu Cui, Kai Dang, Xiaodong Deng, Yang Fan, Wenbin Ge, Yu Han, Fei Huang, Binyuan Hui, Luo Ji, Mei Li, Junyang Lin, Runji Lin, Dayiheng Liu, Gao Liu, Chengqiang Lu, Keming Lu, Jianxin Ma, Rui Men, Xingzhang Ren, Xuancheng Ren, Chuanqi Tan, Sinan Tan, Jianhong Tu, Peng Wang, Shijie Wang, Wei Wang, Shengguang Wu, Benfeng Xu, Jin Xu, An Yang, Hao Yang, Jian Yang, Shusheng Yang, Yang Yao, Bowen Yu, Hongyi Yuan, Zheng Yuan, Jianwei Zhang, Xingxuan Zhang, Yichang Zhang, Zhenru Zhang, Chang Zhou, Jingren Zhou, Xiaohuan Zhou, and Tianhang Zhu. Qwen technical report, 2023. URL https://arxiv.org/abs/2309.16609.
  3. [3]Satwik Bhattamishra, Arkil Patel, Varun Kanade, and Phil Blunsom. Simplicity bias in transformers and their ability to learn sparse Boolean functions. In Proceedings of the 61st Annual Meeting of the Association for Computational Linguistics, pp. 5767–5791, 2023. doi:10.18653/v1/2023.acl-long.317.DOI
  4. [4]Satwik Bhattamishra, Michael Hahn, Phil Blunsom, and Varun Kanade. Separations in the representational capabilities of transformers and recurrent architectures. In Advances in Neural Information Processing Systems, volume 37, 2024. doi:10.52202/079017-1135.DOI
  5. [5]Shi Chen, Zhengjiang Lin, Yury Polyanskiy, and Philippe Rigollet. Critical attention scaling in long-context transformers. In Proceedings of the International Conference on Learning Representations (ICLR), 2026. URL https://openreview.net/forum?id=7SLtElfqCW.arxiv.org/abs/2510.05554
  6. [6]David Chiang and Peter Cholak. Overcoming a theoretical limitation of self-attention. In Proceedings of the 60th Annual Meeting of the Association for Computational Linguistics, pp. 7654–7664, 2022. doi:10.18653/v1/2022.acl-long.527.DOI
  7. [7]Ping-yeh Chiang, Renkun Ni, David Yu Miller, Arpit Bansal, Jonas Geiping, Micah Goldblum, and Tom Goldstein. Loss landscapes are all you need: Neural network generalization can be explained without the implicit bias of gradient descent. In Proceedings of the International Conference on Learning Representations (ICLR), 2023. URL https://openreview.net/forum?id=QC10RmRbZy9.
  8. [8]Michael Hahn and Mark Rofin. Why are sensitive functions hard for transformers? In Proceedings of the 62nd Annual Meeting of the Association for Computational Linguistics, pp. 14973–15008, 2024. doi:10.18653/v1/2024.acl-long.800.DOI
  9. [9]Alex Henry, Prudhvi Raj Dachapally, Shubham Shantaram Pawar, and Yuxuan Chen. Query-key normalization for transformers. In Findings of the Association for Computational Linguistics: EMNLP 2020, pp. 4246–4253, 2020. doi:10.18653/v1/2020.findings-emnlp.379.
  10. [10]Amirhossein Kazemnejad, Inkit Padhi, Karthikeyan Natesan Ramamurthy, Payel Das, and Siva Reddy. The impact of positional encoding on length generalization in transformers. In Advances in Neural Information Processing Systems, volume 36, pp. 24892–24928, 2023. URL https://proceedings.neurips.cc/paper_files/paper/2023/hash/4e85362c02172c0c6567ce593122d31c-Abstract-Conference.html.arxiv.org/abs/2305.19466
  11. [11]Blanka Kover, Alexandra Butoi, Anej Svete, Michael Hahn, and Ryan Cotterell. Understanding the parameter space geometry of transformers encoding boolean functions. In Proceedings of the International Conference on Machine Learning (ICML), 2026. URL https://arxiv.org/pdf/2606.08768.
  12. [13]Alexander Kozachinsky, Vicente Opazo, and Felipe Urrutia. Indexing: The beginning and the end, 2026a. URL https://arxiv.org/abs/2607.22361.
  13. [14]Alexander Kozachinsky, Tomasz Steifer, and Przemyslaw Walega. Parity, sensitivity, and transformers, 2026b. URL https://arxiv.org/abs/2602.05896.
  14. [15]Ze Liu, Han Hu, Yutong Lin, Zhuliang Yao, Zhenda Xie, Yixuan Wei, Jia Ning, Yue Cao, Zheng Zhang, Li Dong, Furu Wei, and Baining Guo. Swin Transformer V2: Scaling up capacity and resolution. In Proceedings of the IEEE/CVF Conference on Computer Vision and Pattern Recognition (CVPR), pp. 12009–12019, 2022. doi:10.1109/CVPR52688.2022.01170.DOI
  15. [16]Ken M. Nakanishi. Scalable-softmax is superior for attention, 2025. URL https://arxiv.org/abs/2501.19399.
  16. [17]Ofir Press, Noah A. Smith, and Mike Lewis. Train short, test long: Attention with linear biases enables input length extrapolation. In Proceedings of the International Conference on Learning Representations (ICLR), 2022. URL https://openreview.net/forum?id=R8sQPpGCV0.arxiv.org/abs/2108.12409
  17. [19]Lena Strobl, Dana Angluin, and Robert Frank. Concise one-layer transformers can do function evaluation (sometimes), 2025. URL https://arxiv.org/abs/2503.22076.
  18. [20]Yutao Sun, Li Dong, Barun Patra, Shuming Ma, Shaohan Huang, Alon Benhaim, Vishrav Chaudhary, Xia Song, and Furu Wei. A length-extrapolatable transformer. In Proceedings of the 61st Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers), pp. 14590–14604, 2023. doi:10.18653/v1/2023.acl-long.816.DOI

Paper details

vlnc:W_tz696tyc
Version
v1 · latest
Published
Fresh — added to the Hub within the last 30 days
Added
License
CC BY 4.0
Usage

views · 0

downloads · 0

A view counts once per browser per day, a download each time the PDF is requested.

  • Computer Science

generative AI tools

View statement
Looking for related papers…
Contents