Bayesian Attention Mechanism: A Probabilistic Framework for Positional Encoding and Context Length Extrapolation
Not on the map. Why?
Abstract (arXiv)
Transformer-based language models rely on positional encoding (PE) to handle token order and support context length extrapolation. However, existing PE methods lack theoretical clarity and rely on limited evaluation metrics to substantiate their extrapolation claims. We propose the Bayesian Attention Mechanism (BAM), a theoretical framework that formulates positional encoding as a prior within a probabilistic model. BAM unifies existing methods (e.g., NoPE and ALiBi) and motivates a new Generalized Gaussian positional prior that substantially improves long-context generalization. Empirically, BAM enables accurate information retrieval at 500× the training context length, outperforming previous state-of-the-art context length generalization in long context retrieval accuracy while maintaining comparable perplexity and introducing minimal additional parameters.
Key facts. Cited by 3 papers in the map (data through 14 Oct 2026). Builds on 23 of its 24 references that are in the map. First posted on arXiv 28 May 2025.
Builds on
23 of 24 references.
References · 23
- 2017Attention Is All You Needcited by 60,361
- 2024The Llama 3 Herd of Modelscited by 14,715
- 2019Exploring the Limits of Transfer Learning with a Unified Text-to-Text Transformercited by 14,599
- 2020Measuring Massive Multitask Language Understandingcited by 7,963
- 2018Think you have Solved Question Answering? Try ARC, the AI2 Reasoning Challengecited by 4,886
- 2021RoFormer: Enhanced Transformer with Rotary Position Embeddingcited by 4,703
- 2023Lost in the Middle: How Language Models Use Long Contextscited by 3,455
- 2023Mistral 7Bcited by 3,164
- 2020GLU Variants Improve Transformercited by 1,804
- 2019Root Mean Square Layer Normalizationcited by 1,480
- 2024RULER: What's the Real Context Size of Your Long-Context Language Models?cited by 1,346
- 2024The FineWeb Datasets: Decanting the Web for the Finest Text Data at Scalecited by 1,160
11 more
- 2021Train Short, Test Long: Attention with Linear Biases Enables Input Length Extrapolationcited by 1,103
- 2024LongBench v2: Towards Deeper Understanding and Reasoning on Realistic Long-context Multitaskscited by 379
- 2023The Impact of Positional Encoding on Length Generalization in Transformerscited by 327
- 2023Landmark Attention: Random-Access Infinite Context Length for Transformerscited by 213
- 2022Transformer Language Models without Positional Encodings Still Learn Positional Informationcited by 150
- 2023Full Stack Optimization of Transformer Inference: a Surveycited by 80
- 2023Advancing Transformer Architecture in Long-Context Large Language Models: A Comprehensive Surveycited by 72
- 2024Can Perplexity Reflect Large Language Model's Ability in Long Text Understanding?cited by 45
- 2025Scalable-Softmax Is Superior for Attentioncited by 45
- 2023Attention: Marginal Probability is All You Need?cited by 4
- 2025Computation Mechanism Behind LLM Position Generalizationcited by 2
Built on by
Citing papers per year: 2025: 1; 2026: 2.
3 papers.
- 2026A Probabilistic Interpretation of KV Cache Eviction28 Aug 2026
- 2026The Transformer as a Polar State Estimator10 May 2026
- 2025Robust Filter Attention: Self-Attention as Precision-Weighted State Estimation4 Sep 2025