モデル概要
モデル特徴
モデル能力
使用事例
🚀 recruit-jp/japanese-clip-vit-b-32-roberta-base
このモデルは、日本語のテキストと画像を同じ埋め込み空間にマッピングすることができる日本語CLIPモデルです。ゼロショット画像分類、テキスト - 画像検索、画像特徴抽出などのタスクに利用できます。
🚀 クイックスタート
インストール
必要なパッケージをインストールします。
pip install pillow requests transformers torch torchvision sentencepiece
コードの実行
以下のコードを実行します。
import io
import requests
import torch
import torchvision
from PIL import Image
from transformers import AutoTokenizer, AutoModel
model_name = "recruit-jp/japanese-clip-vit-b-32-roberta-base"
device = torch.device("cuda:0" if torch.cuda.is_available() else "cpu")
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModel.from_pretrained(model_name, trust_remote_code=True).to(device)
def _convert_to_rgb(image):
return image.convert('RGB')
preprocess = torchvision.transforms.Compose([
torchvision.transforms.Resize(size=224, interpolation=torchvision.transforms.InterpolationMode.BICUBIC, max_size=None),
torchvision.transforms.CenterCrop(size=(224, 224)),
_convert_to_rgb,
torchvision.transforms.ToTensor(),
torchvision.transforms.Normalize(mean=[0.48145466, 0.4578275, 0.40821073], std=[0.26862954, 0.26130258, 0.27577711])
])
def tokenize(tokenizer, texts):
texts = ["[CLS]" + text for text in texts]
encodings = [
# NOTE: the maximum token length that can be fed into this model is 77
tokenizer(text, max_length=77, padding="max_length", truncation=True, add_special_tokens=False)["input_ids"]
for text in texts
]
return torch.LongTensor(encodings)
# Run!
image = 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(image).unsqueeze(0).to(device)
text = tokenize(tokenizer, texts=["犬", "猫", "象"]).to(device)
with torch.inference_mode():
image_features = model.get_image_features(image)
image_features /= image_features.norm(dim=-1, keepdim=True)
text_features = model.get_text_features(input_ids=text)
text_features /= text_features.norm(dim=-1, keepdim=True)
probs = image_features @ text_features.T
print("Label probs:", probs.cpu().numpy()[0])
✨ 主な機能
- 日本語のテキストと画像を同じ埋め込み空間にマッピングすることができます。
- ゼロショット画像分類、テキスト - 画像検索、画像特徴抽出などのタスクに利用できます。
📚 ドキュメント
概要
- 開発元: Recruit Co., Ltd.
- モデルタイプ: 対照的言語 - 画像事前学習モデル
- 言語: 日本語
- ライセンス: CC - BY - 4.0
詳細は、弊社のテクノロジーブログ記事に記載されています。
モデルの詳細
このモデルは日本語のCLIPです。このモデルを使用すると、日本語のテキストと画像を同じ埋め込み空間にマッピングすることができます。 このモデルは、画像エンコーダに[laion/CLIP - ViT - B - 32 - laion2B - s34B - b79K](https://huggingface.co/laion/CLIP - ViT - B - 32 - laion2B - s34B - b79K)、テキストエンコーダに[rinna/japanese - roberta - base](https://huggingface.co/rinna/japanese - roberta - base)を使用しています。このモデルは、[LAION2B - multiデータセット](https://huggingface.co/datasets/laion/laion2B - multi)の日本語サブセットで学習されており、日本語に特化しています。
モデルの性能
以下のデータセットでモデルの性能評価を行いました。ImageNet V2とFood101は英語圏のデータセットであるため、評価前にクラスラベルを日本語に翻訳しました。
- ImageNet V2 テストセット (Top - 1精度)
- [Food101](https://data.vision.ee.ethz.ch/cvl/datasets_extra/food - 101/) (Top - 1精度)
- ETL文字データベースのひらがなデータセット (Top - 1精度)
- ETL文字データベースのカタカナデータセット (Top - 1精度)
- STAIR Captions 画像からテキストへの検索 (Precision@1,5,10の平均)
- STAIR Captions テキストから画像への検索 (Precision@1,5,10の平均)
- [jafood101](https://huggingface.co/datasets/recruit - jp/japanese - image - classification - evaluation - dataset/blob/main/jafood101.csv) (Top - 1精度)
- [jaflower30](https://huggingface.co/datasets/recruit - jp/japanese - image - classification - evaluation - dataset/blob/main/jaflower30.csv) (Top - 1精度)
- [jafacility20](https://huggingface.co/datasets/recruit - jp/japanese - image - classification - evaluation - dataset/blob/main/jafacility20.csv) (Top - 1精度)
- [jalandmark10](https://huggingface.co/datasets/recruit - jp/japanese - image - classification - evaluation - dataset/blob/main/jalandmark10.csv) (Top - 1精度)
また、同じデータセットで[laion/CLIP - ViT - H - 14 - frozen - xlm - roberta - large - laion5B - s13B - b90k](https://huggingface.co/laion/CLIP - ViT - H - 14 - frozen - xlm - roberta - large - laion5B - s13B - b90k)、[laion/CLIP - ViT - B - 32 - xlm - roberta - base - laion5B - s13B - b90k](https://huggingface.co/laion/CLIP - ViT - B - 32 - xlm - roberta - base - laion5B - s13B - b90k)、[rinna/japanese - clip - vit - b - 16](https://huggingface.co/rinna/japanese - clip - vit - b - 16)、[stabilityai/japanese - stable - clip - vit - l - 16](https://huggingface.co/stabilityai/japanese - stable - clip - vit - l - 16)の評価も行いました。stabilityai/japanese - stable - clip - vit - l - 16はSTAIR Captionsデータセットで学習されているため、STAIR Captionsでの評価はスキップしました。
モデル | ImageNet V2 | Food101 | ETLC - ひらがな | ETLC - カタカナ | STAIR Captions 画像からテキスト | STAIR Captions テキストから画像 | jafood101 | jaflower30 | jafacility20 | jalandmark10 |
---|---|---|---|---|---|---|---|---|---|---|
laion/CLIP - ViT - H - 14 - frozen - xlm - roberta - large - laion5B - s13B - b90k | 0.471 | 0.742 | 0.055 | 0.029 | 0.462 | 0.223 | 0.709 | 0.869 | 0.820 | 0.899 |
laion/CLIP - ViT - B - 32 - xlm - roberta - base - laion5B - s13B - b90k | 0.326 | 0.508 | 0.162 | 0.061 | 0.372 | 0.169 | 0.609 | 0.709 | 0.749 | 0.846 |
rinna/japanese - clip - vit - b - 16 | 0.435 | 0.491 | 0.014 | 0.024 | 0.089 | 0.034 | 0.308 | 0.592 | 0.406 | 0.656 |
stabilityai/japanese - stable - clip - vit - l - 16 | 0.481 | 0.460 | 0.013 | 0.023 | - | - | 0.413 | 0.689 | 0.677 | 0.752 |
recruit - jp/japanese - clip - vit - b - 32 - roberta - base | 0.175 | 0.301 | 0.030 | 0.038 | 0.191 | 0.102 | 0.524 | 0.592 | 0.676 | 0.797 |
学習データセット
このモデルは、[LAION2B - multi](https://huggingface.co/datasets/laion/laion2B - multi)データセットの日本語サブセットの128Mの画像 - テキストペアで学習されています。
📄 ライセンス
このモデルはCC - BY - 4.0ライセンスの下で提供されています。
⚠️ 免責事項
㈱リクルートは、本モデル利用による成果に関し、正確性、有用性、確実性、違法性の確認及び何らの保証および補償を行わないものとし、また、モデル利用によって利用者に生じた損害および第三者との間における紛争について㈱リクルートは一切責任を負いません。









