Counting Like Transformers: Compiling Temporal Counting Logic Into Softmax Transformers

Andy Yang, David Chiang

TL;DR

This paper introduces a new temporal counting logic, $\textbf{K}_t$[#], and a programming language variant, $\textbf{C-RASP}$, to formally characterize the expressive power of future-masked soft attention transformers. They demonstrate that these formalisms are equivalent and establish them as the tightest known lower bound for transformers operating on unbounded input lengths, without requiring additional positional embeddings.

What Problem Does This Paper Address?

Understanding the precise computational capabilities and limitations of transformer models is a crucial area of research. While transformers have achieved remarkable success, their formal expressivity remains an open question. Existing theoretical frameworks often rely on modified transformer architectures or impose restrictions on input length, making it difficult to directly apply their findings to standard, widely-used transformers. This paper aims to bridge this gap by providing a formal logic and a corresponding programming language that can be directly compiled into standard future-masked soft attention transformers, thereby establishing a more accurate lower bound on their expressive power.

Methods

The authors introduce a temporal counting logic called $\textbf{K}_t$[#], which extends temporal logic with counting capabilities. They also propose $\textbf{C-RASP}$, a variant of the RASP programming language, designed to be directly compilable into transformers. The core of their contribution lies in proving the equivalence between $\textbf{K}_t$[#] and $\textbf{C-RASP}$, and then demonstrating that future-masked soft attention transformers can precisely simulate all formulas expressible in $\textbf{K}_t$[#]. This simulation is achieved by mapping subformulas and count terms to specific dimensions within the transformer's residual stream and leveraging self-attention and feed-forward layers to perform the necessary computations. Crucially, this compilation does not require additional positional embeddings.

Datasets

Not discussed in the paper.

Key Insights and Ideas

  • Bridging Logic and Transformers: The paper successfully connects formal logic ($\textbf{K}_t$[#]) and a programming language ($\textbf{C-RASP}$) to the practical architecture of transformers, offering a new lens for understanding their capabilities.
  • Tightest Lower Bound: $\textbf{K}_t$[#] and $\textbf{C-RASP}$ establish the best-known lower bound for future-masked soft attention transformers with unbounded input, which is a significant theoretical advancement.
  • No Positional Embeddings Needed: The ability to compile $\textbf{K}_t$[#] formulas into transformers without relying on explicit positional embeddings is a key insight, suggesting that the core computational power can be captured by the attention mechanism itself.
  • Equivalence is Key: Proving the equivalence between $\textbf{K}_t$[#] and $\textbf{C-RASP}$ provides a robust theoretical foundation for their use in analyzing transformers.
  • RASP's Practicality: The development of $\textbf{C-RASP}$ offers a more practical way to express computations that can be directly translated into transformers, potentially aiding in the design and interpretation of transformer models.

Key Results

  • The temporal counting logic $\textbf{K}_t$[#] and the $\textbf{C-RASP}$ programming language are shown to be equivalent in expressive power.
  • Together, $\textbf{K}_t$[#] and $\textbf{C-RASP}$ establish the tightest known lower bound on the expressivity of future-masked soft attention transformers with unbounded input size.
  • All $\textbf{K}_t$[#] formulas can be compiled into standard future-masked soft attention transformers without requiring additional positional embeddings.
  • The paper demonstrates that $\textbf{K}_t$[#] is strictly more expressive than the previously established lower bound $\textbf{FOC}[+; \textbf{MOD}]$.

Limitations and Future Work

The authors acknowledge that an exact characterization of $\textbf{K}_t$[#] is not currently known, and it can define a variety of languages, including regular, context-free, and non-context-free ones. They also note that while $\textbf{K}_t$[#] can express Dyck-1, it does not seem to express Dyck-2, suggesting that further work is needed to understand its limits. Future work could involve a comprehensive study of the expressive power of $\textbf{K}_t$[#] and $\textbf{C-RASP}$, including the effect of modal depth, and clarifying the disparities between average-hard and soft attention transformers. Additionally, exploring the connection between theoretical results and empirical observations regarding transformer limitations (e.g., integer multiplication) is suggested.

Summary updated

BibTeX
@inproceedings{yang2024counting,
  author = {Andy Yang and David Chiang},
  title = {{Counting Like Transformers: Compiling Temporal Counting Logic Into Softmax Transformers}},
  booktitle = {COLM},
  year = {2024},
  url = {https://openreview.net/forum?id=FmhPg4UJ9K},
}
Figure