exBERT: A Visual Analysis Tool to Explore Learned Representations in Transformer Models

Benjamin Hoover, Hendrik Strobelt, Sebastian Gehrmann

Introduction

Transformer-based architectures, such as BERT and GPT-2, have fundamentally shifted the landscape of Natural Language Processing (NLP). Despite their state-of-the-art performance, these models remain largely opaque "black boxes." While researchers have developed various "probing" techniques to determine if these models internalize linguistic structures like syntax or grammar, such methods are often static and require custom code for each experiment.

To bridge the gap between complex internal representations and human interpretability, we present exBERT, an interactive visual analysis tool. exBERT allows researchers to explore the inner workings of Transformer models by combining traditional attention visualizations with a novel "Corpus View" that performs real-time similarity searches across large, annotated datasets.

The exBERT Framework

The exBERT interface is designed to provide a multi-faceted view of a model's internal state. It consists of two primary interactive components that work in tandem to reveal how information is processed across layers and heads.

1. Attention View

The Attention View provides a classic visualization of multi-head attention, allowing users to select specific layers and heads to observe the flow of information between tokens. A key interactive feature is the ability to "mask" tokens in real-time. By masking a token, users can observe how the model's internal attention shifts and how its predictions for the masked word change, providing immediate feedback on the model's contextual dependencies.

2. Corpus View

The "Corpus View" is the core innovation of exBERT. When a user selects a specific token, the tool utilizes FAISS (Facebook AI Similarity Search) to identify the top 50 most similar embeddings within a reference corpus, such as Wikipedia or The Wizard of Oz.

The exBERT interface: (a) input area, (b) model controls, (c) Attention View, (d) Corpus View search results, (e) layer/head indicators, (f-g) metadata histograms.

Because the reference corpus is pre-annotated with linguistic metadata—including Part-of-Speech (POS) tags, Dependency (DEP) relations, and Named Entities (ENT)—exBERT can aggregate these labels into histograms. This allows users to see not just where a model is looking, but what linguistic features it has identified. For instance, if a specific attention head consistently retrieves tokens labeled as "Direct Objects," it suggests that the head has specialized in identifying that specific syntactic relationship.

Interactive Linguistic Probing

exBERT facilitates the replication of complex "bertology" findings through an intuitive point-and-click interface. The tool supports both bidirectional models (BERT) and autoregressive models (GPT-2), adjusting its interface to show either masked language modeling predictions or next-token probabilities.

One significant insight gained through the tool is the temporal difference between attention and embedding specialization. Observations suggest that specific attention heads often "learn" linguistic patterns several layers before that information is fully consolidated into the token's final embedding. For example, researchers used exBERT to quickly identify Head 7-5 in BERT-base as a specialist for "Objects of the Preposition" (POBJ) by analyzing the metadata histograms in the Corpus View.

Case Study: Visualizing Model Bias

Beyond linguistic structure, exBERT is a powerful tool for identifying and visualizing social biases encoded within large-scale models. By utilizing the next-token prediction feature in GPT-2, users can observe how the model's internal state shifts based on gendered context.

Visualizing gender bias in GPT-2: Changing the subject from 'nurse' to 'doctor' shifts the model's prediction probability from 'her' to 'him'.

As shown in the figure above, changing a noun like "nurse" to "doctor" significantly alters the model's probability distribution for subsequent pronouns (e.g., "him" vs. "her"). exBERT allows researchers to pinpoint exactly which layers and heads contribute to these shifts, providing a granular view of how bias manifests during the generation process.

Discussion and Limitations

While exBERT provides unprecedented local interpretability, it faces several constraints. It is primarily a "local" analysis tool, focusing on individual tokens and sentences rather than providing a global summary of model behavior across an entire dataset. Furthermore, the quality of insights is strictly dependent on the reference corpus; if the corpus lacks specific annotations (e.g., sentiment), the tool cannot surface those patterns. Finally, scaling real-time similarity searches to multi-billion-token corpora remains a significant engineering challenge for future development.

Despite these limitations, exBERT moves model interpretability from the realm of specialized scripts to an accessible, interactive platform, enabling a broader range of researchers to explore the "thought processes" of modern Transformer models.

Summary updated

BibTeX
@inproceedings{hoover2020exbert,
  author = {Benjamin Hoover and Hendrik Strobelt and Sebastian Gehrmann},
  title = {{exBERT: A Visual Analysis Tool to Explore Learned Representations in Transformer Models}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2020},
  doi = {10.18653/v1/2020.acl-demos.22},
}
Figure