rinna/日语CLIP-ViT-B-16模型

这是由rinna株式会社训练的日语CLIP(对比语言-图像预训练)模型。
其他可用模型请参见japanese-clip项目。
模型使用方法
- 安装依赖包
$ pip install git+https://github.com/rinnakk/japanese-clip.git
- 运行示例代码
import io
import requests
from PIL import Image
import torch
import japanese_clip as ja_clip
device = "cuda" if torch.cuda.is_available() else "cpu"
model, preprocess = ja_clip.load("rinna/japanese-clip-vit-b-16", cache_dir="/tmp/japanese_clip", device=device)
tokenizer = ja_clip.load_tokenizer()
img = Image.open(io.BytesIO(requests.get('https://images.pexels.com/photos/2253275/pexels-photo-2253275.jpeg?auto=compress&cs=tinysrgb&dpr=3&h=750&w=1260').content))
image = preprocess(img).unsqueeze(0).to(device)
encodings = ja_clip.tokenize(
texts=["狗", "猫", "大象"],
max_seq_len=77,
device=device,
tokenizer=tokenizer,
)
with torch.no_grad():
image_features = model.get_image_features(image)
text_features = model.get_text_features(**encodings)
text_probs = (100.0 * image_features @ text_features.T).softmax(dim=-1)
print("标签概率:", text_probs)
模型架构
该模型采用ViT-B/16 Transformer架构作为图像编码器,使用12层BERT作为文本编码器。图像编码器初始化自AugReg vit-base-patch16-224
模型。
训练数据
模型在CC12M数据集上进行训练,并将标题翻译为日语。
发布日期
2022年5月12日
引用方式
@misc{rinna-japanese-clip-vit-b-16,
title = {rinna/日语CLIP-ViT-B-16模型},
author = {Shing, Makoto and Zhao, Tianyu and Sawada, Kei},
url = {https://huggingface.co/rinna/japanese-clip-vit-b-16}
}
@inproceedings{sawada2024release,
title = {日语预训练模型发布},
author = {Sawada, Kei and Zhao, Tianyu and Shing, Makoto and Mitsui, Kentaro and Kaga, Akio and Hono, Yukiya and Wakatsuki, Toshiaki and Mitsuda, Koh},
booktitle = {2024年计算语言学与语言资源联合国际会议论文集(LREC-COLING 2024)},
month = {5},
year = {2024},
pages = {13898--13905},
url = {https://aclanthology.org/2024.lrec-main.1213},
note = {\url{https://arxiv.org/abs/2404.01657}}
}
许可证
Apache 2.0许可证