TL;DR
Transformers are powerful but opaque. InterpreT is a new interactive visualization tool that helps researchers peer inside these models, tracking token embeddings layer-by-layer and analyzing attention head functions. This allows for deeper understanding of how Transformers work and why they succeed (or fail) on specific tasks.
What Problem Does This Paper Address?
Transformer models, like BERT and GPT, have revolutionized Natural Language Processing (NLP), achieving state-of-the-art results across a wide array of tasks. However, their internal workings remain largely a "black box." We don't fully understand why they are so effective, how they generalize to new tasks, or what specific mechanisms contribute to their success. This lack of interpretability hinders our ability to debug, improve, and trust these models. Existing tools offer some insights, but there's a need for a more comprehensive and interactive system to visualize and analyze the complex inner representations of Transformers.
Methods
InterpreT is designed to be a task-agnostic tool, meaning it can be applied to various Transformer architectures and NLP tasks. Its core functionality relies on two stages:
- Offline Extraction: The system first extracts "collateral" information from a trained Transformer model for a specific task. This includes predictions, relevant hidden states, and attention matrices. Hidden states are then processed using t-SNE (t-distributed Stochastic Neighbor Embedding) to reduce their dimensionality for visualization.
- Interactive Visualization: The extracted and processed data is then presented through an interactive user interface. Key features include:
- t-SNE Embeddings: Visualizing token embeddings layer-by-layer in a 2D space, allowing users to track how representations evolve.
- Head Summary: A plot summarizing attention head statistics (like standard deviation and custom metrics) for each head and layer, helping to identify heads with interesting behaviors.
- Attention Matrix/Map: Detailed visualizations of attention patterns for selected heads and layers, presented as heatmaps or token maps.
- Novel Contributions: InterpreT uniquely allows users to:
- Track and visualize token embeddings through each layer of a Transformer.
- Highlight distances between specific token embeddings using illustrative plots.
- Identify task-related functions of attention heads using new metrics like "grammar correlation" and "coreference intensity."
The tool also supports comparing two models side-by-side and allows users to select multiple examples for aggregated analysis.
Datasets
The paper demonstrates InterpreT's capabilities using two distinct NLP tasks:
- Aspect-Based Sentiment Analysis (ABSA): The authors use a dataset derived from restaurant and laptop reviews (Pontiki et al., 2014, 2015; Wang et al., 2016). They specifically analyze a model called LIBERT, which incorporates syntactic information, against a baseline model.
- Winograd Schema Challenge (WSC): This task focuses on coreference resolution. The authors use a fine-tuned BERT-base model on the WSC task, which is part of the SuperGLUE benchmark (Alex Wang, 2020).
No new datasets are introduced; rather, existing datasets are used to showcase the tool's analytical power.
Key Insights and Ideas
- Bridging the "Domain Gap": Visualizing embeddings for Aspect-Based Sentiment Analysis revealed how a syntactically-aware model (LIBERT) can push out-of-domain aspect terms closer to in-domain terms in the embedding space, effectively mitigating the domain gap. This suggests that explicit syntactic information helps models generalize better across different domains.
- Spatial Convergence for Coreference: For coreference resolution, InterpreT helped discover that fine-tuned BERT models learn to spatially "converge" the embeddings of terms they predict to be coreferent. This means the representations of pronouns and their antecedents are pushed closer together in the later layers of the model, indicating a learned association.
- Task-Specific Attention Head Functions: By introducing custom metrics like "grammar correlation" and "coreference intensity," InterpreT can highlight specific attention heads that are crucial for particular linguistic phenomena. For instance, a specific head in LIBERT was found to be highly correlated with syntactic relations, and certain heads in a WSC-tuned BERT model showed strong attention patterns for coreferent terms.
- Layer-wise Evolution of Representations: The ability to track token embeddings through each layer is crucial. It allows users to see how abstract representations are built up, how syntactic or semantic information is encoded, and how the model's focus shifts across layers.
Key Results
The paper presents qualitative results demonstrating InterpreT's utility:
- ABSA: Visualizations showed LIBERT successfully bridging the domain gap, with its embeddings for out-of-domain aspects overlapping more with in-domain aspects compared to the baseline. This correlated with higher F1 scores on out-of-domain examples.
- WSC: InterpreT revealed that BERT models fine-tuned for coreference resolution push embeddings of predicted coreferent terms closer together in later layers. Specific examples highlighted how changing a single word ("back" to "up") altered the model's internal representation and coreference predictions, with "he" becoming closer to "Fred" in the latter case. Attention visualizations identified specific heads (e.g., head 7 in layer 10) that were particularly important for coreference resolution.
Limitations and Future Work
- Limitations: The paper notes that attention visualizations can become unwieldy with very long sequences, though this doesn't affect the tool's core functionality. The collateral generation is an offline process, meaning changes to the model or task require re-extraction.
- Future Work: The authors plan to expand InterpreT's capabilities by:
- Supporting additional use cases and NLP tasks.
- Adding more analysis and interactivity features.
- Enabling dynamic addition and modification of examples while the application is running, allowing for more fluid exploration.
Summary updated