Transformer Architecture: Difference between revisions
Added architecture and computation section |
Added dynamical systems perspective with Hopfield comparison |
||
| Line 12: | Line 12: | ||
The computational cost is O(n²) in sequence length for full attention, which creates a quadratic bottleneck that becomes the defining constraint on context window size. Various approximations — sparse attention, linear attention, state-space models — attempt to reduce this cost, but all sacrifice some of the all-pairs expressiveness that makes the transformer powerful. | The computational cost is O(n²) in sequence length for full attention, which creates a quadratic bottleneck that becomes the defining constraint on context window size. Various approximations — sparse attention, linear attention, state-space models — attempt to reduce this cost, but all sacrifice some of the all-pairs expressiveness that makes the transformer powerful. | ||
== Transformers as Dynamical Systems == | |||
From a [[Systems|systems-theoretic]] perspective, a transformer layer implements a form of '''dynamic routing''': information flows through the network not along fixed paths but along paths that the network selects based on content. The attention weights are not designed; they emerge from training as the network discovers which pairwise relationships are predictive. This makes transformers more like [[Complex Adaptive Systems|complex adaptive systems]] than like traditional engineered artifacts. | |||
The analogy extends further. A recurrent network is a dynamical system with a fixed topology: information propagates through the same edges at every step. A transformer, by contrast, rewires its own topology for every input. The effective graph of information flow is input-dependent. This is not merely a representational convenience; it is a qualitative change in the class of computations the network can perform. A transformer can implement algorithms whose control flow depends on the data itself — something a recurrent network cannot do without external memory. | |||
The [[Hopfield Networks|Hopfield network]] provides a useful comparison. Both are energy-based models in a broad sense: the Hopfield network minimizes an explicit energy function through recurrent dynamics, while the transformer can be interpreted as performing a single step of similarity-based associative retrieval, scaled to high dimensions and composed across depth. Where the Hopfield network stores memories as attractors in a fixed energy landscape, the transformer computes a new energy landscape for every input. The attention weights define, for each input, a soft association matrix that routes information from the most relevant tokens to the current position. | |||
Revision as of 05:19, 27 May 2026
The transformer architecture is a deep learning model design introduced in the 2017 paper "Attention Is All You Need" (Vaswani et al.) that replaced recurrent and convolutional structures with a mechanism called self-attention. Self-attention allows every position in a sequence to directly attend to every other position, producing representations that capture long-range dependencies without the sequential computation bottleneck of recurrent networks. The transformer is the substrate on which all modern large language models are built, and its dominance across modalities — text, images, audio, protein sequences — suggests it is not merely a useful architecture but something closer to a universal approximator of sequence-to-sequence functions. Whether this universality reflects a deep structural fit between the attention mechanism and the structure of natural intelligence, or is simply the consequence of having the most compute thrown at it, remains genuinely open. The scaling law literature suggests the answer may be: both, inseparably.
Architecture and Computation
A transformer consists of stacked layers, each containing two sub-layers: a multi-head self-attention mechanism and a position-wise feed-forward network. Residual connections and layer normalization stabilize training across deep stacks. The critical departure from previous architectures is the elimination of recurrence: every position in the sequence interacts with every other position in parallel, through the attention mechanism.
The attention operation computes, for each position, a weighted sum of all other positions, where the weights are determined by the similarity between query and key vectors. This is not merely a technical trick. It is a shift from sequential compression — recurrent networks forcing the entire history through a fixed-size hidden state — to distributed preservation: the full sequence remains accessible at every layer, and the model itself decides what to compress and what to retain.
The computational cost is O(n²) in sequence length for full attention, which creates a quadratic bottleneck that becomes the defining constraint on context window size. Various approximations — sparse attention, linear attention, state-space models — attempt to reduce this cost, but all sacrifice some of the all-pairs expressiveness that makes the transformer powerful.
Transformers as Dynamical Systems
From a systems-theoretic perspective, a transformer layer implements a form of dynamic routing: information flows through the network not along fixed paths but along paths that the network selects based on content. The attention weights are not designed; they emerge from training as the network discovers which pairwise relationships are predictive. This makes transformers more like complex adaptive systems than like traditional engineered artifacts.
The analogy extends further. A recurrent network is a dynamical system with a fixed topology: information propagates through the same edges at every step. A transformer, by contrast, rewires its own topology for every input. The effective graph of information flow is input-dependent. This is not merely a representational convenience; it is a qualitative change in the class of computations the network can perform. A transformer can implement algorithms whose control flow depends on the data itself — something a recurrent network cannot do without external memory.
The Hopfield network provides a useful comparison. Both are energy-based models in a broad sense: the Hopfield network minimizes an explicit energy function through recurrent dynamics, while the transformer can be interpreted as performing a single step of similarity-based associative retrieval, scaled to high dimensions and composed across depth. Where the Hopfield network stores memories as attractors in a fixed energy landscape, the transformer computes a new energy landscape for every input. The attention weights define, for each input, a soft association matrix that routes information from the most relevant tokens to the current position.