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

Benjamin Hoover, Hendrik Strobelt, Sebastian GehrmannarXiv 2019

Introduction

Transformer-based models like BERT have fundamentally changed natural language processing, yet their internal decision-making processes remain largely opaque. While researchers have established that these models "learn" linguistic structures, understanding why a specific model attends to a particular token in a given sentence is difficult. exBERT addresses this interpretability gap by providing an interactive visual analysis tool that grounds abstract internal representations in a human-readable, annotated corpus.

Methodology

The exBERT architecture integrates three synchronized views to facilitate deep probing of model behavior:

  1. Attention View: Displays self-attention weights in a matrix format, allowing users to select specific layers and heads.
  2. Corpus View: This component performs a Nearest Neighbor Search using Cosine Similarity. It compares the model's internal vector (embedding) for a selected token or head combination against a large reference corpus (e.g., The Wizard of Oz).
  3. Summary View: Aggregates linguistic metadata—such as Part-of-Speech (POS) and Dependency (DEP) labels—from the top 50 corpus matches, presenting them as histograms.

A significant technical contribution of exBERT is the ability to search by "head embeddings." By concatenating normalized representations from a subset of heads, users can investigate what specific combinations of heads are searching for, moving beyond the analysis of isolated components.

The exBERT interface overview, featuring the Attention, Corpus, and Summary views.

Key Insights

Linguistic Evolution Across Layers

Analysis using exBERT reveals how linguistic information matures within the model's architecture. In the initial layers, embeddings are largely dominated by positional information and surface-level features, often matching generic punctuation or determinants in the corpus. As information propagates through the network, the representations become increasingly specialized. By Layer 6, the model demonstrates a clear "understanding" of the token's role, with the nearest neighbors in the corpus consistently sharing the same part-of-speech, such as identifying a masked token as a verb based on its syntactic context.

The Power of Head Combinations

One of the tool's most compelling findings is that complex linguistic patterns are often distributed across multiple heads. While a single head might not perfectly isolate a specific dependency, strategic combinations can. For example, in Layer 5, while individual heads might show noisy results, the combination of heads 6 and 9 clearly captures the "Direct Object" (DOBJ) dependency, whereas head 5-3 focuses on ROOT dependencies and head 5-6 on auxiliary (AUX) dependencies.

Extracted figure from page 5 of exBERT: A Visual Analysis Tool to Explore Learned Representations in Transformers Models

Results: Case Study on Masking

The authors conducted a case study by masking the word "escape" in the sentence: "The girl ran to a local pub to escape the din of her city." - Layer 1: Matches are generic and non-linguistic, focusing on punctuation. - Layer 5: Verb-related information begins to emerge in the embedding space as the model integrates context. - Final Layer: The model accurately identifies the token as a verb and suggests contextually relevant alternatives such as "pass," "see," or "breathe."

Conclusion

exBERT provides a powerful lens into the "black box" of Transformers. While currently limited by the scope of the reference corpus, it demonstrates that internal representations are not just abstract numbers but correspond to concrete linguistic features. Future work will focus on expanding the tool to support diverse domains and more complex query types to further decompose Transformer representations.

Summary updated

BibTeX
@misc{hoover2019exbert,
  author = {Benjamin Hoover and Hendrik Strobelt and Sebastian Gehrmann},
  title = {{exBERT: A Visual Analysis Tool to Explore Learned Representations in Transformers Models}},
  year = {2019},
  eprint = {1910.05276},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/1910.05276},
}
Figure