You need to agree to share your Hugging Face information to access this model

This repository is publicly accessible, but you have to accept the conditions to access its files and content.

By clicking "Agree", you agree to the License Agreement and acknowledge Stability AI's Privacy Policy.

Log in or Sign Up to review the conditions and access this model content.

Japanese Stable VLM

Please note: for commercial usage of this model, please see https://stability.ai/license

ๅ•†็”จๅˆฉ็”จใซ้–ขใ™ใ‚‹ๆ—ฅๆœฌ่ชžใงใฎๅ•ใ„ๅˆใ‚ใ›ใฏใ€€partners-jp@stability.ai ใพใงใŠ้ก˜ใ„่‡ดใ—ใพใ™ใ€‚

Model Details

Japanese Stable VLM is a vision-language instruction-following model that enables to generate Japanese descriptions for input images and optionally input texts such as questions.

Usage

import torch
from transformers import AutoTokenizer, AutoModelForVision2Seq, AutoImageProcessor
from PIL import Image
import requests

# helper function to format input prompts
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

# load model
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)

# prepare inputs
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")
# prompt = build_prompt(task="tag", input=["ๆฒณๆดฅๆกœ", "้’็ฉบ"])
# prompt = build_prompt(task="vqa", input="ๅญฃ็ฏ€ใฏใ„ใคใงใ™ใ‹๏ผŸ")

inputs = processor(images=image, return_tensors="pt")
text_encoding = tokenizer(prompt, add_special_tokens=False, return_tensors="pt")
inputs.update(text_encoding)

# generate
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)
# ๆกœ่ถŠใ—ใฎๆฑไบฌใ‚นใ‚ซใ‚คใƒ„ใƒชใƒผ

Model Details

Training

This model is a vision-language instruction-following model with the LLaVA 1.5 architecture. It uses stabilityai/japanese-stablelm-instruct-gamma-7b as a language model and openai/clip-vit-large-patch14 as an image encoder. During training, the MLP projection was trained from scratch at the first stage and the language model and the MLP projection were further trained at the second stage.

Training Dataset

The training dataset includes the following public datasets:

Use and Limitations

Intended Use

This model is intended to be used by the open-source community in vision-language applications.

Limitations and bias

The training dataset may have contained offensive or inappropriate content even though we applied data filters. We recommend users exercise reasonable caution when using these models in production systems. Do not use the model for any applications that may cause harm or distress to individuals or groups.

How to cite

@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}
}

Contact

  • For questions and comments about the model, please join Stable Community Japan.
  • For future announcements / information about Stability AI models, research, and events, please follow https://twitter.com/StabilityAI_JP.
  • For business and partnership inquiries, please contact partners-jp@stability.ai. ใƒ“ใ‚ธใƒใ‚นใ‚„ๅ”ๆฅญใซ้–ขใ™ใ‚‹ใŠๅ•ใ„ๅˆใ‚ใ›ใฏsales-jp@stability.aiใซใ”้€ฃ็ตกใใ ใ•ใ„ใ€‚
Downloads last month
1
Safetensors
Model size
8B params
Tensor type
F32
ยท
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support

Spaces using stabilityai/japanese-stable-vlm 2

Collection including stabilityai/japanese-stable-vlm

Paper for stabilityai/japanese-stable-vlm