Transformer Architecture: Self-Attention's Context Flattening

The core of the Transformer architecture, the self-attention mechanism, processes all input tokens equally to determine their relationships. This design, while enabling powerful language understanding and generation, inherently flattens the context window, making it challenging for the LLM to differentiate between system instructions and user-provided data, including malicious prompts.

The top 3

  1. RNNs' Sequential Advantage: Hierarchical Context: Before Transformers, Recurrent Neural Networks (RNNs) like LSTMs processed data sequentially, maintaining a hidden state that allowed them to build a more hierarchical understanding of context over time, contrasting with self-attention's simultaneous global view.
  2. Self-Attention's Global View: The QKV Flattening: The Transformer's self-attention mechanism uses Query (Q), Key (K), and Value (V) vectors to enable every token to directly interact with all other tokens, computing a single, globally-aware contextual representation that effectively "flatten" the input structure.
  3. Positional Encoding: Re-injecting Sequence Order: Transformers use positional encodings—mathematical vectors added to input embeddings—to provide tokens with crucial relative and absolute position information, counteracting self-attention's context flattening.

Sources

Open the full topic