ULTra: Unveiling Latent Token Interpretability in Transformer-Based Understanding and Segmentation

Hesam Hosseini, Ghazal Hosseini Mighan, Amirabbas Afzali, Sajjad Amini, Amir Houmansadr

TL;DR

The authors introduce ULTra (Unveiling Latent Token Interpretability), a novel framework that directly explains what intermediate, latent tokens inside a Transformer are "looking at." By backpropagating token embeddings through attention matrices, ULTra generates precise input-space explanation maps that enable state-of-the-art unsupervised semantic segmentation and interpretable text summarization without fine-tuning the underlying model.

What Problem Does This Paper Address?

While Transformers have become the backbone of modern computer vision and natural language processing, they remain notorious "black boxes." Existing interpretability methods (like Grad-CAM or standard attention rollouts) typically focus on explaining the final outputs—such as class logits or the final CLS token.

However, this leaves a massive gap: what is happening inside the intermediate layers? Do individual latent tokens possess semantic awareness on their own? Understanding these hidden representations is crucial for verifying model faithfulness, but directly interpreting high-dimensional intermediate embeddings without modifying the model or relying on paired multi-modal data has remained an open challenge.

Methods

ULTra solves this by tracing how information flows from the input space to any specific latent token at a target layer.

The overall architecture of the ULTra framework, showing the forward pass of input data and the backward path computing gradients to construct explanation maps.

The framework operates via a simple yet elegant pipeline:

  1. Define a Token Function: For a selected latent token, a scalar function $f(z)$ is defined to capture its essence. The paper explores three variants:
  2. ULTraS (Summation): Sums all components of the token vector equally.
  3. ULTraE (Energy): Uses the vector norm (energy) of the token representation.
  4. ULTraW (Weighted): Introduces a lightweight, learnable projection vector optimized via a self-consistency loss under input perturbations (keeping the backbone frozen).
  5. Backpropagate through Attention: The gradient of this function is computed with respect to the attention probability matrices of preceding layers.
  6. Aggregate Layer-wise Maps: These contribution maps are multiplied across layers to generate a token-specific explanation map in the input space.

For Unsupervised Semantic Segmentation (USS), ULTra applies hierarchical clustering to group these individual token explanation maps into pixel-wise semantic regions, completely eliminating the need for downstream task training.

Datasets

The authors evaluated ULTra across several vision and language benchmarks:

  • Vision (Segmentation): COCO-Stuff 27, PASCAL VOC 2012, Potsdam-3 ISPRS (aerial view), and Cityscapes (urban street scenes).
  • Language (Summarization): The Reddit TL;DR dataset, which contains post summaries paired with human feedback.

Key Insights and Ideas

  • The CLS Token Loses Information: A striking finding is that the final CLS token often merges concepts and loses fine-grained spatial/semantic details. Individual latent tokens, however, maintain highly specialized boundaries (e.g., distinguishing a dog from a cat, or even isolating a cat's head), as shown in Figure 2.
  • The "Sweet Spot" of Layer Depth: Deeper is not always better. The authors discovered that segmentation performance peaks in the mid-to-late layers (e.g., around layer 13 for ViT-B/32) and slightly declines in the final layers. This reveals a trade-off where later layers prioritize high-level semantic abstraction over detailed spatial precision.
  • Information-Preserving Aggregation: Projecting embeddings back into the input space before aggregating them across layers drastically reduces information loss compared to methods that aggregate features directly in the latent space.

Key Results

Unsupervised Semantic Segmentation

ULTra achieves state-of-the-art performance across multiple vision datasets without requiring fine-tuning or supervision:

  • COCO-Stuff: Using a pre-trained CLIP ViT-L/14 backbone, ULTraCLIP_W achieved 38.2% mIoU, outperforming the previous unsupervised state-of-the-art method, STEGO (28.2% mIoU). Even the completely training-free variant, ULTraCLIP_S, reached 37.5% mIoU.
  • PASCAL VOC 2012: ULTra variants achieved up to 51.2% mIoU, surpassing competitive baselines like ACSeg (47.1%).
Visual comparison of segmentation heatmaps generated by ULTraS and the refined ULTraW on the COCO-Stuff dataset.

Interpretable Text Summarization

When applied to Llama-2-7B on text summarization, ULTra successfully highlighted semantically critical words (like "relationship", "rejection", or "feelings") that directly drove the generation of the summary. Quantitatively, it consistently outperformed random baselines on the Comprehensiveness metric, proving that the tokens it identifies are genuinely critical to the model's confidence.

Limitations and Future Work

The primary bottleneck of ULTra is its computational complexity. Because it requires computing gradients for every single token individually, generating a full segmentation mask requires one forward pass followed by $n$ backward passes (where $n$ is the number of tokens). This makes it computationally heavy for real-time applications, especially when using small patch sizes (like patch size 8), which exponentially increase token counts.

The authors suggest that future work should focus on mitigating this overhead through attention approximations (such as sparse attention or token pruning), gradient approximations, or parallel processing optimizations.

Summary updated

BibTeX
@article{hosseini2025ultra,
  author = {Hesam Hosseini and Ghazal Hosseini Mighan and Amirabbas Afzali and Sajjad Amini and Amir Houmansadr},
  title = {{ULTra: Unveiling Latent Token Interpretability in Transformer-Based Understanding and Segmentation}},
  journal = {Accepted by TMLR},
  year = {2025},
  url = {https://openreview.net/forum?id=vL3pmJjGDQ},
}
Figure