🚀 さらしな2-Vision-8B
さらしな2-Vision-8B は、SB Intuitions によって訓練された日本語の大規模ビジョン言語モデルです。
このモデルは、さらしな2-7B と Qwen2-VL-7B の画像エンコーダーをベースに構築されています。
2025年3月7日現在、他の日本語のビジョン言語モデルと比較して、4つのベンチマークで最高レベルのスコアを達成しています。
🚀 クイックスタート
📦 インストール
依存関係をインストールするには、以下のコマンドを実行します。
pip install -U transformers==4.47.0 torch torchvision pillow protobuf sentencepiece accelerate
💻 使用例
基本的な使用法
以下のスクリプトは、モデルをロードして推論を行うことができます。
import requests
from PIL import Image
from transformers import AutoModelForCausalLM, AutoProcessor
model_path = "sbintuitions/sarashina2-vision-8b"
processor = AutoProcessor.from_pretrained(model_path, trust_remote_code=True)
model = AutoModelForCausalLM.from_pretrained(
model_path,
device_map="cuda",
torch_dtype="auto",
trust_remote_code=True,
)
message = [{"role": "user", "content": "この写真に写っているもので、最も有名と考えられる建築物は何でどこに写っていますか?"}]
text_prompt = processor.apply_chat_template(message, add_generation_prompt=True)
"""text_prompt: <s><|prefix|><|file|><|suffix|>A chat between a curious human and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the human's questions.
### Human: この写真に写っているもので、最も有名と考えられる建築物は何でどこに写っていますか?
### Assistant:"""
sample_image_url = "https://huggingface.co/sbintuitions/sarashina2-vision-8b/resolve/main/sample.jpg"
image = Image.open(requests.get(sample_image_url, stream=True).raw).convert("RGB")
inputs = processor(
text=[text_prompt],
images=[image],
padding=True,
return_tensors="pt",
)
inputs = inputs.to("cuda")
stopping_criteria = processor.get_stopping_criteria(["\n###"])
output_ids = model.generate(
**inputs,
max_new_tokens=128,
temperature=0.0,
do_sample=False,
stopping_criteria=stopping_criteria,
)
generated_ids = [
output_ids[len(input_ids) :] for input_ids, output_ids in zip(inputs.input_ids, output_ids)
]
output_text = processor.batch_decode(
generated_ids, skip_special_tokens=True, clean_up_tokenization_spaces=True
)
print(output_text[0])
"""この写真に写っているもので、最も有名と考えられる建築物は東京タワーです。東京タワーは、東京のランドマークであり、この写真では、高層ビル群の向こう側に写っています。"""
具体的な使用例
プロンプト |
出力 |
この写真に写っているもので、最も有名と考えられる建築物は何でどこに写っていますか? |
この写真に写っているもので、最も有名と考えられる建築物は東京タワーです。東京タワーは、東京のランドマークであり、この写真では、高層ビル群の向こう側に写っています。 |
真ん中に映っている赤と白の物は何ですか? |
真ん中に映っている赤と白のものはクレーンです。 |
🔧 技術詳細
学習プロセス
さらしな2-Vision は、以下の3段階の学習プロセスを通じて作成されています。
- キャプションデータセットを使用して、プロジェクターのパラメーターを調整します。
- キャプションデータセットを使用して、ビジョンエンコーダーとプロジェクターのパラメーターを調整します。
- ビジュアル命令データセットを使用して、プロジェクターと大規模言語モデル(LLM)のパラメーターを調整します。
評価結果
- 単一画像サンプル(1,286サンプル)のみを評価しました。回答の抽出に失敗した場合は、確率的要素を排除するためにランダムな選択ではなく、不正解(スコア0)として扱いました。
- LLM-as-a-Judgeには、GPT-4o (gpt-4o-2024-08-06) を使用しました。
📄 ライセンス
このモデルは、MITライセンス の下で提供されています。
⚠️ 重要提示
さらしな2-Visionは、意味のないシーケンス、不正確な事例、または偏った/不快な出力を生成する可能性があります。さらしな2-Visionを使用する前に、開発者には人間の嗜好と安全性を考慮してモデルを調整することをお勧めします。