🚀 NLLB-SigLIP-MRLモデル
NLLB-SigLIP-MRLは、画像とテキストのマルチリンガルな検索に特化したモデルです。NLLBのテキストエンコーダーとSigLIPの画像エンコーダーを組み合わせ、201言語に対応しています。また、Matryoshka Representation learningを用いて、多様なサイズの埋め込みを生成できます。
🚀 クイックスタート
モデル概要
NLLB-SigLIP-MRLは、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
ライセンスの下で提供されています。
謝辞
私は、Google Cloudのコンピュートリソースを提供してくれたML Collectiveに感謝します。