🚀 日本穩定視覺語言模型(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 的 隱私政策。