结合NLLB文本编码器与SigLIP图像编码器,支持201种语言。采用Matryoshka表征学习,可生成多种尺寸嵌入,在XTD10等数据集上创多模态检索新SOTA。【此简介由AI生成】
以下内容由 AI 翻译,如有问题请 点此提交 issue 反馈
tags:
- clip library_name: open_clip pipeline_tag: zero-shot-image-classification license: cc-by-nc-4.0 datasets:
- visheratin/laion-coco-nllb
模型概述
NLLB-SigLIP-MRL 是一个结合了 NLLB 模型的文本编码器和 SigLIP 模型的图像编码器的多模态模型。这一设计使模型能够支持 Flores-200 的 201 种语言。该版本模型采用 Matryoshka 表示学习的变体进行训练,除原始 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 |
使用方法
可变分辨率支持
若需使用支持可变嵌入尺寸的模型,可按以下方式操作:
!pip install -U transformers 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 # set resolution here or set `None` to use the original resolution
)
print(torch.softmax(image_logits, dim=1))
OpenCLIP
该模型已集成至 OpenCLIP 框架,您可像使用其他模型一样调用它:
!pip install -U open_clip_torch
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))
致谢
感谢 ML Collective 提供的 Google Cloud 计算资源支持。