🚀 NLLB-SigLIP-MRL模型
NLLB-SigLIP-MRL模型结合了文本编码器和图像编码器的优势,能够支持201种语言,在多语言图像和文本检索任务中表现出色,为相关领域的研究和应用提供了强大的工具。
✨ 主要特性
- 多语言支持:结合了 NLLB模型 的文本编码器和 SigLIP 模型的图像编码器,将模型能力扩展到Flores-200的201种语言。
- 可变嵌入大小:使用 Matryoshka Representation learning 的变体进行训练,除了原始的768维,还能生成大小为 [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.5539 |
0.5232 |
0.7963 |
0.7792 |
0.8643 |
0.8558 |
XTD10 |
0.6559 |
0.6106 |
0.8846 |
0.8643 |
0.9458 |
0.9379 |
🚀 快速开始
可变分辨率使用方法
如果你想使用支持可变嵌入大小的模型,可以按以下步骤操作:
!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-base", 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使用方法
该模型也集成到了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-base-siglip", "mrl", device="cuda")
tokenizer = get_tokenizer("nllb-clip-base-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计算资源。