Instructions to use kbora/CS-CLIP with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- OpenCLIP
How to use kbora/CS-CLIP with OpenCLIP:
import open_clip model, preprocess_train, preprocess_val = open_clip.create_model_and_transforms('hf-hub:kbora/CS-CLIP') tokenizer = open_clip.get_tokenizer('hf-hub:kbora/CS-CLIP') - Notebooks
- Google Colab
- Kaggle
Upload folder using huggingface_hub
Browse files- LICENSE +22 -0
- README.md +97 -0
- open_clip_config.json +32 -0
- open_clip_pytorch_model.bin +3 -0
LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
MIT License
|
| 2 |
+
|
| 3 |
+
Copyright (c) 2021 OpenAI
|
| 4 |
+
Copyright (c) 2026 Bora Kargi, Arnas Uselis, Seong Joon Oh
|
| 5 |
+
|
| 6 |
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
| 7 |
+
of this software and associated documentation files (the "Software"), to deal
|
| 8 |
+
in the Software without restriction, including without limitation the rights
|
| 9 |
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
| 10 |
+
copies of the Software, and to permit persons to whom the Software is
|
| 11 |
+
furnished to do so, subject to the following conditions:
|
| 12 |
+
|
| 13 |
+
The above copyright notice and this permission notice shall be included in all
|
| 14 |
+
copies or substantial portions of the Software.
|
| 15 |
+
|
| 16 |
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
| 17 |
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
| 18 |
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
| 19 |
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
| 20 |
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
| 21 |
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
| 22 |
+
SOFTWARE.
|
README.md
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
library_name: open_clip
|
| 4 |
+
language:
|
| 5 |
+
- en
|
| 6 |
+
base_model: openai/clip-vit-base-patch32
|
| 7 |
+
base_model_relation: finetune
|
| 8 |
+
datasets:
|
| 9 |
+
- kbora/CS-CLIP-Training
|
| 10 |
+
- kbora/Half-Truths
|
| 11 |
+
tags:
|
| 12 |
+
- clip
|
| 13 |
+
- image-text-retrieval
|
| 14 |
+
- compositionality
|
| 15 |
+
- arxiv:2602.23906
|
| 16 |
+
---
|
| 17 |
+
|
| 18 |
+
# CS-CLIP: Component-Supervised CLIP
|
| 19 |
+
|
| 20 |
+
Model for **[Half-Truths Break Similarity-Based Retrieval](https://arxiv.org/abs/2602.23906)**, NeurIPS 2026.
|
| 21 |
+
Bora Kargi, Arnas Uselis, Seong Joon Oh
|
| 22 |
+
|
| 23 |
+
[Project page](https://kargibora.github.io/half-truths/) · [Code](https://github.com/kargibora/CS-CLIP) · [Evaluation data](https://huggingface.co/datasets/kbora/Half-Truths) · [Training annotations](https://huggingface.co/datasets/kbora/CS-CLIP-Training)
|
| 24 |
+
|
| 25 |
+
CS-CLIP fine-tunes CLIP using entity/relation units and their matched foils to improve image–text retrieval when a caption contains a plausible but incorrect detail. Both encoders are fine-tuned; inference uses the standard dual encoder.
|
| 26 |
+
|
| 27 |
+
## Use
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
The ViT-B/32 checkpoint loads directly with OpenCLIP:
|
| 31 |
+
|
| 32 |
+
```bash
|
| 33 |
+
pip install 'open_clip_torch>=2.24,<3'
|
| 34 |
+
```
|
| 35 |
+
|
| 36 |
+
```python
|
| 37 |
+
import open_clip
|
| 38 |
+
import torch
|
| 39 |
+
from PIL import Image
|
| 40 |
+
|
| 41 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 42 |
+
model, preprocess = open_clip.create_model_from_pretrained(
|
| 43 |
+
"hf-hub:kbora/CS-CLIP", device=device
|
| 44 |
+
)
|
| 45 |
+
model.eval()
|
| 46 |
+
tokenizer = open_clip.get_tokenizer("ViT-B-32")
|
| 47 |
+
|
| 48 |
+
image = preprocess(Image.open("image.jpg").convert("RGB")).unsqueeze(0).to(device)
|
| 49 |
+
captions = ["A dog runs on the grass.", "A dog runs on the grass beside a bicycle."]
|
| 50 |
+
with torch.inference_mode():
|
| 51 |
+
image_features = model.encode_image(image, normalize=True)
|
| 52 |
+
text_features = model.encode_text(tokenizer(captions).to(device), normalize=True)
|
| 53 |
+
similarities = image_features @ text_features.T
|
| 54 |
+
print(similarities[0].cpu().tolist())
|
| 55 |
+
```
|
| 56 |
+
|
| 57 |
+
Replace `image.jpg` and the captions with your own inputs. Scores are cosine similarities.
|
| 58 |
+
|
| 59 |
+
## Checkpoint
|
| 60 |
+
|
| 61 |
+
- Backbone: OpenAI CLIP ViT-B/32, fine-tuned on COCO images and the released CS-CLIP annotations.
|
| 62 |
+
- Input: RGB images at 224 × 224; English text with a 77-token context window.
|
| 63 |
+
- Output: 512-dimensional image and text embeddings.
|
| 64 |
+
- Files: `open_clip_pytorch_model.bin` contains the encoder weights; `open_clip_config.json` defines the OpenCLIP architecture and image preprocessing.
|
| 65 |
+
|
| 66 |
+
The checkpoint contains the paper's fine-tuned CLIP encoder weights and loads directly with OpenCLIP.
|
| 67 |
+
|
| 68 |
+
## Evaluation
|
| 69 |
+
|
| 70 |
+
Half-Truth accuracy (%) on the released, human-verified evaluation sets:
|
| 71 |
+
|
| 72 |
+
| Model | COCO–Qwen | COCO–Mistral | CC3M–Qwen |
|
| 73 |
+
|---|---:|---:|---:|
|
| 74 |
+
| CLIP | 34.0 | 28.6 | 36.1 |
|
| 75 |
+
| CS-CLIP | 76.4 | 67.2 | 66.2 |
|
| 76 |
+
|
| 77 |
+
CS-CLIP achieves 57.8% average image-to-text accuracy across the paper's 16 compositional benchmarks. See the [repository](https://github.com/kargibora/CS-CLIP#evaluate-half-truths) for evaluation commands and metric definitions.
|
| 78 |
+
|
| 79 |
+
## Scope and limitations
|
| 80 |
+
|
| 81 |
+
The model is intended for research on image–text retrieval and compositional understanding. A similarity score does not establish that every detail in a caption is correct. Training foils are generated automatically and can be noisy. Fine-tuning also has a zero-shot classification trade-off: the paper reports an average of 59.9%, compared with 63.6% for pretrained CLIP.
|
| 82 |
+
|
| 83 |
+
## License
|
| 84 |
+
|
| 85 |
+
Released under the [MIT license](LICENSE). Generated training annotations are CC BY 4.0; source images and captions retain their original terms.
|
| 86 |
+
|
| 87 |
+
## Citation
|
| 88 |
+
|
| 89 |
+
```bibtex
|
| 90 |
+
@inproceedings{kargi2026halftruths,
|
| 91 |
+
title={Half-Truths Break Similarity-Based Retrieval},
|
| 92 |
+
author={Kargi, Bora and Uselis, Arnas and Oh, Seong Joon},
|
| 93 |
+
booktitle={Advances in Neural Information Processing Systems},
|
| 94 |
+
year={2026},
|
| 95 |
+
url={https://arxiv.org/abs/2602.23906}
|
| 96 |
+
}
|
| 97 |
+
```
|
open_clip_config.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"model_cfg": {
|
| 3 |
+
"embed_dim": 512,
|
| 4 |
+
"vision_cfg": {
|
| 5 |
+
"image_size": 224,
|
| 6 |
+
"layers": 12,
|
| 7 |
+
"width": 768,
|
| 8 |
+
"patch_size": 32
|
| 9 |
+
},
|
| 10 |
+
"text_cfg": {
|
| 11 |
+
"context_length": 77,
|
| 12 |
+
"vocab_size": 49408,
|
| 13 |
+
"width": 512,
|
| 14 |
+
"heads": 8,
|
| 15 |
+
"layers": 12
|
| 16 |
+
}
|
| 17 |
+
},
|
| 18 |
+
"preprocess_cfg": {
|
| 19 |
+
"mean": [
|
| 20 |
+
0.48145466,
|
| 21 |
+
0.4578275,
|
| 22 |
+
0.40821073
|
| 23 |
+
],
|
| 24 |
+
"std": [
|
| 25 |
+
0.26862954,
|
| 26 |
+
0.26130258,
|
| 27 |
+
0.27577711
|
| 28 |
+
],
|
| 29 |
+
"interpolation": "bicubic",
|
| 30 |
+
"resize_mode": "shortest"
|
| 31 |
+
}
|
| 32 |
+
}
|
open_clip_pytorch_model.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f514e7650964fcf954f095e2413dabaadb89b17a36030249042b18cdba3ec75b
|
| 3 |
+
size 605210595
|