Interpreting and Controlling Vision Foundation Models via Text Explanations

Haozhe Chen, Junfeng Yang, Carl Vondrick, Chengzhi MaoarXiv 2023

Abstract

Large-scale pre-trained vision foundation models, such as CLIP, have become de facto backbones for various vision tasks. However, due to their black-box nature, understanding the underlying rules behind these models' predictions and controlling model behaviors have remained open challenges. We present a framework for interpreting vision transformer's latent tokens with natural language. Given a latent token, our framework retains its semantic information to the final layer using transformer's local operations and retrieves the closest text for explanation. Our approach enables understanding of model visual reasoning procedure without needing additional model training or data collection. Based on the obtained interpretations, our framework allows for model editing that controls model reasoning behaviors and improves model robustness against biases and spurious correlations.

Introduction

Vision foundation models like CLIP have revolutionized computer vision, yet they largely operate as "black boxes." While traditional interpretability tools like saliency maps can identify where a model focuses its attention, they often fail to explain what concepts the model is actually processing. This gap makes it difficult to diagnose errors or correct biases. We introduce a training-free framework designed to translate the internal latent tokens of Vision Transformers (ViTs) into human-readable natural language. By mapping mid-layer visual features directly to a text-aligned embedding space, we can decode the model's internal reasoning and even intervene to correct its behavior.

Methodology: Decoding Latent Tokens

The core of our approach is the observation that latent tokens in a transformer maintain local semantic information if they are prevented from interacting with other tokens.

Disabling Self-Attention

To interpret a specific token at an intermediate layer $i$, we perform a modified forward pass where Multi-Head Self-Attention (MSA) is disabled from that layer onward. The token is allowed to pass only through "in-token" operations, such as the Multi-Layer Perceptron (MLP) and LayerNorm. This surgical intervention bypasses the mixing effect of attention, projecting the token into the final embedding space while preserving its original local meaning.

Latent token interpretation through disabling self-attention. By bypassing the mixing effect of attention, tokens are projected into the final embedding space while retaining local semantic information.

Vocabulary Retrieval and Smoothing

Once a token is projected into the final space, we use CLIP’s pre-trained text encoder to find the closest matching concept from a large, open-world vocabulary. To mitigate the "distribution shift" caused by disabling attention—a state the model never encountered during training—we employ Random Smoothing (RS). By adding small amounts of Gaussian noise during the modified forward pass, we empirically improve the stability and accuracy of the resulting text interpretations.

Hierarchical Concept Assembly

Our framework reveals how ViTs build complex concepts across layers. In lower layers, tokens often represent basic visual attributes like "orange color" or "wheels." As the data progresses through the network, these are assembled into more sophisticated concepts like "orange vehicle" and eventually "a group of cars" at the final layer. This hierarchical view provides a window into the model's visual reasoning process.

Hierarchical assembly of concepts. Lower layers interpret tokens as specific attributes (e.g., wheels), while higher layers assemble them into complex concepts (e.g., a group of cars).

Model Control and Editing

Beyond interpretation, our framework enables precise model editing by modifying representations at inference time. Unlike traditional fine-tuning, which alters model weights, this method allows for "surgical" interventions on the model's internal thoughts.

  • Defending Against Typographical Attacks: Typographical attacks, such as placing a label saying "iPad" on a toaster, exploit the model's ability to read text. By identifying tokens interpreted as "text," we can zero them out, forcing the model to rely solely on visual features and restoring correct predictions.
  • Reasoning Intervention: We can redirect the model's logic by swapping token representations. For instance, in satellite imagery, replacing tokens interpreted as "cars" with those representing "airplanes" can change a "Highway" classification to "Airport" with high success.
  • Mitigating Spurious Biases: In datasets like CelebA, models often learn gendered biases (e.g., associating "gray hair" primarily with men). By identifying and replacing gender-specific tokens, we can significantly improve accuracy for underrepresented groups.

Experimental Results

We validated our framework across several benchmarks, demonstrating its efficacy in both interpretation and control:

  • Typographical Attacks: On ImageNet samples corrupted with misleading text, our method repaired predictions in 97% of cases, increasing accuracy from 54.0% to 89.2%.
  • Reasoning Intervention: In the UC Merced Land Use dataset, we achieved a 95% success rate in redirecting model logic through token replacement.
  • Bias Reduction: On CelebA, we improved the worst-group accuracy for "gray hair" classification from 19.7% to 66.6% by intervening on gendered tokens.

Discussion and Limitations

While powerful, our method faces challenges. Disabling attention creates a distribution shift that can affect embedding quality, though Random Smoothing provides a partial remedy. Furthermore, the quality of explanations is inherently tied to the provided vocabulary; a "near miss" interpretation may occur if the exact concept is missing from the dictionary. Future research will focus on refining these interventions and exploring more interactive auditing systems for foundation models.

Summary updated

BibTeX
@misc{chen2023interpreting,
  author = {Haozhe Chen and Junfeng Yang and Carl Vondrick and Chengzhi Mao},
  title = {{Interpreting and Controlling Vision Foundation Models via Text Explanations}},
  year = {2023},
  eprint = {2310.10591},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2310.10591},
}
Figure