Beyond the Doors of Perception: Vision Transformers Represent Relations Between Objects

Michael A. Lepori, Alexa R. Tartaglini, Wai Keen Vong, Thomas Serre, Brenden M. Lake, Ellie Pavlick

TL;DR

Vision Transformers (ViTs), despite their success in image tasks, struggle with relational reasoning. This paper reveals that successful ViTs learn a two-stage processing pipeline: first extracting disentangled object representations (perceptual stage), then comparing these representations to infer relations (relational stage). This insight helps diagnose and fix failures in relational reasoning for AI.

What Problem Does This Paper Address?

Vision Transformers (ViTs) have revolutionized computer vision, achieving state-of-the-art results in tasks like image classification and generation. However, they often falter when it comes to complex tasks that require understanding relationships between objects, such as visual question answering or image-text matching. These tasks go beyond simply recognizing individual objects; they demand an ability to reason about how objects interact or relate to each other. This is a fundamental aspect of human intelligence, and its presence in artificial neural networks has been a long-standing debate. This paper aims to understand how ViTs attempt to perform these relational reasoning tasks and identify the underlying mechanisms that lead to both success and failure.

Methods

The authors employ mechanistic interpretability techniques to dissect the internal workings of ViTs. Instead of just looking at performance metrics, they analyze the attention patterns within the model's layers. They classify attention heads as "local" (attending within an object) or "global" (attending across objects or to the background).

Key techniques include:

  • Attention Pattern Analysis: Visualizing where attention heads focus to understand information flow within and between objects.
  • Distributed Alignment Search (DAS): A method to identify independent linear subspaces within the model's representations that encode specific properties (like shape or color). This allows them to test if these properties are "disentangled" – meaning they can be manipulated independently.
  • Counterfactual Interventions: Modifying specific parts of a model's internal representations (e.g., injecting a different color into an object's representation) to see if it flips the model's decision. This helps determine if a representation is causally linked to the model's output.
  • Linear Probing: Training a simple linear classifier on intermediate representations to see if they encode specific judgments (like "same" or "different").

Datasets

The paper uses two primary synthetic datasets:

  • Discrimination Task: Images contain two objects, each with a unique shape and color. The task is to determine if the objects are identical in both shape and color ("same") or differ in at least one attribute ("different").
  • Relational Match-to-Sample (RMTS) Task: This is a more complex task where models must judge if two pairs of objects exhibit the same relation (e.g., both pairs are "same" or both are "different"). This task is considered more challenging and closer to human relational reasoning.

A photorealistic discrimination dataset generated using Blender is also used to test the robustness of the findings on more complex, out-of-distribution stimuli.

Key Insights and Ideas

  • Two-Stage Processing Pipeline: The most significant finding is that successful ViTs fine-tuned for relational tasks exhibit a clear two-stage processing pipeline:
  • Perceptual Stage: Early layers focus on extracting local features and forming disentangled representations of individual objects.
  • Relational Stage: Later layers compare these object representations to perform abstract relational reasoning.
  • Disentangled Representations are Crucial: The perceptual stage learns to represent object properties (like shape and color) in separate, independent linear subspaces. This disentanglement is key for generalization.
  • Abstract Relational Reasoning is Possible: Contrary to some skepticism, ViTs can learn abstract relational concepts that are somewhat invariant to the specific perceptual details of the objects. This is demonstrated by successful interventions where abstract relations are preserved even when object properties are manipulated.
  • Pretraining Scale Matters: Models with larger pretraining datasets (like CLIP and DINOv2) are more likely to exhibit this clean two-stage processing pipeline and achieve higher performance. Smaller models or those trained from scratch often show mixed local and global processing, hindering relational reasoning.
  • Failures in Either Stage Impede Reasoning: If either the perceptual stage fails to produce good object representations or the relational stage fails to compare them effectively, the model will fail at relational tasks.

Key Results

  • High Accuracy on Synthetic Tasks: CLIP and DINOv2 models achieve over 97% accuracy on the synthetic discrimination and RMTS tasks after fine-tuning.
  • Disentanglement Correlates with Generalization: Models with higher disentanglement scores (measured by counterfactual interventions) show better performance on out-of-distribution and compositional generalization tasks.
  • Photorealistic Robustness: CLIP ViT demonstrates strong performance (93.9% accuracy) on a challenging photorealistic discrimination dataset, even in a zero-shot setting, indicating that the learned two-stage processing generalizes beyond synthetic stimuli. Other models perform poorly on this task.
  • From Scratch Models Struggle: ViTs trained from scratch show significantly lower performance and lack the clear two-stage processing observed in pretrained models. Auxiliary losses (disentanglement and pipeline loss) are necessary to improve their performance, especially for the RMTS task.

Limitations and Future Work

  • Synthetic Stimuli: While the photorealistic dataset shows generalization, the primary analysis relies on synthetic stimuli. Future work could explore more complex and diverse real-world datasets.
  • Specific Models: The detailed mechanistic analysis is focused on CLIP and DINOv2. While other models are analyzed, a deeper dive into their specific failure modes could be beneficial.
  • Generalizing to More Complex Relations: The current work focuses on same-different judgments. Extending these analysis techniques to more complex relational tasks (e.g., spatial relations, causal relations) is a natural next step.
  • Understanding Pretraining: The paper suggests pretraining scale is a key factor for the two-stage processing. Future work could further pinpoint the exact mechanisms by which pretraining enables this.

Summary updated

BibTeX
@inproceedings{lepori2024beyond,
  author = {Michael A. Lepori and Alexa R. Tartaglini and Wai Keen Vong and Thomas Serre and Brenden M. Lake and Ellie Pavlick},
  title = {{Beyond the Doors of Perception: Vision Transformers Represent Relations Between Objects}},
  booktitle = {Advances in Neural Information Processing Systems},
  year = {2024},
  url = {https://openreview.net/forum?id=8puv3c9CPg},
}
Figure