tianyuz commited on
Commit
1be71f5
โ€ข
1 Parent(s): e61009e
Files changed (7) hide show
  1. README.md +156 -0
  2. config.json +23 -0
  3. pytorch_model.bin +3 -0
  4. rinna.png +0 -0
  5. spiece.model +3 -0
  6. spiece.vocab +0 -0
  7. 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"}