[Paper Review] Analyzing Feed-Forward Blocks in Transformers through the Lens of Attention Maps
This paper proposes a novel attention map-based method to visualize and analyze the input contextualization effects of feed-forward (FF) blocks in Transformers, revealing that FF networks amplify specific linguistic compositions like subword-to-word and multi-word expressions. Key findings show FF blocks significantly reshape attention patterns, while residual and normalization layers suppress their effects, suggesting redundancy in the Transformer's internal processing.
Transformers are ubiquitous in wide tasks. Interpreting their internals is a pivotal goal. Nevertheless, their particular components, feed-forward (FF) blocks, have typically been less analyzed despite their substantial parameter amounts. We analyze the input contextualization effects of FF blocks by rendering them in the attention maps as a human-friendly visualization scheme. Our experiments with both masked- and causal-language models reveal that FF networks modify the input contextualization to emphasize specific types of linguistic compositions. In addition, FF and its surrounding components tend to cancel out each other's effects, suggesting potential redundancy in the processing of the Transformer layer.
Motivation & Objective
- To address the lack of interpretability for feed-forward (FF) blocks in Transformers, despite their large parameter count and critical role in model performance.
- To investigate how FF blocks influence input contextualization, particularly in relation to linguistic composition and token relationships.
- To develop a visualization method that captures the impact of FF blocks on attention maps, extending beyond standard attention mechanisms.
- To examine the interplay between FF blocks and surrounding components (residual and normalization layers) in shaping intermediate representations.
- To provide insights into architectural redundancy and potential model pruning opportunities by analyzing FF block effects.
Proposed method
- Extends norm-based attribution methods (Kobayashi et al., 2021) to capture input contextualization effects of FF blocks by incorporating input magnitude via vector norms.
- Applies integrated gradients partially to handle non-linearities in FF networks, enabling gradient-like attribution without backpropagation.
- Computes attention maps that reflect the influence of FF blocks by combining their output norms with residual and normalization layer dynamics.
- Uses forward pass only, avoiding backpropagation while maintaining interpretability and computational efficiency.
- Visualizes the impact of FF blocks on token-to-token attention patterns, focusing on changes in contextualization across layers.
- Employs layer-wise analysis on both masked (e.g., BERT) and causal (e.g., GPT-2) language models to compare effects across architectures.
Experimental results
Research questions
- RQ1How do feed-forward blocks modify input contextualization in Transformers, as reflected in attention maps?
- RQ2What types of linguistic compositions are amplified or suppressed by FF blocks across different model architectures?
- RQ3To what extent do residual and normalization layers counteract the effects of FF blocks in the same layer?
- RQ4Are there consistent patterns in FF block behavior across different model sizes and training seeds?
- RQ5Can the influence of FF blocks on attention maps be reliably visualized and attributed using norm-based and integrated gradient techniques?
Key findings
- FF blocks significantly alter input contextualization, as evidenced by pronounced changes in attention map patterns when FF outputs are modified or masked.
- Specific linguistic compositions—particularly subword-to-word and multi-word expression constructions—are consistently amplified by FF blocks across both BERT and GPT-2 models.
- Residual and normalization layers tend to suppress the effects of FF blocks, indicating a form of internal redundancy in the Transformer layer’s processing.
- The magnitude of FF output vectors correlates strongly with attention map changes, especially in deeper layers, suggesting that FF output norms are key drivers of contextualization shifts.
- Layer normalization (LN) weights show strong correlation with input/output vector norms in FF blocks, indicating LN plays a central role in modulating FF influence.
- Experiments on multiple model variants (e.g., BERT-base with different seeds and sizes) confirm consistent FF effects, supporting the robustness of observed patterns across architectures and training variations.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.