Analyzing Transformers in Embedding Space

Guy Dar, Mor Geva, Ankit Gupta, Jonathan Berant

Introduction

Despite the ubiquity of Transformer-based models in modern artificial intelligence, they remain largely "black boxes." Understanding the internal logic of these high-dimensional systems is a primary goal of the field of interpretability. Most existing methods, such as probing or activation patching, are input-dependent, requiring researchers to feed specific sequences into the model to observe its reactions. While useful, these methods are computationally expensive and may fail to capture the full scope of a model's latent knowledge.

This paper introduces a unified, zero-pass framework that interprets Transformer parameters by projecting them into the model's own vocabulary embedding space. By treating this space as a universal "lingua franca," the authors enable input-independent interpretability, the alignment of disparate models, and "zero-shot stitching"—the transfer of capabilities between models without additional training.

Methodology: The Embedding Space as a Lens

The core innovation of this work is Parameter Projection. In a standard Transformer, the residual stream is eventually projected into the vocabulary space to generate a probability distribution over tokens. The authors argue that every intermediate weight vector can be viewed through this same lens.

Parameter Interpretation

To interpret a weight vector $v$, the authors multiply it by the transpose of the embedding matrix ($E^T$). This produces a distribution over the entire vocabulary, identifying the "top-k" tokens most associated with that specific weight. While a pseudo-inverse of $E$ is mathematically intuitive, empirical results showed that the transpose $E^T$ is more effective for identifying semantically relevant tokens.

Figure 1: Parameter interpretation via projection into embedding space. The top-k tokens reveal semantic clusters for keys (K), values (V), and interaction matrices ($W_{VO}$, $W_{QK}$).

For attention layers, the authors analyze "interaction matrices" ($W_{QK}$ for query-key and $W_{VO}$ for value-output). Projecting these into an $e \times e$ space (where $e$ is the vocabulary size) reveals which pairs of words the model prioritizes. As shown in Figure 1, this method uncovers highly specialized components: Layer 21 might contain neurons dedicated to months of the year, while specific attention heads in Layer 18 specialize in mapping names to gendered nouns.

Model Alignment and Stitching

Because the embedding space is tied to the vocabulary rather than a specific model's internal architecture, it serves as a bridge between different models.

  1. Parameter Alignment: By computing dot-products in the embedding space between parameters of two different models (e.g., two BERT models trained with different seeds), researchers can find functional equivalents across models.
  2. Zero-Shot Stitching: This bridge allows for "teleporting" a classifier from a source Model A to a target Model B. By projecting Model A's fine-tuned weights into the embedding space and then "re-projecting" them into Model B's feature space, a functional stitched model is created without any new training data.
Figure 2: The zero-shot stitching process, where a feature space from Model A is mapped to Model B's space using the embedding space as an intermediary.

Key Insights and Results

The Consistency of Transformer "Recipes"

When aligning different BERT models (MultiBERTs), the authors discovered a striking pattern: Layer $i$ of Model A almost always aligns best with Layer $i$ of Model B. This suggests that despite random initialization, Transformers follow a highly consistent functional trajectory during training. The embedding space projection captures the functional essence of these layers, proving that they are learning similar concepts at similar depths.

Qualitative Discoveries

The projection method revealed that Feed-Forward (FF) keys and values often act as semantic partners. For instance, a key that detects tokens related to "legal" concepts is frequently paired with a value that writes "legal" information back into the residual stream. Specific attention heads were also found to perform discrete tasks, such as converting words to British spellings or mapping countries to their respective capital cities.

Performance in Zero-Shot Transfer

The efficacy of the "stitching" method was tested using the IMDB sentiment analysis dataset. By translating a classifier fine-tuned on GPT-2 Medium to a frozen GPT-2 Base model via the embedding space, the authors achieved 70% accuracy. This result is significant because it was achieved "zero-shot," without a single step of gradient descent on the target model.

Limitations and Conclusion

While powerful, the embedding space lens has limitations. It can only interpret features that are expressible through the vocabulary; abstract logical or syntactic features that do not map to specific tokens may remain hidden. Additionally, while the method works seamlessly for models with linear heads like GPT-2, models with non-linear output layers (like BERT) present more theoretical complexity.

In conclusion, projecting parameters into the embedding space provides a robust, input-independent map of a Transformer's internal world. It proves that the vocabulary is not just the model's output format, but the fundamental language it uses to organize its internal knowledge.

Summary updated

BibTeX
@inproceedings{dar2023analyzing,
  author = {Guy Dar and Mor Geva and Ankit Gupta and Jonathan Berant},
  title = {{Analyzing Transformers in Embedding Space}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2023},
  doi = {10.18653/v1/2023.acl-long.893},
}
Figure