Skip to main content
QUICK REVIEW

[Paper Review] Transformer visualization via dictionary learning: contextualized embedding as a linear superposition of transformer factors

Zeyu Yun, Yubei Chen|arXiv (Cornell University)|Mar 29, 2021
Topic ModelingComputer Science19 references5 citations
TL;DR

This paper proposes a dictionary learning approach to visualize contextualized embeddings in Transformers as sparse linear superpositions of learned 'transformer factors,' revealing hierarchical semantic structures such as polysemy disambiguation, sentence-level pattern formation, and long-range dependencies. The method enables interpretable, data-driven visualization that uncovers both expected linguistic patterns and novel, unexpected representations beyond prior knowledge.

ABSTRACT

Transformer networks have revolutionized NLP representation learning since they were introduced. Though a great effort has been made to explain the representation in transformers, it is widely recognized that our understanding is not sufficient. One important reason is that there lack enough visualization tools for detailed analysis. In this paper, we propose to use dictionary learning to open up these "black boxes" as linear superpositions of transformer factors. Through visualization, we demonstrate the hierarchical semantic structures captured by the transformer factors, e.g., word-level polysemy disambiguation, sentence-level pattern formation, and long-range dependency. While some of these patterns confirm the conventional prior linguistic knowledge, the rest are relatively unexpected, which may provide new insights. We hope this visualization tool can bring further knowledge and a better understanding of how transformer networks work. The code is available at https://github.com/zeyuyun1/TransformerVis

Motivation & Objective

  • To address the lack of effective visualization tools for interpreting contextualized representations in Transformer models.
  • To overcome limitations of probing tasks, which are often too simplistic and cannot reveal representations beyond prior linguistic knowledge.
  • To enable fine-grained localization of linguistic structures within the model's hierarchical layers.
  • To develop a method that reveals both known linguistic phenomena and novel, unexpected patterns in attention-based representations.
  • To provide a data-driven, interpretable framework for analyzing how Transformers encode contextually sensitive semantics.

Proposed method

  • The method models contextualized word embeddings as sparse linear combinations of learned 'transformer factors' via non-negative sparse coding.
  • A unified dictionary is trained across multiple Transformer layers to capture hierarchical representations from all depths.
  • The optimization uses FISTA to solve the inverse problem: $ x = \Phi\alpha + \epsilon $, with $ \alpha \succeq 0 $, ensuring non-negative, sparse coefficients.
  • The dictionary $ \Phi \in \mathbb{R}^{d \times m} $ is overcomplete ($ m > d $) to allow rich, disentangled factorization of semantic content.
  • The approach leverages skip connections to model each layer’s output as a superposition of modifications from all lower layers.
  • The method is applied to collected contextualized embeddings from BERT-style models across all layers, enabling visualization of learned factors.

Experimental results

Research questions

  • RQ1Can contextualized word embeddings in Transformers be meaningfully decomposed into a sparse linear superposition of interpretable semantic factors?
  • RQ2What kind of hierarchical semantic structures—such as polysemy, syntactic patterns, or long-range dependencies—emerge from the learned factors?
  • RQ3Do the learned factors reveal known linguistic phenomena, or do they uncover novel, unexpected representations?
  • RQ4How does the factorization vary across different layers, and what does this imply about the flow of semantic information in Transformers?
  • RQ5Can this method localize where specific linguistic features are encoded within the model architecture?

Key findings

  • The method successfully visualizes hierarchical semantic structures, including word-level polysemy disambiguation, where the same word is represented by distinct factors in different contexts.
  • Sentence-level pattern formation is observed, with factors capturing syntactic and discourse-level dependencies across spans of text.
  • Long-range dependencies are encoded through distributed, sparse combinations of factors, suggesting a compositional mechanism for long-range reasoning.
  • Some learned factors align with conventional linguistic categories (e.g., parts of speech, named entities), validating the method’s interpretability.
  • Other factors represent unexpected, non-traditional semantic patterns, indicating new structural insights into how Transformers process language.
  • The factorization is stable across layers and reveals that representations evolve through additive modifications, consistent with the skip-connection hypothesis.

Read this paper

Open the full text in the Nubint reader and ask about any passage as you read.

Read this paper on Nubint

This review was generated by AI from the original paper. Please check the paper before citing it.