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.
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