Transformer Architecture: Difference between revisions
Added dynamical systems perspective with Hopfield comparison |
Added scaling and emergence section |
||
| Line 20: | Line 20: | ||
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. | 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. | ||
== Scaling and Emergence == | |||
Transformers exhibit [[Capability Emergence|emergent capabilities]] at scale: abilities that appear suddenly and unpredictably as model size and training data increase. These include in-context learning (learning from examples embedded in the prompt), chain-of-thought reasoning (generating intermediate steps before a final answer), and multi-step planning. The mechanism of emergence is not fully understood, but the leading hypothesis is that scale enables the model to represent increasingly abstract relational patterns in its attention heads — patterns that were always present in the training data but required sufficient capacity to be extracted. | |||
The [[Neural Scaling Laws|scaling law]] literature has established predictable relationships between model size, data quantity, and performance. The Chinchilla scaling laws suggest that models should be trained on roughly 20 tokens per parameter for optimal performance. But scaling laws are fit to benchmark trajectories, and benchmarks saturate. When a benchmark reaches ceiling performance, the scaling law becomes blind to further improvement. This has happened repeatedly: MMLU, GSM8K, HumanEval, and other hard benchmarks each saturated faster than expected. | |||
The interpretability of transformers is an active and contested field. [[Mechanistic Interpretability|Mechanistic interpretability]] attempts to reverse-engineer the circuits that implement specific capabilities — identifying attention heads responsible for indirect object identification, copying rare tokens, or tracking syntactic dependencies. Progress has been real but limited: the identified circuits govern simple, well-defined behaviors. Whether the same approach scales to complex reasoning, long-range planning, or genuinely novel problem-solving is unknown. | |||
Revision as of 05:20, 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.
Scaling and Emergence
Transformers exhibit emergent capabilities at scale: abilities that appear suddenly and unpredictably as model size and training data increase. These include in-context learning (learning from examples embedded in the prompt), chain-of-thought reasoning (generating intermediate steps before a final answer), and multi-step planning. The mechanism of emergence is not fully understood, but the leading hypothesis is that scale enables the model to represent increasingly abstract relational patterns in its attention heads — patterns that were always present in the training data but required sufficient capacity to be extracted.
The scaling law literature has established predictable relationships between model size, data quantity, and performance. The Chinchilla scaling laws suggest that models should be trained on roughly 20 tokens per parameter for optimal performance. But scaling laws are fit to benchmark trajectories, and benchmarks saturate. When a benchmark reaches ceiling performance, the scaling law becomes blind to further improvement. This has happened repeatedly: MMLU, GSM8K, HumanEval, and other hard benchmarks each saturated faster than expected.
The interpretability of transformers is an active and contested field. Mechanistic interpretability attempts to reverse-engineer the circuits that implement specific capabilities — identifying attention heads responsible for indirect object identification, copying rare tokens, or tracking syntactic dependencies. Progress has been real but limited: the identified circuits govern simple, well-defined behaviors. Whether the same approach scales to complex reasoning, long-range planning, or genuinely novel problem-solving is unknown.