Views
No views yet

"A parrot able to speak Japanese, ukiyoe, edo period" — Stable Diffusion XL
japanese-stablelm-instruct-alpha-7b-v2 is a 7B parameter decoder-only language models pre-trained built on top of the Japanese-StableLM-Base-Alpha-7B model and further fine-tuned on various instruction-following datasets.pip install sentencepiece einopsjapanese-stablelm-instruct-alpha-7b-v2 by using the following code snippet:1import torch
2from transformers import LlamaTokenizer, AutoModelForCausalLM
3
4tokenizer = LlamaTokenizer.from_pretrained(
5 "novelai/nerdstash-tokenizer-v1", additional_special_tokens=["▁▁"]
6)
7model = AutoModelForCausalLM.from_pretrained(
8 "stabilityai/japanese-stablelm-instruct-alpha-7b-v2",
9 trust_remote_code=True,
10 torch_dtype=torch.float16,
11 variant="fp16",
12)
13model.eval()
14
15if torch.cuda.is_available():
16 model = model.to("cuda")
17
18def build_prompt(user_query, inputs="", sep="\n\n### "):
19 sys_msg = "以下は、タスクを説明する指示と、文脈のある入力の組み合わせです。要求を適切に満たす応答を書きなさい。"
20 p = sys_msg
21 roles = ["指示", "応答"]
22 msgs = [": \n" + user_query, ": \n"]
23 if inputs:
24 roles.insert(1, "入力")
25 msgs.insert(1, ": \n" + inputs)
26 for role, msg in zip(roles, msgs):
27 p += sep + role + msg
28 return p
29
30# Infer with prompt without any additional input
31user_inputs = {
32 "user_query": "与えられたことわざの意味を小学生でも分かるように教えてください。",
33 "inputs": "情けは人のためならず"
34}
35prompt = build_prompt(**user_inputs)
36
37input_ids = tokenizer.encode(
38 prompt,
39 add_special_tokens=False,
40 return_tensors="pt"
41)
42
43tokens = model.generate(
44 input_ids.to(device=model.device),
45 max_new_tokens=256,
46 temperature=1,
47 top_p=0.95,
48 do_sample=True,
49)
50
51out = tokenizer.decode(tokens[0][input_ids.shape[1]:], skip_special_tokens=True).strip()
52print(out)
53"""
54「情けは人のためならず」は、「情けをかけるとその人のためにならない」という意味ではありません。
55このことわざは、もともと「誰かのために行動するとその行動が回り回って自分に返ってくる」ということを説いたことわざです。
56"""
57japanese-stablelm-instruct-alpha-7b-v2 is an auto-regressive language model based on the NeoX transformer architecture.| Parameters | Hidden Size | Layers | Heads | Sequence Length |
|---|---|---|---|---|
| 7B | 4096 | 32 | 32 | 1024 |
japanese-stablelm-instruct-alpha-7b-v2 is fine-tuned on a combination of following datasets:1@misc{JapaneseStableLMInstructAlpha7Bv2,
2 url={[https://huggingface.co/stabilityai/japanese-stablelm-instruct-alpha-7b-v2](https://huggingface.co/stabilityai/japanese-stablelm-instruct-alpha-7b-v2)},
3 title={Japanese StableLM Instruct Alpha 7B v2},
4 author={Lee, Meng and Nakamura, Fujiki and Shing, Makoto and McCann, Paul and Akiba, Takuya and Orii, Naoki}
5}1@misc{alpaca,
2 author = {Rohan Taori and Ishaan Gulrajani and Tianyi Zhang and Yann Dubois and Xuechen Li and Carlos Guestrin and Percy Liang and Tatsunori B. Hashimoto },
3 title = {Stanford Alpaca: An Instruction-following LLaMA model},
4 year = {2023},
5 publisher = {GitHub},
6 journal = {GitHub repository},
7 howpublished = {\url{https://github.com/tatsu-lab/stanford_alpaca}},
8}1@software{gpt-neox-library,
2 title = {{GPT-NeoX: Large Scale Autoregressive Language Modeling in PyTorch}},
3 author = {Andonian, Alex and Anthony, Quentin and Biderman, Stella and Black, Sid and Gali, Preetham and Gao, Leo and Hallahan, Eric and Levy-Kramer, Josh and Leahy, Connor and Nestler, Lucas and Parker, Kip and Pieler, Michael and Purohit, Shivanshu and Songz, Tri and Phil, Wang and Weinbach, Samuel},
4 url = {https://www.github.com/eleutherai/gpt-neox},
5 doi = {10.5281/zenodo.5879544},
6 month = {8},
7 year = {2021},
8 version = {0.0.1},
9}