🚀 mBLIP mT0-XL
このモデルは、私たちの研究「mBLIP: Efficient Bootstrapping of Multilingual Vision-LLMs」のチェックポイントです。mBLIPは、画像キャプショニングや視覚的質問応答などのタスクを96言語で実行できるモデルです。
🚀 クイックスタート
このセクションでは、mBLIPモデルの基本的な使い方を説明します。具体的なコード例については、「💻 使用例」を参照してください。
✨ 主な機能
- 多言語対応:96言語で画像キャプショニングや視覚的質問応答(VQA)などのタスクを実行できます。
- 高性能:BLIP-2モデルをベースにしており、高い性能を発揮します。
📦 インストール
このREADMEには具体的なインストール手順が記載されていないため、このセクションを省略します。
💻 使用例
基本的な使用法
CPUでの実行
import requests
from PIL import Image
from transformers import BlipProcessor, Blip2ForConditionalGeneration
processor = BlipProcessor.from_pretrained("Gregor/mblip-mt0-xl")
model = Blip2ForConditionalGeneration.from_pretrained("Gregor/mblip-mt0-xl")
img_url = 'https://storage.googleapis.com/sfr-vision-language-research/BLIP/demo.jpg'
raw_image = Image.open(requests.get(img_url, stream=True).raw).convert('RGB')
question = "Describe the image in German."
inputs = processor(raw_image, question, return_tensors="pt")
out = model.generate(**inputs)
print(processor.decode(out[0], skip_special_tokens=True))
高度な使用法
GPUでの実行(全精度)
import requests
from PIL import Image
from transformers import Blip2Processor, Blip2ForConditionalGeneration
processor = Blip2Processor.from_pretrained("Gregor/mblip-mt0-xl")
model = Blip2ForConditionalGeneration.from_pretrained("Gregor/mblip-mt0-xl", device_map="auto")
img_url = 'https://storage.googleapis.com/sfr-vision-language-research/BLIP/demo.jpg'
raw_image = Image.open(requests.get(img_url, stream=True).raw).convert('RGB')
question = "Describe the image in German."
inputs = processor(raw_image, question, return_tensors="pt").to("cuda")
out = model.generate(**inputs)
print(processor.decode(out[0], skip_special_tokens=True))
GPUでの実行(半精度 bfloat16
)
import torch
import requests
from PIL import Image
from transformers import Blip2Processor, Blip2ForConditionalGeneration
processor = Blip2Processor.from_pretrained("Gregor/mblip-mt0-xl")
model = Blip2ForConditionalGeneration.from_pretrained("Gregor/mblip-mt0-xl", torch_dtype=torch.bfloat16, device_map="auto")
img_url = 'https://storage.googleapis.com/sfr-vision-language-research/BLIP/demo.jpg'
raw_image = Image.open(requests.get(img_url, stream=True).raw).convert('RGB')
question = "Describe the image in German."
inputs = processor(raw_image, question, return_tensors="pt").to("cuda", torch.bfloat16)
out = model.generate(**inputs)
print(processor.decode(out[0], skip_special_tokens=True))
GPUでの実行(8ビット精度 int8
)
⚠️ 重要提示
論文の結果では、LLMの重みのみをint8で使用していますが、このコードではすべての重みをint8で読み込んでいます。これにより、結果が若干劣化することがあります。現在、HuggingFaceでは一部のモデル部分のint8サポートがないためです。
import torch
import requests
from PIL import Image
from transformers import Blip2Processor, Blip2ForConditionalGeneration
processor = Blip2Processor.from_pretrained("Gregor/mblip-mt0-xl")
model = Blip2ForConditionalGeneration.from_pretrained("Gregor/mblip-mt0-xl", load_in_8bit=True, device_map="auto")
img_url = 'https://storage.googleapis.com/sfr-vision-language-research/BLIP/demo.jpg'
raw_image = Image.open(requests.get(img_url, stream=True).raw).convert('RGB')
question = "Describe the image in German."
inputs = processor(raw_image, question, return_tensors="pt").to("cuda", torch.bfloat16)
out = model.generate(**inputs)
print(processor.decode(out[0], skip_special_tokens=True))
📚 ドキュメント
モデルの説明
mBLIPは、BLIP-2モデルに基づいており、3つのサブモデルで構成されています。Vision Transformer (ViT)、Query-Transformer (Q-Former)、および大規模言語モデル (LLM) です。
Q-FormerとViTは、英語のBLIP-2チェックポイント(blip2-flan-t5-xl)で初期化され、その後、多言語タスクミックスチャーを使用して多言語LLM(mt0-xl)に再調整されています。

これにより、モデルは以下のようなタスクに使用できます。
言語
mBLIPは、以下の96言語で学習されています。
af, am, ar, az, be, bg, bn, ca, ceb, cs, cy, da, de, el, en, eo, es, et, eu, fa, fi, fil, fr, ga, gd, gl, gu, ha, hi, ht, hu, hy, id, ig, is, it, iw, ja, jv, ka, kk, km, kn, ko, ku, ky, lb, lo, lt, lv, mg, mi, mk, ml, mn, mr, ms, mt, my, ne, nl, no, ny, pa, pl, ps, pt, ro, ru, sd, si, sk, sl, sm, sn, so, sq, sr, st, su, sv, sw, ta, te, tg, th, tr, uk, ur, uz, vi, xh, yi, yo, zh, zu
直接使用と下流タスクへの適用
画像とプロンプトテキストを与えて、ゼロショット設定で条件付きテキスト生成に生モデルを使用することも、下流アプリケーション用に微調整することもできます。微調整する際には、LLMにLoRAを適用し、データ型としてbf16を使用することを強くおすすめします。標準のfp16を使用すると、NaN損失が発生する可能性があります。
このモデルを学習および微調整するために使用されたコードについては、私たちのリポジトリを参照してください。
バイアス、リスク、制限事項、および倫理的考慮事項
mBLIPは理論的には最大100言語で動作する可能性がありますが、実際には、英語、ドイツ語、スペイン語などのリソースが豊富な言語でプロンプトを与えた場合に最良の結果が得られると予想されます。
mBLIPは、初期化に使用されたモデルからバイアス、リスク、および制限事項を引き継いでいます。mBLIPは実世界のアプリケーションでテストされていません。直接アプリケーションにデプロイすべきではありません。研究者は、モデルをデプロイする特定のコンテキストに関連して、まず慎重に安全性と公平性を評価する必要があります。
🔧 技術詳細
このREADMEには具体的な技術詳細が記載されていないため、このセクションを省略します。
📄 ライセンス
このモデルはMITライセンスの下で提供されています。
📖 引用
もしこのモデルを使用する場合は、以下を引用してください。
@article{geigle2023mblip,
author = {Gregor Geigle and
Abhay Jain and
Radu Timofte and
Goran Glava\v{s}},
title = {mBLIP: Efficient Bootstrapping of Multilingual Vision-LLMs},
journal = {arXiv},
volume = {abs/2307.06930},
year = {2023},
url = {https://arxiv.org/abs/2307.06930},
eprinttype = {arXiv},
eprint = {2307.06930},
}