モデル概要
モデル特徴
モデル能力
使用事例
🚀 mBLIP BLOOMZ-7B
このモデルは、我々の研究「mBLIP: Efficient Bootstrapping of Multilingual Vision-LLMs」のチェックポイントです。このモデルは、画像キャプショニングや視覚的質問応答などのタスクを96言語で実行できます。
🚀 クイックスタート
このセクションでは、mBLIP BLOOMZ-7Bモデルの基本的な使い方を説明します。具体的なコード例については、「💻 使用例」を参照してください。
✨ 主な機能
- 多言語対応:96言語での画像キャプショニングや視覚的質問応答(VQA)などのタスクに対応しています。
- 高度なアーキテクチャ:Vision Transformer (ViT)、Query-Transformer (Q-Former)、大規模言語モデル (LLM) の3つのサブモデルから構成されています。
📦 インストール
このREADMEには具体的なインストール手順が記載されていないため、このセクションは省略されます。
💻 使用例
基本的な使用法
以下のコードは、モデルをCPUで実行する基本的な使用例です。
import requests
from PIL import Image
from transformers import Blip2Processor, Blip2ForConditionalGeneration
processor = Blip2Processor.from_pretrained("Gregor/mblip-bloomz-7b")
model = Blip2ForConditionalGeneration.from_pretrained("Gregor/mblip-bloomz-7b")
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での全精度実行
# pip install accelerate
import requests
from PIL import Image
from transformers import Blip2Processor, Blip2ForConditionalGeneration
processor = Blip2Processor.from_pretrained("Gregor/mblip-bloomz-7b")
model = Blip2ForConditionalGeneration.from_pretrained("Gregor/mblip-bloomz-7b", 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)実行
# pip install accelerate
import torch
import requests
from PIL import Image
from transformers import Blip2Processor, Blip2ForConditionalGeneration
processor = Blip2Processor.from_pretrained("Gregor/mblip-bloomz-7b")
model = Blip2ForConditionalGeneration.from_pretrained("Gregor/mblip-bloomz-7b", 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で読み込みます。これにより、結果が若干劣化することがあります。現在、一部のモデル部分のみをint8で使用することは、HuggingFaceではサポートされていません。
# pip install accelerate bitsandbytes
import torch
import requests
from PIL import Image
from transformers import Blip2Processor, Blip2ForConditionalGeneration
processor = Blip2Processor.from_pretrained("Gregor/mblip-bloomz-7b")
model = Blip2ForConditionalGeneration.from_pretrained("Gregor/mblip-bloomz-7b", 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))
GPUでの4ビット精度(int4)実行
⚠️ 重要提示
論文の結果では、LLMの重みのみをint4で使用していますが、このコードではすべての重みをint8で読み込みます。これにより、結果が若干劣化することがあります。現在、一部のモデル部分のみをint4で使用することは、HuggingFaceではサポートされていません。
# pip install accelerate bitsandbytes
import torch
import requests
from PIL import Image
from transformers import Blip2Processor, Blip2ForConditionalGeneration
processor = Blip2Processor.from_pretrained("Gregor/mblip-bloomz-7b")
model = Blip2ForConditionalGeneration.from_pretrained("Gregor/mblip-bloomz-7b",
load_in_4bit=True,
bnb_4bit_quant_type="nf4",
bnb_4bit_use_double_quant=False,
bnb_4bit_compute_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))
📚 ドキュメント
モデルの説明
mBLIPは、BLIP-2モデルであり、3つのサブモデルから構成されています。Vision Transformer (ViT)、Query-Transformer (Q-Former)、大規模言語モデル (LLM) です。
Q-FormerとViTは、英語版のBLIP-2チェックポイント(blip2-flan-t5-xl)で初期化され、その後、多言語タスクミックスチャーを使用して多言語LLM(bloomz-7b1)に再調整されています。
これにより、モデルは以下のようなタスクに使用できます。
- 画像キャプショニング
- 視覚的質問応答(VQA)
96言語での使用が可能です。
言語
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は、実世界のアプリケーションでテストされていません。直接アプリケーションにデプロイすることは避けてください。研究者は、モデルをデプロイする特定のコンテキストに関連して、モデルの安全性と公平性を慎重に評価する必要があります。
🔧 技術詳細
このセクションには、具体的な技術詳細が記載されていません。
📄 ライセンス
このモデルは、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},
}








