语言:
- 日语
- 英语
基础模型:
- sbintuitions/sarashina2-7b
许可证: MIT
标签:
- 多模态
- 视觉语言
- llama
- qwen2_vl
管道标签: 图像转文本
库名称: transformers
Sarashina2-Vision-8B
Sarashina2-Vision-8B 是由 SB Intuitions 训练的日本大型视觉语言模型。
该模型基于 Sarashina2-7B 和 Qwen2-VL-7B 的图像编码器。
与其他日本视觉语言模型相比,该模型在4个基准测试中取得了最高分数(截至2025年3月7日)。
使用方法
1. 安装依赖项
pip install -U transformers==4.47.0 torch torchvision pillow protobuf sentencepiece accelerate
2. 推理
以下脚本加载模型并允许进行推理。
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])
"""この写真に写っているもので、最も有名と考えられる建築物は東京タワーです。東京タワーは、東京のランドマークであり、この写真では、高層ビル群の向こう側に写っています。"""
示例
提示 |
输出 |
この写真に写っているもので、最も有名と考えられる建築物は何でどこに写っていますか? |
この写真に写っているもので、最も有名と考えられる建築物は東京タワーです。東京タワーは、東京のランドマークであり、この写真では、高層ビル群の向こう側に写っています。 |
真ん中に映っている赤と白の物は何ですか? |
真ん中に映っている赤と白のものはクレーンです。 |
训练
Sarashina2-Vision 通过以下三个阶段的学习过程创建:
- 我们通过字幕数据集调整投影仪中的参数。
- 我们通过字幕数据集调整视觉编码器和投影仪中的参数。
- 我们通过视觉指令数据集调整投影仪和LLM中的参数。
评估结果
- 仅评估单图像样本(1,286个样本)。如果答案提取失败,我们将其视为不正确(分数0),而不是随机选择以消除随机性。
- 使用GPT-4o(gpt-4o-2024-08-06)作为LLM-as-a-Judge。
伦理考虑和限制
Sarashina2-Vision可能会生成一些无意义的序列、不准确的实例或有偏见/令人反感的输出。在使用Sarashina2-Vision之前,我们希望开发者基于人类偏好和安全考虑调整模型。
许可证
MIT许可证