英文

AltCLIP-m9

它支持英语(En),中文(Zh),西班牙语(Es),法语(Fr),俄语(Ru),日语(Ja),韩语(Ko),阿拉伯语(Ar)和意大利语(It)语言。

名称 Name 任务 Task 语言 Language(s) 模型 Model Github
AltCLIP-m9 Text-Image Multilingual CLIP 1232321

简介 Brief Introduction

我们提出了一个简单高效的方法去训练更加优秀的九语CLIP模型。命名为AltCLIP-m9。AltCLIP训练数据来自 WuDao数据集 和 LIAON

AltCLIP-m9模型可以为本项目中的AltDiffusion-m9模型提供支持,关于AltDiffusion-m9模型的具体信息可查看 此教程 。

模型代码已经在 FlagAI 上开源,权重位于我们搭建的 modelhub 上。我们还提供了微调,推理,验证的脚本,欢迎试用。

我们提出了一个简单高效的方法去训练更好的多语CLIP模型。命名为AltCLIP-m9。AltCLIP-m9使用来自 WuDao dataset 和 Liaon 的训练数据。

AltCLIP-m9模型可以为本项目中的AltDiffusion-m9模型提供支持。关于AltDiffusion模型的具体信息可以在 this tutorial 中找到。

模型代码已经在 FlagAI 上开源,权重位于 modelhub 上。我们还提供了微调、推理和验证的脚本,欢迎尝试。

引用

关于AltCLIP,我们已经推出了相关报告,有更多细节可以查阅,如对您的工作有帮助,欢迎引用。

如果您发现这项工作有所帮助,请考虑引用

@article{https://doi.org/10.48550/arxiv.2211.06679,
  doi = {10.48550/ARXIV.2211.06679},
  url = {https://arxiv.org/abs/2211.06679},
  author = {Chen, Zhongzhi and Liu, Guang and Zhang, Bo-Wen and Ye, Fulong and Yang, Qinghong and Wu, Ledell},
  keywords = {Computation and Language (cs.CL), FOS: Computer and information sciences},
  title = {AltCLIP: Altering the Language Encoder in CLIP for Extended Language Capabilities},
  publisher = {arXiv},
  year = {2022},
  copyright = {arXiv.org perpetual, non-exclusive license}
}

训练 Training

训练共有两个阶段。在平行知识蒸馏阶段,我们只是使用平行语料文本来进行蒸馏(平行语料相对于图文对更容易获取且数量更大)。在多语对比学习阶段,我们使用少量的中-英 图像-文本对(每种语言6百万)来训练我们的文本编码器以更好地适应图像编码器。

训练共有两个阶段。在平行知识蒸馏阶段,我们只使用平行语料文本进行蒸馏(平行语料比图像-文本对更易于获取且数量更多)。在多语对比学习阶段,我们使用少量的图像-文本对(每种语言约600万个)来训练我们的文本编码器以更好地适应图像编码器。

下游效果 Performance

可视化效果 Visualization effects

基于AltCLIP,我们还开发了AltDiffusion模型,可视化效果如下。

基于AltCLIP,我们还开发了AltDiffusion模型,如下图所示。

模型推理 Inference

请从 FlagAI AltCLIP 下载代码

from PIL import Image
import requests

# transformers version >= 4.21.0
from modeling_altclip import AltCLIP
from processing_altclip import AltCLIPProcessor

# now our repo's in private, so we need `use_auth_token=True`
model = AltCLIP.from_pretrained("BAAI/AltCLIP-m9")
processor = AltCLIPProcessor.from_pretrained("BAAI/AltCLIP-m9")

url = "http://images.cocodataset.org/val2017/000000039769.jpg"
image = Image.open(requests.get(url, stream=True).raw)

inputs = processor(text=["a photo of a cat", "a photo of a dog"], images=image, return_tensors="pt", padding=True)

outputs = model(**inputs)
logits_per_image = outputs.logits_per_image # this is the image-text similarity score
probs = logits_per_image.softmax(dim=1) # we can take the softmax to get the label probabilities