Attend or Perish: Benchmarking Attention on Algorithmic Reasoning

Michal Spiegel, Michal Štefánik, Marek Kadlčík, Valeria Ruscio, Martin Fajčík, Josef Kuchař


Abstract
While Transformer models can learn algorithmic tasks and generalize reliably to unseen, in-distribution data, they often fail catastrophically when required to extrapolate to sequence lengths beyond their training regime. Using AttentionSpan, a suite of synthetic diagnostic tasks designed to enable inspection of internal model computations, we analyze the model’s behavior on length extrapolation. Our findings indicate that this failure is not fully explained by an inability to induce general rules for the task. Instead, we identify inconsistent attention patterns as a major contributing factor: information retrieval strategies learned by individual attention heads, which fail to remain stable as sequence length increases. Reinforcing a reference attention pattern at inference time, using no out-of-distribution data, largely recovers accuracy on String Reversal and partially on Value Assignment, while leaving multi-digit arithmetic unresolved. We also study length adaptation, how a model trained on one length adjusts to another by fine-tuning its Key and Query parameters, and find that a single dimension in every attention head is enough, across 4 algorithmic tasks and the RULER benchmark. Adaptation does not carry past the fine-tuned lengths, and our interventions are diagnostic rather than a proposed remedy. We make our benchmark and code publicly available.
Anthology ID:
2026.blackboxnlp-1.41
Volume:
Proceedings of the 9th BlackboxNLP Workshop: Analyzing and Interpreting Neural Networks for NLP
Month:
October
Year:
2026
Address:
Budapest, Hungary
Editors:
Dana Arad, Yonatan Belinkov, Hanjie Chen, Nils Feldhus, Aaron Mueller, Hosein Mohebbi, Gabriele Sarti, Martin Tutek
Venues:
BlackboxNLP | WS
SIG:
Publisher:
Association for Computational Linguistics
Note:
Pages:
707–725
Language:
URL:
https://aclanthology.org/2026.blackboxnlp-1.41/
DOI:
Bibkey:
Cite (ACL):
Michal Spiegel, Michal Štefánik, Marek Kadlčík, Valeria Ruscio, Martin Fajčík, and Josef Kuchař. 2026. Attend or Perish: Benchmarking Attention on Algorithmic Reasoning. In Proceedings of the 9th BlackboxNLP Workshop: Analyzing and Interpreting Neural Networks for NLP, pages 707–725, Budapest, Hungary. Association for Computational Linguistics.
Cite (Informal):
Attend or Perish: Benchmarking Attention on Algorithmic Reasoning (Spiegel et al., BlackboxNLP 2026)
Copy Citation:
PDF:
https://aclanthology.org/2026.blackboxnlp-1.41.pdf