This is a 7B-parameter decoder-only Japanese language model fine-tuned on instruction-following datasets, built on top of the base model
Japanese Stable LM Base Gamma 7B.
Ensure you are using Transformers 4.34.0 or newer.
1import torch
2from transformers import AutoTokenizer, AutoModelForCausalLM
3
4tokenizer = AutoTokenizer.from_pretrained("stabilityai/japanese-stablelm-instruct-gamma-7b")
5model = AutoModelForCausalLM.from_pretrained(
6 "stabilityai/japanese-stablelm-instruct-gamma-7b",
7 torch_dtype="auto",
8)
9model.eval()
10
11if torch.cuda.is_available():
12 model = model.to("cuda")
13
14def build_prompt(user_query, inputs="", sep="\n\n### "):
15 sys_msg = "以下は、タスクを説明する指示と、文脈のある入力の組み合わせです。要求を適切に満たす応答を書きなさい。"
16 p = sys_msg
17 roles = ["指示", "応答"]
18 msgs = [": \n" + user_query, ": \n"]
19 if inputs:
20 roles.insert(1, "入力")
21 msgs.insert(1, ": \n" + inputs)
22 for role, msg in zip(roles, msgs):
23 p += sep + role + msg
24 return p
25
26# Infer with prompt without any additional input
27user_inputs = {
28 "user_query": "与えられたことわざの意味を小学生でも分かるように教えてください。",
29 "inputs": "情けは人のためならず"
30}
31prompt = build_prompt(**user_inputs)
32
33input_ids = tokenizer.encode(
34 prompt,
35 add_special_tokens=False,
36 return_tensors="pt"
37)
38
39tokens = model.generate(
40 input_ids.to(device=model.device),
41 max_new_tokens=256,
42 temperature=1,
43 top_p=0.95,
44 do_sample=True,
45)
46
47out = tokenizer.decode(tokens[0][input_ids.shape[1]:], skip_special_tokens=True).strip()
48print(out)
For details, please see Mistral AI's
paper and
release blog post.
The model is intended to be used by all individuals as a foundational model for application-specific fine-tuning without strict limitations on commercial use.
The pre-training dataset may have contained offensive or inappropriate content even after applying data cleansing filters which can be reflected in the model-generated text. 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.
The fine-tuning was carried out by
Fujiki Nakamura.
Other aspects, including data preparation and evaluation, were handled by the Language Team of Stability AI Japan, notably
Meng Lee,
Makoto Shing,
Paul McCann,
Naoki Orii, and
Takuya Akiba.
This model is based on Mistral-7B-v0.1 released by the Mistral AI team. We are grateful to the Mistral AI team for providing such an excellent base model.
We are grateful for the contributions of the EleutherAI Polyglot-JA team in helping us to collect a large amount of pre-training data in Japanese. Polyglot-JA members includes Hyunwoong Ko (Project Lead), Fujiki Nakamura (originally started this project when he commited to the Polyglot team), Yunho Mo, Minji Jung, KeunSeok Im, and Su-Kyeong Jang.
We are also appreciative of
AI Novelist/Sta (Bit192, Inc.) and the numerous contributors from
Stable Community Japan for assisting us in gathering a large amount of high-quality Japanese textual data for model training.