upload
Browse files- README.md +156 -0
- config.json +23 -0
- pytorch_model.bin +3 -0
- rinna.png +0 -0
- spiece.model +3 -0
- spiece.vocab +0 -0
- tokenizer_config.json +1 -0
README.md
CHANGED
@@ -1,3 +1,159 @@
|
|
1 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
license: mit
|
|
|
|
|
|
|
|
|
3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
+
language: ja
|
3 |
+
thumbnail: https://github.com/rinnakk/japanese-pretrained-models/blob/master/rinna.png
|
4 |
+
tags:
|
5 |
+
- ja
|
6 |
+
- gpt_neox
|
7 |
+
- text-generation
|
8 |
+
- lm
|
9 |
+
- nlp
|
10 |
license: mit
|
11 |
+
datasets:
|
12 |
+
- Anthropic/hh-rlhf
|
13 |
+
- stanfordnlp/SHP
|
14 |
+
inference: false
|
15 |
---
|
16 |
+
|
17 |
+
# japanese-gpt-neox-3.6b-instruction-sft-v2
|
18 |
+
|
19 |
+
![rinna-icon](./rinna.png)
|
20 |
+
|
21 |
+
# Overview
|
22 |
+
This repository provides a Japanese GPT-NeoX model of 3.6 billion parameters. The model is based on [`rinna/japanese-gpt-neox-3.6b`](https://huggingface.co/rinna/japanese-gpt-neox-3.6b) and has been finetuned to serve as an instruction-following conversational agent.
|
23 |
+
|
24 |
+
This model slightly differs from the previous SFT model [`rinna/japanese-gpt-neox-3.6b-instruction-sft`](https://huggingface.co/rinna/japanese-gpt-neox-3.6b-instruction-sft), where a different data split is used for training.
|
25 |
+
|
26 |
+
* **Model architecture**
|
27 |
+
|
28 |
+
A 36-layer, 2816-hidden-size transformer-based language model.
|
29 |
+
|
30 |
+
* **SFT vs. previous SFT evaluation**
|
31 |
+
|
32 |
+
We conducted ChatGPT-based automated evaluation on 100 prompts to assess the performance difference between this SFT model and the previous SFT model.
|
33 |
+
|
34 |
+
| [this SFT](https://huggingface.co/rinna/japanese-gpt-neox-3.6b-instruction-sft-v2) vs. [previous SFT](https://huggingface.co/rinna/japanese-gpt-neox-3.6b-instruction-sft) | win | tie | loss |
|
35 |
+
| :---: | :---: | :---: | :---: |
|
36 |
+
| ChatGPT auto. evaluation | **55**% | 0% | 45% |
|
37 |
+
|
38 |
+
* **Finetuning**
|
39 |
+
|
40 |
+
The finetuning data is the subset of the following datasets and has been translated into Japanese.
|
41 |
+
* [Anthropic HH RLHF data](https://huggingface.co/datasets/Anthropic/hh-rlhf)
|
42 |
+
* [FLAN Instruction Tuning data](https://github.com/google-research/FLAN)
|
43 |
+
* [Stanford Human Preferences Dataset](https://huggingface.co/datasets/stanfordnlp/SHP)
|
44 |
+
|
45 |
+
The data will **not** be released.
|
46 |
+
|
47 |
+
* **Authors**
|
48 |
+
|
49 |
+
[Tianyu Zhao](https://huggingface.co/tianyuz) and [Kei Sawada](https://huggingface.co/keisawada)
|
50 |
+
|
51 |
+
# I/O Format
|
52 |
+
|
53 |
+
A special format has been adopted to construct inputs.
|
54 |
+
* An input prompt is formatted as a conversation between `ใฆใผใถใผ` and `ใทในใใ `.
|
55 |
+
* Each input utterance consists of (1) its speaker (`"ใฆใผใถใผ"` or `"ใทในใใ "`), (2) a colon (`":"`), (3) a whitespace (`" "`), and (4) utterance text (e.g. `"ไธ็ใงไธ็ช้ซใๅฑฑใฏ๏ผ"`).
|
56 |
+
* The input prompt should be ended with `"ใทในใใ : "` to acknowledge the model to generate a response.
|
57 |
+
* Since the model's tokenizer does not recognize `"\n"`, a special newline symbol `"<NL>"` is used instead.
|
58 |
+
* All the newlines in input and output utterances should be replaced with `"<NL>"`.
|
59 |
+
* All the utterances in the input prompt should be separated by `"<NL>"`.
|
60 |
+
|
61 |
+
Following is an example to construct an input from a conversation.
|
62 |
+
~~~python
|
63 |
+
prompt = [
|
64 |
+
{
|
65 |
+
"speaker": "ใฆใผใถใผ",
|
66 |
+
"text": "ใณใณใฟใฏใใฌใณใบใๆ
ฃใใใซใฏใฉใใใใฐใใใงใใ๏ผ"
|
67 |
+
},
|
68 |
+
{
|
69 |
+
"speaker": "ใทในใใ ",
|
70 |
+
"text": "ใใใซใคใใฆๅ
ทไฝ็ใซ่ชฌๆใใฆใใใ ใใพใใ๏ผไฝใ้ฃใใใฎใงใใใใ๏ผ"
|
71 |
+
},
|
72 |
+
{
|
73 |
+
"speaker": "ใฆใผใถใผ",
|
74 |
+
"text": "็ฎใ็ใใฎใงใใ"
|
75 |
+
},
|
76 |
+
{
|
77 |
+
"speaker": "ใทในใใ ",
|
78 |
+
"text": "ๅใใใพใใใใณใณใฟใฏใใฌใณใบใใคใใใจ็ฎใใใใใชใใจใใใใจใงใใญใๆใฃใไปฅไธใซใฌใณใบใๅคใๅฟ
่ฆใใใใงใใใใ๏ผ"
|
79 |
+
},
|
80 |
+
{
|
81 |
+
"speaker": "ใฆใผใถใผ",
|
82 |
+
"text": "ใใใใฌใณใบใฏๅคใใพใใใใ็ฎใ่ตคใใชใใใงใใ"
|
83 |
+
}
|
84 |
+
]
|
85 |
+
prompt = [
|
86 |
+
f"{uttr['speaker']}: {uttr['text']}"
|
87 |
+
for uttr in prompt
|
88 |
+
]
|
89 |
+
prompt = "<NL>".join(prompt)
|
90 |
+
prompt = (
|
91 |
+
prompt
|
92 |
+
+ "<NL>"
|
93 |
+
+ "ใทในใใ : "
|
94 |
+
)
|
95 |
+
print(prompt)
|
96 |
+
# "ใฆใผใถใผ: ใณใณใฟใฏใใฌใณใบใๆ
ฃใใใซใฏใฉใใใใฐใใใงใใ๏ผ<NL>ใทในใใ : ใใใซใคใใฆๅ
ทไฝ็ใซ่ชฌๆใใฆใใใ ใใพใใ๏ผไฝใ้ฃใใใฎใงใใใใ๏ผ<NL>ใฆใผใถใผ: ็ฎใ็ใใฎใงใใ<NL>ใทในใใ : ๅใใใพใใใใณใณใฟใฏใใฌใณใบใใคใใใจ็ฎใใใใใชใใจใใใใจใงใใญใๆใฃใไปฅไธใซใฌใณใบใๅคใๅฟ
่ฆใใใใงใใใใ๏ผ<NL>ใฆใผใถใผ: ใใใใฌใณใบใฏๅคใใพใใใใ็ฎใ่ตคใใชใใใงใใ<NL>ใทในใใ : "
|
97 |
+
~~~
|
98 |
+
|
99 |
+
# How to use the model
|
100 |
+
|
101 |
+
~~~~python
|
102 |
+
import torch
|
103 |
+
from transformers import AutoTokenizer, AutoModelForCausalLM
|
104 |
+
|
105 |
+
tokenizer = AutoTokenizer.from_pretrained("rinna/japanese-gpt-neox-3.6b-instruction-sft-v2", use_fast=False)
|
106 |
+
model = AutoModelForCausalLM.from_pretrained("rinna/japanese-gpt-neox-3.6b-instruction-sft-v2")
|
107 |
+
|
108 |
+
if torch.cuda.is_available():
|
109 |
+
model = model.to("cuda")
|
110 |
+
|
111 |
+
token_ids = tokenizer.encode(prompt, add_special_tokens=False, return_tensors="pt")
|
112 |
+
|
113 |
+
with torch.no_grad():
|
114 |
+
output_ids = model.generate(
|
115 |
+
token_ids.to(model.device),
|
116 |
+
do_sample=True,
|
117 |
+
max_new_tokens=128,
|
118 |
+
temperature=0.7,
|
119 |
+
repetition_penalty=1.1,
|
120 |
+
pad_token_id=tokenizer.pad_token_id,
|
121 |
+
bos_token_id=tokenizer.bos_token_id,
|
122 |
+
eos_token_id=tokenizer.eos_token_id
|
123 |
+
)
|
124 |
+
|
125 |
+
output = tokenizer.decode(output_ids.tolist()[0][token_ids.size(1):])
|
126 |
+
output = output.replace("<NL>", "\n")
|
127 |
+
print(output)
|
128 |
+
"""ใใใใพใใใใพใใฏใใณใณใฟใฏใใฌใณใบใ้ทๆ้็็จใใใใจใซใใ็ฎใฎไนพ็ฅใ้ฒใใใจใใงใใพใใใพใใๆฏๆฅๅใๆ้ๅธฏใซใณใณใฟใฏใใฌใณใบใ็็จใใฆใฟใใใจใใงใใพใใใใใฆใใณใณใฟใฏใใฌใณใบใ็ฎใซๅใใชใใใใชๅ ดๅใฏใๆฐใใใใฎใ่ฉฆใใฆใฟใๅฟ
่ฆใใใใพใใ</s>"""
|
129 |
+
~~~~
|
130 |
+
|
131 |
+
# Tokenization
|
132 |
+
The model uses a [sentencepiece](https://github.com/google/sentencepiece)-based tokenizer.
|
133 |
+
* The tokenizer has a vocabulary size of 32,000.
|
134 |
+
* It uses sentencepiece's byte fallback feature to decompose unknown text pieces into UTF-8 byte pieces and to avoid producing `<UNK>` tokens.
|
135 |
+
* sentencepiece's `--add_dummy_prefix` option was turned off so that a leading whitespace will not be prepended automatically.
|
136 |
+
~~~
|
137 |
+
print(tokenizer.tokenize("ๅพ่ผฉใฏ็ซใงใใ"))
|
138 |
+
# ['ๅพ', '่ผฉ', 'ใฏ', '็ซ', 'ใงใใ']
|
139 |
+
# instead of ['โ', 'ๅพ', '่ผฉ', 'ใฏ', '็ซ', 'ใงใใ'] as in rinna/japanese-gpt-1b
|
140 |
+
~~~
|
141 |
+
* sentencepiece's `--remove_extra_whitespaces` option was turned off so that leading, trailing, and duplicate whitespaces are reserved.
|
142 |
+
~~~
|
143 |
+
print(tokenizer.tokenize(" ๅพ่ผฉใฏ ็ซใงใใ "))
|
144 |
+
# ['โ', 'โ', 'ๅพ', '่ผฉ', 'ใฏ', 'โ', 'โ', '็ซ', 'ใงใใ', 'โ', 'โ', 'โ']
|
145 |
+
# instead of ['โ', 'ๅพ', '่ผฉ', 'ใฏ', 'โ็ซ', 'ใงใใ'] as in rinna/japanese-gpt-1b
|
146 |
+
~~~
|
147 |
+
* Don't forget to set `use_fast=False` to make the above features function correctly.
|
148 |
+
~~~
|
149 |
+
good_tokenizer = AutoTokenizer.from_pretrained("rinna/japanese-gpt-neox-3.6b", use_fast=False)
|
150 |
+
bad_tokenizer = AutoTokenizer.from_pretrained("rinna/japanese-gpt-neox-3.6b")
|
151 |
+
|
152 |
+
print(good_tokenizer.decode(good_tokenizer.encode("แแแแแ แฏแแแ ๅพ่ผฉใฏ ็ซใงใใ ")))
|
153 |
+
# 'แแแแแ แฏแแแ ๅพ่ผฉใฏ ็ซใงใใ </s>'
|
154 |
+
print(bad_tokenizer.decode(bad_tokenizer.encode("แแแแแ แฏแแแ ๅพ่ผฉใฏ ็ซใงใใ ")))
|
155 |
+
# 'แแแแแ [UNK]แแแ ๅพ่ผฉใฏ ็ซใงใใ </s>'
|
156 |
+
~~~
|
157 |
+
|
158 |
+
# Licenese
|
159 |
+
[The MIT license](https://opensource.org/licenses/MIT)
|
config.json
ADDED
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"architectures": [
|
3 |
+
"GPTNeoXForCausalLM"
|
4 |
+
],
|
5 |
+
"bos_token_id": 2,
|
6 |
+
"eos_token_id": 3,
|
7 |
+
"hidden_act": "gelu",
|
8 |
+
"hidden_size": 2816,
|
9 |
+
"initializer_range": 0.02,
|
10 |
+
"intermediate_size": 11264,
|
11 |
+
"layer_norm_eps": 1e-05,
|
12 |
+
"max_position_embeddings": 2048,
|
13 |
+
"model_type": "gpt_neox",
|
14 |
+
"num_attention_heads": 22,
|
15 |
+
"num_hidden_layers": 36,
|
16 |
+
"rotary_emb_base": 10000,
|
17 |
+
"rotary_pct": 1.0,
|
18 |
+
"tie_word_embeddings": false,
|
19 |
+
"torch_dtype": "float16",
|
20 |
+
"use_cache": true,
|
21 |
+
"use_parallel_residual": false,
|
22 |
+
"vocab_size": 32000
|
23 |
+
}
|
pytorch_model.bin
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:5ba121ae99a336269e4eaf02c95b8bb8fe28e8eea5413d5d393cdc2c39537110
|
3 |
+
size 7365670537
|
rinna.png
ADDED
spiece.model
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:7d78ab344146700112cd41628ac7ce54b79c0868fe0c7c201750d8237b54dbb4
|
3 |
+
size 786216
|
spiece.vocab
ADDED
The diff for this file is too large to render.
See raw diff
|
|
tokenizer_config.json
ADDED
@@ -0,0 +1 @@
|
|
|
|
|
1 |
+
{"eos_token": "</s>", "unk_token": "[UNK]", "pad_token": "[PAD]", "extra_ids": 0, "additional_special_tokens": [], "sp_model_kwargs": {}, "bos_token": "<s>", "cls_token": "[CLS]", "sep_token": "[SEP]", "mask_token": "[MASK]", "do_lower_case": false, "tokenizer_class": "T5Tokenizer"}
|