🚀 日本稳定视觉语言模型(Japanese Stable VLM)
日本稳定视觉语言模型(Japanese Stable VLM)是一款视觉语言指令跟随模型,能够为输入的图像以及可选的输入文本(如问题)生成日语描述,可广泛应用于图像描述生成等视觉语言相关场景。
🚀 快速开始
请注意:如需商业使用此模型,请查看 https://stability.ai/license。
若您有关于商业使用的日语咨询,请发送邮件至 partners-jp@stability.ai。
✨ 主要特性
日本稳定视觉语言模型(Japanese Stable VLM)是一个视觉语言指令跟随模型,它可以为输入的图像和可选的输入文本(如问题)生成日语描述。
📦 安装指南
文档中未提及具体安装步骤,暂无法提供。
💻 使用示例
基础用法
import torch
from transformers import AutoTokenizer, AutoModelForVision2Seq, AutoImageProcessor
from PIL import Image
import requests
TASK2INSTRUCTION = {
"caption": "画像を詳細に述べてください。",
"tag": "与えられた単語を使って、画像を詳細に述べてください。",
"vqa": "与えられた画像を下に、質問に答えてください。",
}
def build_prompt(task="caption", input=None, sep="\n\n### "):
assert (
task in TASK2INSTRUCTION
), f"Please choose from {list(TASK2INSTRUCTION.keys())}"
if task in ["tag", "vqa"]:
assert input is not None, "Please fill in `input`!"
if task == "tag" and isinstance(input, list):
input = "、".join(input)
else:
assert input is None, f"`{task}` mode doesn't support to input questions"
sys_msg = "以下は、タスクを説明する指示と、文脈のある入力の組み合わせです。要求を適切に満たす応答を書きなさい。"
p = sys_msg
roles = ["指示", "応答"]
instruction = TASK2INSTRUCTION[task]
msgs = [": \n" + instruction, ": \n"]
if input:
roles.insert(1, "入力")
msgs.insert(1, ": \n" + input)
for role, msg in zip(roles, msgs):
p += sep + role + msg
return p
device = "cuda" if torch.cuda.is_available() else "cpu"
model = AutoModelForVision2Seq.from_pretrained("stabilityai/japanese-stable-vlm", trust_remote_code=True)
processor = AutoImageProcessor.from_pretrained("stabilityai/japanese-stable-vlm")
tokenizer = AutoTokenizer.from_pretrained("stabilityai/japanese-stable-vlm")
model.to(device)
url = "https://images.unsplash.com/photo-1582538885592-e70a5d7ab3d3?ixlib=rb-4.0.3&ixid=M3wxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8fA%3D%3D&auto=format&fit=crop&w=1770&q=80"
image = Image.open(requests.get(url, stream=True).raw).convert("RGB")
prompt = build_prompt(task="caption")
inputs = processor(images=image, return_tensors="pt")
text_encoding = tokenizer(prompt, add_special_tokens=False, return_tensors="pt")
inputs.update(text_encoding)
outputs = model.generate(
**inputs.to(device, dtype=model.dtype),
do_sample=False,
num_beams=5,
max_new_tokens=128,
min_length=1,
repetition_penalty=1.5,
)
generated_text = tokenizer.batch_decode(outputs, skip_special_tokens=True)[0].strip()
print(generated_text)
📚 详细文档
模型详情
训练
该模型是一个基于 LLaVA 1.5 架构的视觉语言指令跟随模型。它使用 stabilityai/japanese-stablelm-instruct-gamma-7b 作为语言模型,openai/clip-vit-large-patch14 作为图像编码器。在训练过程中,第一阶段从零开始训练 MLP 投影,第二阶段进一步训练语言模型和 MLP 投影。
训练数据集
训练数据集包括以下公共数据集:
使用与限制
预期用途
该模型旨在供开源社区用于视觉语言应用。
限制和偏差
尽管应用了数据过滤,但训练数据集仍可能包含冒犯性或不适当的内容。我们建议用户在生产系统中使用这些模型时保持合理的谨慎。请勿将该模型用于任何可能对个人或群体造成伤害或困扰的应用。
引用方式
@misc{JapaneseStableVLM,
url = {[https://huggingface.co/stabilityai/japanese-stable-vlm](https://huggingface.co/stabilityai/japanese-stable-vlm)},
title = {Japanese Stable VLM},
author = {Shing, Makoto and Akiba, Takuya}
}
联系信息
📄 许可证
该模型遵循 STABILITY AI 社区许可证。点击“同意”即表示您同意 许可协议,并认可 Stability AI 的 隐私政策。