Long-CLIP: Unlocking the Long-Text Capability of CLIP

Beichen Zhang, Pan Zhang, Xiaoyi Dong, Yuhang Zang, Jiaqi Wang

Introduction

Contrastive Language-Image Pre-training (CLIP) has become a foundational component in modern AI, bridging the gap between vision and language for tasks ranging from zero-shot classification to text-to-image generation. However, a significant limitation persists: CLIP is constrained to a maximum of 77 tokens. Empirical analysis reveals an even tighter "effective" length, where the model primarily attends to fewer than 20 tokens. This constraint forces CLIP to operate as a "bag of concepts," often failing to capture complex spatial relationships or detailed attributes in long descriptions.

Methodology: Long-CLIP

To address these limitations without the prohibitive cost of full-scale retraining, the authors introduce Long-CLIP, a "plug-and-play" upgrade that extends text capacity to 248 tokens. The approach relies on two key innovations:

Knowledge-Preserved Stretching (KPS)

Standard interpolation of positional embeddings often degrades performance on short-text tasks. Recognizing that CLIP is most robust on the initial 20 tokens, KPS maintains these embeddings exactly. Only the subsequent 57 positions are "stretched" to cover the expanded 248-token range, preserving the model's existing short-text proficiency.

Primary Component Matching (PCM)

To balance fine-grained detail with high-level summarization, Long-CLIP employs a dual-alignment strategy. It aligns detailed image features with long captions while simultaneously using Principal Component Analysis (PCA) to extract "primary components" from image features. These coarse-grained summaries are aligned with short text versions, ensuring the model distinguishes between core concepts and intricate details.

Evaluation and Benchmarks

The model was fine-tuned for just 20 minutes on 8 GPUs using 1 million image-text pairs from the ShareGPT4V dataset. Evaluation spanned standard benchmarks like ImageNet-1K, COCO, and Flickr30k. Additionally, the authors introduced Urban-1k, a specialized dataset derived from Visual Genome with GPT-4V-generated long captions to rigorously test spatial and attribute reasoning.

Key Results

Long-CLIP achieves a substantial performance boost, improving long-caption retrieval on Urban-200 by 20% and traditional short-caption retrieval by 6%. Crucially, it maintains the original model's zero-shot classification accuracy on ImageNet-1K, avoiding the "catastrophic forgetting" typical of naive fine-tuning.

Figure 3: Long-CLIP demonstrates superior long-text retrieval performance and broader benchmark improvements compared to standard CLIP.

Beyond retrieval, Long-CLIP serves as a drop-in replacement for text encoders in generative models like Stable Diffusion (v1.5 and SDXL). This allows for significantly more complex prompts without the risk of truncation, unlocking new creative possibilities in high-fidelity image synthesis.

Conclusion

Long-CLIP demonstrates that the long-text bottleneck in vision-language models can be overcome efficiently. By preserving the original latent space and strategically adapting positional embeddings, Long-CLIP provides a scalable, high-performance solution that remains compatible with the existing CLIP ecosystem.

Summary updated

BibTeX
@inproceedings{zhang2024long,
  author = {Beichen Zhang and Pan Zhang and Xiaoyi Dong and Yuhang Zang and Jiaqi Wang},
  title = {{Long-CLIP: Unlocking the Long-Text Capability of CLIP}},
  booktitle = {European Conference on Computer Vision},
  year = {2024},
  doi = {10.1007/978-3-031-72983-6\_18},
}
Figure