Improving Length-Generalization in Transformers via Task Hinting
Not on the map. Why?
Abstract (arXiv)
It has been observed in recent years that transformers have problems with length generalization for certain types of reasoning and arithmetic tasks. In particular, the performance of a transformer model trained on tasks (say addition) up to a certain length (e.g., 5 digit numbers) drops sharply when applied to longer instances of the same problem. This work proposes an approach based on task hinting towards addressing length generalization. Our key idea is that while training the model on task-specific data, it is helpful to simultaneously train the model to solve a simpler but related auxiliary task as well. We study the classical sorting problem as a canonical example to evaluate our approach. We design a multitask training framework and show that task hinting significantly improve length generalization. For sorting we show that it is possible to train models on data consisting of sequences having length at most 20, and improve the test accuracy on sequences of length 100 from less than 1% (for standard training) to more than 92% (via task hinting). Our study uncovers several interesting aspects of length generalization. We observe that while several auxiliary tasks may seem natural a priori, their effectiveness in improving length generalization differs dramatically. We further use probing and visualization-based techniques to understand the internal mechanisms via which the model performs the task, and propose a theoretical construction consistent with the observed learning behaviors of the model. Based on our construction, we show that introducing a small number of length dependent parameters into the training procedure can further boost the performance on unseen lengths. Finally, we also show the efficacy of our task hinting based approach beyond sorting, giving hope that these techniques will be applicable in broader contexts.
Key facts. Cited by 12 papers in the map (data through 7 Oct 2026). Builds on 25 of its 32 references that are in the map. First posted on arXiv 1 Oct 2023.
Builds on
25 of 32 references.
References · 25
- 2018BERT: Pre-training of Deep Bidirectional Transformers for Language Understandingcited by 40,204
- 2014Adam: A Method for Stochastic Optimizationcited by 36,960
- 2020Language Models are Few-Shot Learnerscited by 32,199
- 2023LLaMA: Open and Efficient Foundation Language Modelscited by 13,958
- 2022Chain-of-Thought Prompting Elicits Reasoning in Large Language Modelscited by 12,302
- 2022PaLM: Scaling Language Modeling with Pathwayscited by 5,304
- 2016SGDR: Stochastic Gradient Descent with Warm Restartscited by 4,993
- 2019ALBERT: A Lite BERT for Self-supervised Learning of Language Representationscited by 2,772
- 2021Train Short, Test Long: Attention with Linear Biases Enables Input Length Extrapolationcited by 1,085
- 2021Show Your Work: Scratchpads for Intermediate Computation with Language Modelscited by 871
- 2023Progress measures for grokking via mechanistic interpretabilitycited by 822
- 2022PaLI: A Jointly-Scaled Multilingual Language-Image Modelcited by 762
13 more
- 2022Emergent World Representations: Exploring a Sequence Model Trained on a Synthetic Taskcited by 417
- 2020Multi-Task Learning with Deep Neural Networks: A Surveycited by 374
- 2023Emergent Linear Representations in World Models of Self-Supervised Sequence Modelscited by 313
- 2023Towards Generalist Biomedical AIcited by 286
- 2022Exploring Length Generalization in Large Language Modelscited by 204
- 2021Saturated Transformers are Constant-Depth Threshold Circuitscited by 137
- 2022Unveiling Transformers with LEGO: a synthetic reasoning taskcited by 105
- 2023Goat: Fine-tuned LLaMA Outperforms GPT-4 on Arithmetic Taskscited by 84
- 2023Generalization on the Unseen, Logic Reasoning and Degree Curriculumcited by 73
- 2023Auto-Regressive Next-Token Predictors are Universal Learnerscited by 65
- 2023Length Generalization in Arithmetic Transformerscited by 64
- 2020The EOS Decision and Length Extrapolationcited by 46
- 2019Location Attention for Extrapolation to Longer Sequencescited by 33
Built on by
Citing papers per year: 2023: 3; 2024: 4; 2025: 4; 2026: 1.
12 papers.
- 2023What Algorithms can Transformers Learn? A Study in Length Generalizationcited by 198
- 2024Transformers Can Achieve Length Generalization But Not Robustlycited by 82
- 2024Causal Language Modeling Can Elicit Search and Reasoning Capabilities on Logic Puzzlescited by 35
- 2024Position Coupling: Improving Length Generalization of Arithmetic Transformers Using Task Structurecited by 22
- 2023Why Softmax Attention Outperforms Linear Attentioncited by 15
- 2025Extrapolation by Association: Length Generalization Transfer in Transformerscited by 13
- 2023The Expressibility of Polynomial based Attention Schemecited by 7
- 2025Beyond Single-Task: Robust Multi-Task Length Generalization for LLMscited by 7
- 2025To Infinity and Beyond: Tool-Use Unlocks Length Generalization in State Space Modelscited by 3
- 2025Towards Sampling Data Structures for Tensor Products in Turnstile Streamscited by 1
- 2026Dissecting Linear Recurrent Models: How Different Gating Strategies Drive Selectivity and Generalizationcited by 1
- 2024Block-level Text Spotting with LLMscited by 0
- 2026Dissecting Linear Recurrent Models: How Different Gating Strategies Drive Selectivity and Generalization18 Jan 2026
- 2025To Infinity and Beyond: Tool-Use Unlocks Length Generalization in State Space Models16 Oct 2025
- 2025Towards Sampling Data Structures for Tensor Products in Turnstile Streams4 Oct 2025
- 2025Extrapolation by Association: Length Generalization Transfer in Transformers10 Jun 2025
- 2025Beyond Single-Task: Robust Multi-Task Length Generalization for LLMs17 Feb 2025
- 2024Causal Language Modeling Can Elicit Search and Reasoning Capabilities on Logic Puzzles16 Sep 2024
- 2024Block-level Text Spotting with LLMs19 Jun 2024
- 2024Position Coupling: Improving Length Generalization of Arithmetic Transformers Using Task Structure31 May 2024
- 2024Transformers Can Achieve Length Generalization But Not Robustly14 Feb 2024
- 2023The Expressibility of Polynomial based Attention Scheme30 Oct 2023
- 2023What Algorithms can Transformers Learn? A Study in Length Generalization24 Oct 2023
- 2023Why Softmax Attention Outperforms Linear Attention18 Oct 2023