Unique Hard Attention: A Tale of Two Sides

Selim Jerad, Anej Svete, Jiaoda Li, Ryan Cotterell · OpenReview

Abstract

Understanding the expressive power of transformers has recently attracted attention, as it offers insights into their abilities and limitations. Many studies analyze unique hard attention transformers, where attention selects a single position that maximizes the attention scores. When multiple positions achieve the maximum score, either the rightmost or the leftmost of those is chosen. In this paper, we highlight the importance of this seeming triviality. Recently, finite-precision transformers with both leftmost- and rightmost-hard attention were shown to be equivalent to Linear Temporal Logic (LTL). We show that this no longer holds with only leftmost-hard attention -- in that case, they correspond to a strictly weaker fragment of LTL. Furthermore, we show that models with leftmost-hard attention are equivalent to soft attention, suggesting they may better approximate real-world transformers than right-attention models. These findings refine the landscape of transformer expressivity and underscore the role of attention directionality.

Introduction

To understand the fundamental capabilities and limitations of transformer architectures, researchers often turn to "Unique Hard Attention" (UHA) models. These idealized versions of the attention mechanism simplify the process by selecting exactly one token—the one with the maximum attention score—rather than distributing focus across multiple tokens. However, a critical implementation detail often overlooked is the tiebreaking rule: when multiple tokens share the same maximum score, does the model select the leftmost or the rightmost occurrence?

While this choice might seem like a minor implementation detail, it fundamentally dictates the computational power of the model. This paper demonstrates that for causal (future-masked) transformers, "leftmost" hard attention is strictly weaker than "rightmost" attention. Crucially, it is the leftmost variant that accurately reflects the behavior of the standard soft-attention transformers used in practice.

The Asymmetry of Tiebreaking

In a causal transformer, where a token can only attend to its predecessors, the direction of tiebreaking creates a significant functional divide. The authors show that rightmost attention can simulate leftmost attention within just two steps. However, the reverse is not true: leftmost attention is physically incapable of simulating rightmost attention.

This stems from the "asymmetry of time." In a sequence, identifying the first time a specific token appeared (leftmost) is computationally simpler for these models than identifying the most recent occurrence (rightmost). Leftmost attention effectively "gets stuck" on the earliest instance and cannot "see" more recent repetitions if the older ones remain in the context.

Theoretical Mapping: Logic and Automata

The research employs formal language theory and mathematical logic to categorize these differences:

  • B-RASP Analysis: By utilizing a Boolean-valued programming language (B-RASP) restricted to leftmost tiebreaking ($B-RASP^\triangleleft_F$), the authors isolated the specific capabilities of this model class.
  • Logical Equivalences: The study proves that leftmost UHA is equivalent to a fragment of Linear Temporal Logic known as $LTL[\diamondsuit^-]$. This logic only allows the model to look into the past using a "sometime in the past" operator, lacking the full expressive power of standard LTL (which describes star-free languages).
  • Automata Theory: These models are linked to Partially Ordered Finite State Automata (POFA). These machines are restricted in their ability to handle complex counting or certain types of nested patterns, further illustrating the limitations of leftmost attention.

Perhaps the most significant finding is the connection to standard finite-precision softmax (soft) attention. While soft attention is often viewed as more flexible than hard attention, the authors demonstrate that it is functionally equivalent to the "weaker" leftmost hard attention. Because soft attention effectively "blurs" multiple positions together, it lacks the surgical precision required to consistently isolate the "most recent" token in a way that rightmost hard attention can. This suggests that leftmost UHA is a much better theoretical proxy for real-world transformers than previously studied models that allowed for rightmost tiebreaking.

Explaining Empirical Phenomena

This theoretical framework provides a rigorous explanation for known empirical struggles. For instance, transformers often fail at the "flip-flop" language task, which requires maintaining the state of a switch based on the most recent instruction. Since leftmost/soft attention is theoretically barred from perfectly identifying the most recent token among duplicates, the model's failure is a matter of architectural capacity rather than just training difficulty.

Furthermore, this explains the success of architectural modifications like ALiBi (Attention with Linear Biases). By manually biasing attention toward more recent tokens, ALiBi compensates for the inherent "leftmost" weakness of soft attention, effectively granting the model the capabilities of a rightmost-attention machine.

Conclusion

The choice between leftmost and rightmost tiebreaking in hard attention is far from trivial; it defines the boundary of what a transformer can compute. By proving that leftmost UHA is equivalent to soft attention and strictly weaker than rightmost UHA, this work refines our understanding of transformer expressivity. It underscores that the "past-facing" nature of causal transformers, combined with standard attention mechanisms, inherently limits their ability to track the most recent occurrences of events—a limitation that must be addressed through specific architectural choices or positional biases.

Summary updated

BibTeX
@inproceedings{jerad2025unique,
  author = {Selim Jerad and Anej Svete and Jiaoda Li and Ryan Cotterell},
  title = {{Unique Hard Attention: A Tale of Two Sides}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2025},
  doi = {10.18653/v1/2025.acl-short.76},
}
Figure