Lune

ICLR2026Top-tier venue

Bayesian Attention Mechanism: A Probabilistic Framework for Positional Encoding and Context Length Extrapolation

Arthur S. Bianchessi, Yasmin C. Aguirre, Rodrigo C. Barros, Lucas S. Kupssinskü

Abstract

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×500\times the training context length, outperforming previous state-of-the-art context length generalization by more than 25×25\times in retrieval accuracy while maintaining comparable perplexity and introducing minimal additional parameters.

Ask Lune

Know this paper in minutes, not an afternoon.

Lune can read every page of it and the top-tier papers that cite it, and gives you its claims, its evidence and its limits, each one cited to the paper it comes from. No skimming, no AI slop.

1 top-tier paper has cited it since. Know what they found before your reviewers do.

Questions to start from

Lune can draw on

the full paper · the top-tier papers that cite it · related work

Get the answer

Free to start. No credit card required.

Lineage

  • The Impact of Positional Encoding on Length Generalization in Transformers cites Train Short, Test Long: Attention with Linear Biases Enables Input Length Extrapolation
  • The Impact of Positional Encoding on Length Generalization in Transformers cites Transformer Language Models without Positional Encodings Still Learn Positional Information
  • Random-Access Infinite Context Length for Transformers cites Train Short, Test Long: Attention with Linear Biases Enables Input Length Extrapolation
  • Random-Access Infinite Context Length for Transformers cites Transformer Language Models without Positional Encodings Still Learn Positional Information
  • Transformer Language Models without Positional Encodings Still Learn Positional Information cites Train Short, Test Long: Attention with Linear Biases Enables Input Length Extrapolation
  • Robust Filter Attention: Self-Attention as a Parallel State Estimator cites Train Short, Test Long: Attention with Linear Biases Enables Input Length Extrapolation
Builds onCited byLeft to right by year; the more cited, the higher.

Cited by top-tier papers1

  1. Robust Filter Attention: Self-Attention as a Parallel State EstimatorPeter RacioppoICML 2026

Builds on7

  1. Measuring Massive Multitask Language UnderstandingDan Hendrycks, Collin Burns, Steven Basart, Andy Zou et al.ICLR 2021 · 7,905 citations
  2. Train Short, Test Long: Attention with Linear Biases Enables Input Length ExtrapolationOfir Press, Noah A. Smith, Mike LewisICLR 2022 · 1,168 citations
  3. The Impact of Positional Encoding on Length Generalization in TransformersAmirhossein Kazemnejad, Inkit Padhi, Karthikeyan Natesan Ramamurthy, Payel Das et al.NeurIPS 2023 · 444 citations
  4. Random-Access Infinite Context Length for TransformersAmirkeivan Mohtashami, Martin JaggiNeurIPS 2023 · 207 citations
  5. Transformer Language Models without Positional Encodings Still Learn Positional InformationAdi Haviv, Ori Ram, Ofir Press, Peter Izsak et al.EMNLP Findings 2022 · 61 citations

Related papers

  1. Length Generalization of Causal Transformers without Position EncodingJie Wang, Tao Ji, Yuanbin Wu, Hang Yan et al.ACL Findings 2024 · 1 citation
  2. The Role of Sparsity for Length Generalization in LLMsNoah Golowich, Samy Jelassi, David Brandfonbrener, Sham M. Kakade et al.ICML 2025
  3. DAPE: Data-Adaptive Positional Encoding for Length ExtrapolationChuanyang Zheng, Yihang Gao, Han Shi, Minbin Huang et al.NeurIPS 2024 · 42 citations
  4. Functional Interpolation for Relative Positions improves Long Context TransformersShanda Li, Chong You, Guru Guruganesh, Joshua Ainslie et al.ICLR 2024 · 66 citations
  5. Two Stones Hit One Bird: Bilevel Positional Encoding for Better Length ExtrapolationZhenyu He, Guhao Feng, Shengjie Luo, Kai Yang et al.ICML 2024 · 25 citations
Dusk over the sea between two cliffs drawn in fine vertical lines