Vision Transformers with Natural Language Semantics

Young Kyung Kim, J. Matías Di Martino, Guillermo SapiroarXiv 2024 · DOI

Abstract

Standard Vision Transformers (ViTs) rely on fixed-grid patch tokenization, which lacks semantic meaning and sensitivity to object scales. We present the Semantic Vision Transformer (sViT), a novel architecture that leverages the Segment Anything Model (SAM) to decompose images into semantically meaningful tokens. By treating objects as discrete units—analogous to words in natural language processing—sViT achieves superior interpretability, data efficiency, and robustness across diverse benchmarks and distribution shifts.

Introduction: The Semantic Gap in Computer Vision

Traditional Vision Transformers (ViTs) process images by dividing them into a rigid grid of fixed-size rectangular patches (e.g., $16 \times 16$ pixels). While computationally efficient, this approach is semantically arbitrary. A single patch often contains fragments of multiple unrelated objects, forcing the model to learn "object-ness" from scratch through massive amounts of data. Furthermore, fixed grids are inherently sensitive to scale; an object's representation changes drastically as its size in the frame varies.

In contrast, Natural Language Processing (NLP) utilizes tokens that represent words or sub-words—units that carry inherent meaning. The Semantic Vision Transformer (sViT) bridges this gap by aligning the "vocabulary" of computer vision with human-interpretable objects.

Comparison of NLP tokenization and Computer Vision tokenization strategies. Semantic tokenization aligns CV more closely with the meaningful units found in language.

Methodology: The sViT Pipeline

The core innovation of sViT is its overhaul of the tokenization process, moving from geometric grids to semantic segments. The pipeline consists of several key stages:

  1. Semantic Tokenization: Instead of a grid, sViT employs the Segment Anything Model (SAM) to decompose an image into its constituent objects or segments. This ensures that each token represents a coherent entity.
  2. Normalization and Embedding: To achieve scale invariance, each segment is resized to a fixed resolution (e.g., $32 \times 32$) before being embedded via a convolutional layer. This ensures that a "dog" token maintains a consistent representation regardless of whether the dog appears small in the background or large in the foreground.
  3. Rich Positional Encoding: Since segments are no longer arranged on a grid, sViT incorporates the $(x, y)$ coordinates of each segment's bounding box and its original pixel size as positional inputs, preserving spatial context.
  4. Background and Augmentation: Pixels not identified as primary objects are grouped into a "background token" to prevent information loss. Additionally, sViT introduces segment-level augmentation, where transformations are applied to individual segments. This creates a combinatorial explosion of training variety, significantly improving data efficiency.
Comparison between non-semantic grid tokenization and semantic object-centric tokenization for different image types.

Experimental Results

The researchers evaluated sViT across a wide range of benchmarks, including scene recognition (Places365), object-centric generalization (Stanford Cars, Caltech 101), and robustness to distribution shifts (ImageNet-A/R/Sketch).

Superior Accuracy and Efficiency

sViT consistently outperformed standard ViTs. The performance gap was most significant on smaller datasets like MIT67 and SUN, suggesting that semantic tokens provide a powerful inductive bias that reduces the reliance on "Big Data" pre-training.

Robustness and Generalization

When trained on scene data and tested on object-centric data, sViT showed accuracy improvements of 10% to 29% over standard ViT baselines. It also demonstrated higher resilience to natural distribution shifts, such as sketches and artistic renditions, likely due to its focus on object shapes and semantic content rather than raw pixel grids.

Natural Interpretability

Unlike the blurry heatmaps generated by traditional methods like Grad-CAM, sViT's attention weights are inherently interpretable. They point directly to specific, human-understandable segments, allowing researchers to see exactly which objects influenced a classification decision.

Limitations and Future Outlook

While sViT offers significant advantages, it introduces computational overhead due to the preprocessing step required by SAM. Currently, this roughly doubles inference latency compared to standard ViTs. Furthermore, the model's performance is tied to the quality of the underlying segmentation model. As segmentation models become more efficient, the authors anticipate that semantic tokenization will become a viable and robust standard for computer vision, moving the field closer to a unified understanding of visual and linguistic data.

Summary updated

BibTeX
@misc{kim2024vision,
  author = {Young Kyung Kim and J. Matías Di Martino and Guillermo Sapiro},
  title = {{Vision Transformers with Natural Language Semantics}},
  year = {2024},
  eprint = {2402.17863},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2402.17863},
}
Figure