Introduction
Large Language Models (LLMs) based on the Transformer architecture have achieved state-of-the-art performance across various natural language processing tasks. However, these models remain notoriously "brittle," where minor adversarial perturbations—such as synonym substitutions or word deletions—can lead to drastic changes in model output. This paper establishes a surprising structural equivalence: a one-layer decoder-only Transformer is mathematically identical to a specific two-layer Recurrent Neural Network (RNN). Leveraging this connection, the authors introduce ARC-Tran, a framework for formally verifying the robustness of Transformers against complex, variable-length input perturbations.
Problem Statement: The Challenges of Verification
Certified robustness provides mathematical guarantees that a model's prediction remains invariant within a defined "perturbation space." Applying these techniques to Transformers involves overcoming two significant hurdles:
- Global Dependency: In decoder-only Transformers, each token attends to all preceding tokens. This global lookback mechanism is significantly more complex to verify than the local, step-by-step updates characteristic of RNNs.
- Variable Sequence Lengths: Standard verification tools typically handle fixed-length inputs. Perturbations that alter sequence length (e.g., insertions or deletions) cause misalignments in traditional position encodings, breaking the verification process.
Methodology
The authors address these challenges through a mathematical reformulation of the attention mechanism and a novel embedding strategy.
Transformer-to-RNN Equivalence
The core innovation is a formal proof demonstrating that the attention mechanism in a one-layer decoder-only Transformer can be decomposed into a recursive form. By rewriting the Softmax function as a series of Sigmoid-based updates, the Transformer's state can be tracked using two hidden variables, $f_i$ and $g_i$. This transformation effectively maps the Transformer into a two-layer RNN architecture, as illustrated in Figure 1. This allows the application of "Abstract Interpretation" tools, such as the ARC framework, which were originally designed for recursive models.
Flexible Position Encoding
To accommodate perturbations that change sequence length, the authors introduce a flexible embedding strategy ($e_{i,j}$). Instead of a static $token + position$ vector, they represent the $j$-th original token moved to the $i$-th position in a perturbed sequence. This approach prevents the position mismatch that typically invalidates verification when tokens are added or removed.
Experimental Setup
The ARC-Tran framework was evaluated using the SST2 (Stanford Sentiment Treebank) benchmark for sentiment analysis. The authors defined "programmable" perturbation spaces, including $T_{Dup}$ (word duplication) and $T_{SubSyn}$ (synonym substitution), to test the model's resilience against both content and length-altering attacks.
Results
The performance of ARC-Tran was compared against standard training, data augmentation, and HotFlip (a gradient-based adversarial training method).
As shown in the table above, ARC-Tran achieved a Certified Accuracy (CF Acc.) of 64.80%, significantly outperforming baseline methods which ranged between 9% and 14%. This metric indicates that for nearly 65% of the test set, the model is mathematically guaranteed to be robust against the specified perturbations. Furthermore, ARC-Tran led in Exhaustive Accuracy (EX Acc.) at 72.71%, representing the worst-case performance under any allowed perturbation.
Discussion and Limitations
The realization that a Transformer can be viewed as a legacy RNN suggests that the primary advantage of Transformers may lie in their training efficiency and parallelization rather than a fundamental difference in single-layer representational capacity. While ARC-Tran offers superior verifiability, it introduces certain trade-offs:
- Computational Complexity: The RNN reformulation is inherently sequential, losing the parallelization benefits of Transformers during verification.
- Architectural Depth: The current proof is limited to one-layer models. Extending this framework to deep, multi-layer Transformers remains a significant challenge.
- Component Omissions: Standard features like Layer Normalization were omitted from the current evaluation. Developing abstract versions of these components is a priority for future work.
Despite these limitations, ARC-Tran represents a vital step toward building verifiable and robust language models, particularly for high-stakes applications like automated code generation.
Summary updated