Emergence of Text Semantics in CLIP Image Encoders

Sreeram Vennam, Shashwat Singh, Anirudh Govil, Ponnurangam KumaraguruUniReps @ NeurIPS 2024

TL;DR

This paper investigates whether CLIP's image encoder, trained to align images with text captions, also learns to understand the semantics of text within images, independent of its visual appearance. The authors demonstrate that CLIP's image representations indeed capture textual semantics in a way that is largely invariant to font style, suggesting a dedicated semantic subspace.

What Problem Does This Paper Address?

Large-scale self-supervised models like CLIP excel at aligning images with textual descriptions. However, a key question remains: does the image encoder learn to understand the meaning of text rendered within an image, or does it primarily focus on the visual content of the image itself? For instance, an image of a restaurant with a sign saying "Caesar's" should be understood as a place to eat, not necessarily as a reference to Julius Caesar. This paper probes this gap, specifically examining if CLIP's image encoder can disentangle textual semantics from visual artifacts like font, and how well it performs compared to CLIP's dedicated text encoder.

Methods

The researchers employ a "probe" methodology to assess the learned representations. They train linear probes on image representations of rendered text to perform semantic tasks, such as sentiment classification. The core idea is that if the image encoder has learned semantic information, these probes should generalize across different fonts used to render the same text.

Specifically, they:

  • Render text into images: Using the Pillow library, they generate images of text samples in various fonts.
  • Utilize CLIP's image encoder: They feed these rendered text images into a frozen CLIP image encoder to obtain embeddings.
  • Train linear probes: These probes are trained to predict semantic labels (e.g., sentiment) from the image embeddings. Crucially, they train probes on text rendered in one font and test them on text rendered in other fonts.
  • Introduce control tasks: To rule out reliance on mere character associations, they use ROT-k ciphers (which shift letters by a fixed amount) and "jumbled" text (randomized character order) as controls. Performance on these controls should be significantly lower if the model is truly understanding semantics.
  • Measure semantic similarity: They use Central Kernel Alignment (CKA) to compare the similarity of rendered text embeddings from the CLIP image encoder with embeddings from a powerful language model (Llama 3) and CLIP's own text encoder.

Datasets

The experiments utilize two established sentiment classification datasets:

  • SST2 (Stanford Sentiment Treebank v2): A dataset for binary sentiment classification.
  • MR (Movie Review): Another dataset for sentiment analysis.

For the CKA analysis, they use 1000 samples from the captions of the MS-COCO dataset.

Key Insights and Ideas

  • A Dedicated Semantic Subspace: The paper provides strong evidence that CLIP's image encoder possesses a subspace for textual semantics that is largely independent of visual font characteristics. This is a significant finding, as CLIP's primary training objective is image-text alignment, not explicit text understanding within images.
  • Font Invariance: The ability of probes trained on one font to generalize to unseen fonts for sentiment classification is a key indicator of this semantic subspace. This suggests that the model is learning the meaning of the text, not just its visual appearance.
  • Near-Parity with Text Encoder: The CKA scores reveal that the image encoder's representations of rendered text are remarkably close in semantic alignment to CLIP's dedicated text encoder, and also to a powerful LLM like Llama 3. This implies that the image encoder is capturing a rich semantic understanding of text.
  • Controls Validate Semantic Understanding: The significantly lower performance on control tasks (ROT-k and jumbled text) compared to meaningful text strongly supports the conclusion that CLIP is not relying on superficial character patterns but rather on actual semantic content.

Key Results

  • Sentiment Classification: F1 scores for sentiment classification probes trained on rendered text are consistently well above chance, and importantly, show good generalization across different fonts. For example, probes trained on one font often achieve high F1 scores when tested on text rendered in other fonts, including highly distinct styles like handwritten (Cedarville) and monospace (Source Code Pro).
  • CKA Scores: Table 1 shows that the CKA scores between the CLIP image encoder's representations of rendered text and Llama 3's text representations are substantial, often exceeding 0.6 and reaching up to 0.72 for certain fonts. These scores are only slightly lower than the CKA scores between CLIP's text encoder and Llama 3.
  • Control Performance: The F1 scores for the ROT-k and Jumble controls are consistently low, often near random chance (0.5-0.6), and show minimal cross-font generalization, validating the effectiveness of these controls.

Limitations and Future Work

  • Slight Lag Behind Text Encoder: While the image encoder performs impressively, its semantic representations for rendered text slightly lag behind those of CLIP's text encoder and Llama 3, as indicated by the CKA scores.
  • Motivation for Further Study: The authors suggest that this work should motivate further research into the specific training circumstances and task configurations that lead to the emergence of textual semantics in image encoders. Understanding these factors could lead to even more robust and versatile vision-language models.
  • Task-Specific vs. General Semantics: The paper focuses on sentiment classification and general semantic similarity. Future work could explore other linguistic tasks to further probe the depth and breadth of the learned textual semantics.

Summary updated

BibTeX
@inproceedings{vennam2024emergence,
  author = {Sreeram Vennam and Shashwat Singh and Anirudh Govil and Ponnurangam Kumaraguru},
  title = {{Emergence of Text Semantics in CLIP Image Encoders}},
  booktitle = {UniReps @ NeurIPS},
  year = {2024},
  url = {https://openreview.net/forum?id=eEtFRl7ksZ},
}
Figure