🚀 NLLB - CLIP - SigLIP模型
NLLB - CLIP - SigLIP模型结合了NLLB模型的文本编码器和SigLIP模型的图像编码器,能将模型能力拓展至Flores - 200中的201种语言。该模型在Crossmodal - 3600数据集上达到了最先进水平,尤其在低资源语言上表现出色。你可以在论文中了解该模型的更多细节。
🚀 快速开始
本模型集成于OpenCLIP中,你可以像使用其他模型一样使用它。点击下方按钮在Colab中打开示例:
📦 安装指南
首先,你需要安装open_clip_torch
库:
!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", "v1", 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))
📚 详细文档
模型概述
NLLB - CLIP - SigLIP模型结合了NLLB的文本编码器和SigLIP的图像编码器,将模型能力拓展到201种语言。它在Crossmodal - 3600数据集上表现出色,尤其在低资源语言上。
版本对比
此版本比标准版本性能更好,你可以在这里和这里查看结果。
注意:该模型还有更好的版本可供使用!
📄 许可证
本模型采用CC - BY - NC - 4.0许可证。
致谢
感谢ML Collective提供Google Cloud计算资源,用于训练与OpenCLIP兼容的NLLB - CLIP版本。