Abstract
While transformer-based models have achieved state-of-the-art results in a variety of classification and generation tasks, their black-box nature makes them challenging for interpretability. In this work, we present a novel visual analytical framework to support the analysis of transformer-based generative networks. In contrast to previous work, which has mainly focused on encoder-based models, our framework is one of the first dedicated to supporting the analysis of transformer-based encoder-decoder models and decoder-only models for generative and classification tasks. Hence, we offer an intuitive overview that allows the user to explore different facets of the model through interactive visualization. To demonstrate the feasibility and usefulness of our framework, we present three detailed case studies based on real-world NLP research problems.
Introduction
Transformer-based models have revolutionized Natural Language Processing (NLP), yet their internal mechanisms remain largely opaque. While tools for visualizing encoder-only models like BERT are relatively common, generative models—which utilize decoders to produce text—remain significant "black boxes." These models, such as BART, PEGASUS, and GPT, are prone to critical failures, including "hallucinations" (generating facts not present in the source) and a lack of robustness.
This research addresses the gap in specialized tools for analyzing encoder-decoder and decoder-only architectures. The primary goal is to provide researchers with a way to determine which internal components (attention heads) contribute most to the final output and which specific parts of an input sequence the model prioritizes during prediction.
System Design and Workflow
The proposed framework is built on a robust technical stack designed for high-performance model analysis. The backend utilizes Flask and the Captum library for gradient-based analysis, while the frontend is powered by D3.js for interactive visualization.
As shown in the architecture diagram, the system processes input sequences through the Seq2Seq model, performing ad-hoc processing and dimensionality reduction. Simultaneously, a model analysis module calculates component importance and token attribution, which are then stored on a server to facilitate real-time interactive exploration.
The Interactive Visualization Interface
The interface is designed to provide both global and local perspectives on model behavior through three interconnected views:
- Projection View: This view uses dimensionality reduction techniques like UMAP or t-SNE to plot entire documents as points in a 2D space. By selecting attributes such as ROUGE scores, users can visually identify clusters of documents where the model performs poorly, helping to isolate systematic errors.
- Attention Views: Rather than simple attention maps, this view ranks the importance of individual attention heads using Attention Attribution. This method calculates the model's sensitivity to specific weights via Integrated Gradients, highlighting which heads are truly functional versus redundant.
- Instance View: This view allows for a deep dive into individual examples. It provides one-dimensional heatmaps showing attention distribution, input attribution (identifying which input tokens influenced a specific output token), and interaction scores between pairs of tokens.
Case Studies and Key Insights
The framework's utility was demonstrated through three distinct NLP tasks:
Abstractive Summarization (XSum)
Using the PEGASUS model, researchers investigated entity-level hallucinations. The tool revealed a distinct "signature" for hallucinations: when the model generates a name or fact not in the source text, the input attributions for those tokens are typically "noisier" (higher entropy) and often point toward stop words rather than meaningful content. This suggests that hallucinated entities are generated with lower confidence and less focused attention.
Neural Machine Translation (OPUS-MT)
Analyzing English-to-Chinese translation revealed significant attention sparsity. The tool showed that only a small fraction of attention heads are significant for the task. Many heads focus on purely local information (adjacent tokens), while only a few specialized heads handle complex cross-lingual alignment. This insight suggests that many redundant heads could be pruned without sacrificing performance.
Multi-choice Question Answering (CommonsenseQA)
Using GPT-2 Large, the researchers analyzed in-context learning. The tool helped visualize how "demonstration" examples in a prompt help the model "locate" a specific concept. High interaction scores were found between semantically related tokens in the prompt and the predicted answer, providing a visual explanation for why the model arrived at a specific conclusion.
Limitations and Future Work
While powerful, the framework faces scalability challenges. Computing second-order derivatives (Hessian matrices) for interaction scores is memory-intensive, making it difficult to apply to "massive" large language models (LLMs) in its current form. Additionally, the interface requires a high degree of user expertise in Transformer architecture.
Future work aims to automate these insights. For example, the entropy of input attributions could be used as a real-time "hallucination filter" to automatically flag untrustworthy summaries before they reach the user.
Summary updated