🚀 NLLB-SigLIP-MRL模型
NLLB-SigLIP-MRL模型結合了NLLB模型的文本編碼器和SigLIP模型的圖像編碼器。這使得該模型的能力能夠擴展到Flores-200中的201種語言。此版本的模型使用了Matryoshka Representation learning的一種變體進行訓練,除了原始的1152維嵌入外,還能生成大小為[32, 64, 128, 256, 512]的嵌入。根據以下基準測試,256維和512維的嵌入保留了超過90%的完整嵌入質量。

完整嵌入模型在XTD10和Crossmodal-3600數據集上的多語言圖像和文本檢索任務中創造了新的最優成績。
數據集 |
圖像檢索R@1,平均 |
文本檢索R@1,平均 |
圖像檢索R@5,平均 |
文本檢索R@5,平均 |
圖像檢索R@10,平均 |
文本檢索R@10,平均 |
Crossmodal-3600 |
0.6079 |
0.5741 |
0.8333 |
0.8174 |
0.8922 |
0.8816 |
XTD10 |
0.6997 |
0.6433 |
0.8988 |
0.8848 |
0.9503 |
0.9449 |
🚀 快速開始
✨ 主要特性
NLLB-SigLIP-MRL模型的主要特性如下:
- 結合NLLB模型的文本編碼器和SigLIP模型的圖像編碼器,支持Flores-200中的201種語言。
- 使用Matryoshka Representation learning的變體進行訓練,可生成多種大小的嵌入。
- 在XTD10和Crossmodal-3600數據集上的多語言圖像和文本檢索任務中取得了新的最優成績。
📦 安裝指南
根據不同的使用方式,安裝命令如下:
可變分辨率使用方式
!pip install -U transformers open_clip_torch
OpenCLIP使用方式
!pip install -U open_clip_torch
💻 使用示例
基礎用法(可變分辨率)
from transformers import AutoModel
from PIL import Image
import requests
import torch
model = AutoModel.from_pretrained("visheratin/nllb-siglip-mrl-large", device="cpu", trust_remote_code=True)
image_path = "https://huggingface.co/spaces/jjourney1125/swin2sr/resolve/main/samples/butterfly.jpg"
image = Image.open(requests.get(image_path, stream=True).raw)
class_options = ["бабочка", "butterfly", "kat"]
class_langs = ["rus_Cyrl", "eng_Latn", "afr_Latn"]
image_logits, text_logits = model.get_logits(
images=[image],
texts=class_options,
langs=class_langs,
resolution=512
)
print(torch.softmax(image_logits, dim=1))
高級用法(OpenCLIP)
from open_clip import create_model_from_pretrained, get_tokenizer
from PIL import Image
import requests
import torch
model, transform = create_model_from_pretrained("nllb-clip-large-siglip", "mrl", device="cuda")
tokenizer = get_tokenizer("nllb-clip-large-siglip")
class_options = ["бабочка", "butterfly", "kat"]
class_langs = ["rus_Cyrl", "eng_Latn", "afr_Latn"]
text_inputs = []
for i in range(len(class_options)):
tokenizer.set_language(class_langs[i])
text_inputs.append(tokenizer(class_options[i]))
text_inputs = torch.stack(text_inputs).squeeze(1).to("cuda")
image_path = "https://huggingface.co/spaces/jjourney1125/swin2sr/resolve/main/samples/butterfly.jpg"
image = Image.open(requests.get(image_path, stream=True).raw)
image_inputs = transform(image).unsqueeze(0).to("cuda")
with torch.inference_mode():
logits_per_image, logits_per_text = model.get_logits(image_inputs, text_inputs)
print(logits_per_image.softmax(dim=-1))
📄 許可證
本模型使用的許可證為cc-by-nc-4.0
。
致謝
感謝ML Collective提供Google Cloud計算資源。