Abstract
Transformers have achieved unprecedented success in deep learning, yet their architectural components—softmax attention, residual connections, and linear layers—often lack a first-principles theoretical justification. This paper proposes that the Transformer architecture emerges naturally from the optimization of input features for multinomial regression. By interpreting attention as a gradient flow that minimizes cross-entropy loss, the authors demonstrate that standard Transformer blocks are discrete implementations of feature refinement algorithms. Empirical validation on Fashion MNIST shows that this framework effectively "denoises" features, significantly improving classification accuracy through iterative refinement.
Introduction
Despite their transformative impact, Transformer architectures are frequently treated as empirical "black boxes." While post-hoc interpretations attempt to explain neuron behavior after training, this research seeks an a priori justification. The authors hypothesize that if one begins with the objective of performing multinomial regression and optimizes input features to minimize classification error, the resulting mathematical structure mirrors the standard Transformer block.
Theoretical Framework: From Regression to Attention
The authors bridge classical statistics and deep learning by treating feature refinement as a continuous optimization problem.
1. Feature Optimization and Gradient Flow
Instead of focusing solely on weight optimization, the study examines how input features ($Z$) should evolve to minimize cross-entropy loss. By calculating the gradient of the Log-Sum-Exp function—a core component of classification loss—the authors find that the gradient is precisely the softmax function.
2. The Emergence of Attention
Because the gradient involves a softmax operation, the direction required to improve feature representations for classification aligns with the mathematical definition of cross-attention (in linear contexts) or self-attention (in quadratic contexts). This suggests that attention is not an arbitrary choice but the mathematically "correct" mechanism for feature updating.
3. Operator Splitting and Architecture Derivation
To translate this continuous gradient flow into a discrete neural architecture, the authors employ operator splitting. This technique decomposes complex movements into two distinct steps:
- Step 1: Results in an attention operation coupled with a residual connection.
- Step 2: Results in a linear mapping (MLP) with a second residual connection.
This derivation yields a system of discrete equations that structurally matches the Transformer block introduced in "Attention is All You Need."
Empirical Validation
The theory was tested using the Fashion MNIST dataset, consisting of 70,000 grayscale clothing images. To evaluate the robustness of the derived architecture, the researchers corrupted images with Gaussian noise to determine if the attention mechanism could recover clean, discriminative features.
Key Results
The derived equations were applied to noisy data using weights from a pre-trained optimal linear classifier, without traditional backpropagation training for the attention mechanism.
- Rapid Accuracy Gains: A single pass through the derived attention block yielded significant improvements.
- Denoising Capabilities: On noisy data, accuracy increased from 81.39% at the initial state to 98.35% after one iteration, reaching 100% on the test sample by the fourth iteration.
- Feature Sharpening: Even with clean data, accuracy rose from 84.24% to 99.99%, indicating that the mechanism refines features toward an "ideal" class representation.
Discussion and Insights
This framework offers several novel interpretations of Transformer components:
- Attention as a Trajectory: Data evolution through layers is a trajectory toward optimal classification representations. Each layer moves the data closer to an archetypal version of its class.
- Residual Connections as Integration: The additive structure ($x + \text{Attention}(x)$) represents a numerical integration step (e.g., Forward Euler) in the gradient flow process.
- Intrinsic Interpretability: Transformers can be viewed as "denoising" engines that refine inputs toward ideal class versions, making the internal logic of the model more transparent.
Limitations and Future Work
While providing a rigorous link between regression and Transformers, the study notes several areas for expansion. The current derivation uses a simplified MLP and does not fully incorporate Layer Normalization, which may act as a directional constraint. Furthermore, while the current model assumes supervised labels, future work could adapt this to self-supervised contexts by replacing true labels with a learned "oracle" or MLP. Extending the derivation to multi-head attention also remains a key objective.
Summary updated