Unique Hard Attention: A Tale of Two Sides

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

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 limits of what Transformers can "compute," researchers often study an idealized version called Unique Hard Attention (UHA). In UHA, the model does not look at a weighted average of all previous tokens (soft attention); instead, it selects exactly one token that has the highest attention score.

The Unique Hard Attention (UHA) mechanism selecting a specific token $x_{t^*}$ to update the current state $x_t$.

However, a problem arises when multiple tokens have the exact same maximum score. Most researchers assumed that the choice of tiebreaking—picking the first occurrence (leftmost) or the last occurrence (rightmost)—was a minor implementation detail. This paper challenges that assumption, asking: Does the direction of tiebreaking change the fundamental power of the architecture?

Methodology

The authors categorize the expressive power of these models using formal language theory and mathematical logic. The approach involves several key components:

  • B-RASP: A Boolean-valued version of RASP (a programming language designed to mimic transformer operations) serves as an intermediary to bridge the gap between neural networks and logic.
  • Linear Temporal Logic (LTL): Transformer behaviors are mapped to fragments of LTL, a logic used to describe sequences of events over time.
  • Automata Theory: The models are related to Partially Ordered Finite State Automata (POFA) to provide an exact characterization of the languages these models can recognize.
  • Formal Proofs: Constructive proofs show how any leftmost-UHA transformer can be translated into a specific fragment of LTL ($LTL[\diamondsuit^-]$) and vice versa.

The Asymmetry of Attention

A key insight of this work is that the "two sides" are not equal. In a future-masked setting (where tokens only look at the past), rightmost attention is strictly more powerful. A rightmost-attention model can easily "read" the token immediately to its left ($t-1$). In contrast, a leftmost-attention model cannot do this because it is always biased toward the beginning of the sequence.

This asymmetry explains why soft-attention transformers struggle with certain tasks, such as the "flip-flop" language. These tasks require locating the most recent instance of a specific instruction—a task that is trivial for rightmost attention but impossible for the leftmost/soft-attention logic.

Theoretical Results and Hierarchy

The paper establishes a clear hierarchy of expressivity, mapping transformer variants to formal logic and automata classes.

Theoretical hierarchy of transformer expressivity across different formalisms, showing the equivalence between leftmost UHA and soft attention.

Key findings include:

  • Theorem 3.1: Finite-precision, future-masked leftmost-UHA transformers are strictly weaker than rightmost-UHA transformers.
  • Theorem 3.2: Leftmost-UHA transformers are exactly equivalent to the $LTL[\diamondsuit^-]$ fragment (LTL using only the "past" operator).
  • The Softmax Connection: Leftmost UHA is equivalent to standard soft-attention (softmax) transformers. This suggests that leftmost tiebreaking is a more faithful abstraction of real-world transformers than the rightmost models studied in previous literature.

Discussion and Limitations

These findings provide a theoretical justification for positional encoding schemes like ALiBi, which bias attention toward more recent (rightmost) tokens. Such schemes essentially help the model "unlock" the higher expressivity associated with rightmost tiebreaking.

However, the study has limitations. The proofs rely on a "barebone" idealization of transformers with fixed bit-width and no initial positional information. While standard for theoretical analysis, real-world models use high-precision floats and complex embeddings. Furthermore, the paper focuses on representational capacity rather than learnability via gradient descent. Future work may investigate how temperature scaling and unbounded positional encodings bridge the gap between these theoretical classes in practice.

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