模型:
M-CLIP/XLM-Roberta-Large-Vit-B-16Plus
语言:
多语言-CLIP扩展了OpenAI的英文文本编码器到其他多种语言。该模型仅包含多语言文本编码器。相应的图像模型 Vit-B-16Plus 可以通过在 mlfoundations open_clip repository on Github 上找到的说明来检索。下面是一个使用示例。
要同时使用多语言文本编码器和相应的图像编码器,我们需要安装 multilingual-clip 和 open_clip_torch 的软件包。
pip install multilingual-clip pip install open_clip_torch
可以通过以下方法从文本编码器中提取嵌入向量:
from multilingual_clip import pt_multilingual_clip import transformers texts = [ 'Three blind horses listening to Mozart.', 'Älgen är skogens konung!', 'Wie leben Eisbären in der Antarktis?', 'Вы знали, что все белые медведи левши?' ] model_name = 'M-CLIP/XLM-Roberta-Large-Vit-B-16Plus' # Load Model & Tokenizer model = pt_multilingual_clip.MultilingualCLIP.from_pretrained(model_name) tokenizer = transformers.AutoTokenizer.from_pretrained(model_name) embeddings = model.forward(texts, tokenizer) print("Text features shape:", embeddings.shape)
可以通过以下方法从相应的图像编码器中提取嵌入向量:
import torch import open_clip import requests from PIL import Image device = "cuda" if torch.cuda.is_available() else "cpu" model, _, preprocess = open_clip.create_model_and_transforms('ViT-B-16-plus-240', pretrained="laion400m_e32") model.to(device) url = "http://images.cocodataset.org/val2017/000000039769.jpg" image = Image.open(requests.get(url, stream=True).raw) image = preprocess(image).unsqueeze(0).to(device) with torch.no_grad(): image_features = model.encode_image(image) print("Image features shape:", image_features.shape)
尚未对M-CLIP模型进行全面评估,但在人工翻译的MS-COCO数据集上进行Txt2Img检索测试时,我们看到以下 R@10 结果:
Name | En | De | Es | Fr | Zh | It | Pl | Ko | Ru | Tr | Jp |
---|---|---|---|---|---|---|---|---|---|---|---|
1236321 | 90.3 | - | - | - | - | - | - | - | - | - | - |
1237321 | 91.8 | - | - | - | - | - | - | - | - | - | - |
1238321 | 94.3 | - | - | - | - | - | - | - | - | - | - |
1239321 | 91.6 | 89.6 | 89.5 | 89.9 | 88.9 | 90.1 | 89.8 | 80.8 | 85.5 | 89.8 | 73.9 |
12310321 | 91.8 | 88.7 | 89.1 | 89.4 | 89.3 | 89.8 | 91.4 | 82.1 | 86.1 | 88.8 | 81.0 |
12311321 | 92.4 | 90.6 | 91.0 | 90.0 | 89.7 | 91.1 | 91.3 | 85.2 | 85.8 | 90.3 | 81.9 |
12312321 | 95.0 | 93.0 | 93.6 | 93.1 | 94.0 | 93.1 | 94.4 | 89.0 | 90.0 | 93.0 | 84.2 |
关于模型训练和数据的更多详细信息可以在 model card 中找到。