RichardErkhov commited on
Commit
2745839
1 Parent(s): 8e6cf00

uploaded readme

Browse files
Files changed (1) hide show
  1. README.md +210 -0
README.md ADDED
@@ -0,0 +1,210 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ Quantization made by Richard Erkhov.
2
+
3
+ [Github](https://github.com/RichardErkhov)
4
+
5
+ [Discord](https://discord.gg/pvy7H8DZMG)
6
+
7
+ [Request more models](https://github.com/RichardErkhov/quant_request)
8
+
9
+
10
+ japanese-gpt-neox-3.6b-instruction-ppo - bnb 8bits
11
+ - Model creator: https://huggingface.co/rinna/
12
+ - Original model: https://huggingface.co/rinna/japanese-gpt-neox-3.6b-instruction-ppo/
13
+
14
+
15
+
16
+
17
+ Original model description:
18
+ ---
19
+ language: ja
20
+ thumbnail: https://github.com/rinnakk/japanese-pretrained-models/blob/master/rinna.png
21
+ tags:
22
+ - gpt_neox
23
+ - text-generation
24
+ - lm
25
+ - nlp
26
+ license: mit
27
+ datasets:
28
+ - Anthropic/hh-rlhf
29
+ inference: false
30
+ base_model: rinna/japanese-gpt-neox-3.6b
31
+ ---
32
+
33
+ # japanese-gpt-neox-3.6b-instruction-ppo
34
+
35
+ ![rinna-icon](./rinna.png)
36
+
37
+ # Overview
38
+ This repository provides a Japanese GPT-NeoX model of 3.6 billion parameters. The model is based on [`rinna/japanese-gpt-neox-3.6b-instruction-sft-v2`](https://huggingface.co/rinna/japanese-gpt-neox-3.6b-instruction-sft-v2) and has been aligned to serve as an instruction-following conversational agent.
39
+
40
+ * **Model architecture**
41
+
42
+ A 36-layer, 2816-hidden-size transformer-based language model.
43
+
44
+ * **RLHF**
45
+
46
+ Following the [OpenAI InstructGPT paper](https://arxiv.org/abs/2203.02155), **Reinforcement Learning from Human Feedback** (RLHF) has been applied to aligning the model's behaviour with input instructions. Particularly, the model has been trained in two stages, i.e. **Supervised Fine-Tuning** (SFT) and [PPO](https://arxiv.org/abs/1707.06347)-based **Reinforcement Learning** (RL).
47
+ * The first SFT stage produces [`rinna/japanese-gpt-neox-3.6b-instruction-sft-v2`](https://huggingface.co/rinna/japanese-gpt-neox-3.6b-instruction-sft-v2).
48
+ * The second RL stage produces this model.
49
+
50
+ * **PPO vs. SFT evaluation**
51
+
52
+ We conducted human evaluation and ChatGPT-based automated evaluation on 100 prompts to assess the *performance gain from reinforcement learning*.
53
+
54
+ | [PPO](https://huggingface.co/rinna/japanese-gpt-neox-3.6b-instruction-ppo) vs. [SFT](https://huggingface.co/rinna/japanese-gpt-neox-3.6b-instruction-sft-v2) | win | tie | loss |
55
+ | :---: | :---: | :---: | :---: |
56
+ | Human evaluation | **47**% | 30% | 23% |
57
+ | ChatGPT auto. evaluation | **63**% | 3% | 34% |
58
+
59
+ * **Reinforcement learning**
60
+
61
+ We used [CarperAI/trlx](https://github.com/CarperAI/trlx) and its implementation of the PPO algorithm for the RL stage.
62
+
63
+ The RL data is the subset of the following dataset and has been translated into Japanese.
64
+ * [Anthropic HH RLHF data](https://huggingface.co/datasets/Anthropic/hh-rlhf)
65
+
66
+ * **Model Series**
67
+
68
+ | Variant | Link |
69
+ | :-- | :--|
70
+ | 3.6B PPO | https://huggingface.co/rinna/japanese-gpt-neox-3.6b-instruction-ppo |
71
+ | 3.6B SFT-v2 | https://huggingface.co/rinna/japanese-gpt-neox-3.6b-instruction-sft-v2 |
72
+ | 3.6B SFT | https://huggingface.co/rinna/japanese-gpt-neox-3.6b-instruction-sft |
73
+ | 3.6B pretrained | https://huggingface.co/rinna/japanese-gpt-neox-3.6b |
74
+
75
+ * **Contributors**
76
+
77
+ [Tianyu Zhao](https://huggingface.co/tianyuz) and [Kei Sawada](https://huggingface.co/keisawada)
78
+
79
+ # Limitations
80
+ * We found this verison of PPO model tends to generate repeated text more often than its SFT counterpart, and thus we set `repetition_penalty=1.1` for better generation performance. (*The same generation hyper-parameters are applied to the SFT model in aforementioned evaluation experiments.*) You can also explore other hyperparameter combinations that yield higher generation randomness/diversity for better generation quality, e.g. `temperature=0.9, repetition_penalty=1.0`.
81
+
82
+ # I/O Format
83
+
84
+ A special format has been adopted to construct inputs.
85
+ * An input prompt is formatted as a conversation between `ユーザー` and `システム`.
86
+ * Each input utterance consists of (1) its speaker (`"ユーザー"` or `"システム"`), (2) a colon (`":"`), (3) a whitespace (`" "`), and (4) utterance text (e.g. `"世界で一番高い山は?"`).
87
+ * The input prompt should be ended with `"システム: "` to acknowledge the model to generate a response.
88
+ * Since the model's tokenizer does not recognize `"\n"`, a special newline symbol `"<NL>"` is used instead.
89
+ * All the newlines in input and output utterances should be replaced with `"<NL>"`.
90
+ * All the utterances in the input prompt should be separated by `"<NL>"`.
91
+
92
+ Following is an example to construct an input from a conversation.
93
+ ~~~python
94
+ prompt = [
95
+ {
96
+ "speaker": "ユーザー",
97
+ "text": "コンタクトレンズを慣れるにはどうすればよいですか?"
98
+ },
99
+ {
100
+ "speaker": "システム",
101
+ "text": "これについて具体的に説明していただけますか?何が難しいのでしょうか?"
102
+ },
103
+ {
104
+ "speaker": "ユーザー",
105
+ "text": "目が痛いのです。"
106
+ },
107
+ {
108
+ "speaker": "システム",
109
+ "text": "分かりました、コンタクトレンズをつけると目がかゆくなるということですね。思った以上にレンズを外す必要があるでしょうか?"
110
+ },
111
+ {
112
+ "speaker": "ユーザー",
113
+ "text": "いえ、レンズは外しませんが、目が赤くなるんです。"
114
+ }
115
+ ]
116
+ prompt = [
117
+ f"{uttr['speaker']}: {uttr['text']}"
118
+ for uttr in prompt
119
+ ]
120
+ prompt = "<NL>".join(prompt)
121
+ prompt = (
122
+ prompt
123
+ + "<NL>"
124
+ + "システム: "
125
+ )
126
+ print(prompt)
127
+ # "ユーザー: コンタクトレンズを慣れるにはどうすればよいですか?<NL>システム: これについて具体的に説明していただけますか?何が難しいのでしょうか?<NL>ユーザー: 目が痛いのです。<NL>システム: 分かりました、コンタクトレンズをつけると目がかゆくなるということですね。思った以上にレンズを外す必要があるでしょうか?<NL>ユーザー: いえ、レンズは外しませんが、目が赤くなるんです。<NL>システム: "
128
+ ~~~
129
+ # How to use the model
130
+
131
+ ~~~~python
132
+ import torch
133
+ from transformers import AutoTokenizer, AutoModelForCausalLM
134
+
135
+ tokenizer = AutoTokenizer.from_pretrained("rinna/japanese-gpt-neox-3.6b-instruction-ppo", use_fast=False)
136
+ model = AutoModelForCausalLM.from_pretrained("rinna/japanese-gpt-neox-3.6b-instruction-ppo")
137
+
138
+ if torch.cuda.is_available():
139
+ model = model.to("cuda")
140
+
141
+ token_ids = tokenizer.encode(prompt, add_special_tokens=False, return_tensors="pt")
142
+
143
+ with torch.no_grad():
144
+ output_ids = model.generate(
145
+ token_ids.to(model.device),
146
+ do_sample=True,
147
+ max_new_tokens=128,
148
+ temperature=0.7,
149
+ repetition_penalty=1.1,
150
+ pad_token_id=tokenizer.pad_token_id,
151
+ bos_token_id=tokenizer.bos_token_id,
152
+ eos_token_id=tokenizer.eos_token_id
153
+ )
154
+
155
+ output = tokenizer.decode(output_ids.tolist()[0][token_ids.size(1):])
156
+ output = output.replace("<NL>", "\n")
157
+ print(output)
158
+ """それは、コンタクトレンズが目に合わないために起こることがあります。レンズが目の表面に長時間触れ続けることが原因となることがあります。また、コンタクトレンズが汚れている可能性もあります。コンタクトレンズケースを定期的に洗浄したり、コンタクトレンズを正しくフィットさせるようにしたりすることが役立ちます。</s>"""
159
+ ~~~~
160
+
161
+ # Tokenization
162
+ The model uses a [sentencepiece](https://github.com/google/sentencepiece)-based tokenizer.
163
+ * The tokenizer has a vocabulary size of 32,000.
164
+ * It uses sentencepiece's byte fallback feature to decompose unknown text pieces into UTF-8 byte pieces and to avoid producing `<UNK>` tokens.
165
+ * sentencepiece's `--add_dummy_prefix` option was turned off so that a leading whitespace will not be prepended automatically.
166
+ ~~~
167
+ print(tokenizer.tokenize("吾輩は猫である"))
168
+ # ['吾', '輩', 'は', '猫', 'である']
169
+ # instead of ['▁', '吾', '輩', 'は', '猫', 'である'] as in rinna/japanese-gpt-1b
170
+ ~~~
171
+ * sentencepiece's `--remove_extra_whitespaces` option was turned off so that leading, trailing, and duplicate whitespaces are reserved.
172
+ ~~~
173
+ print(tokenizer.tokenize(" 吾輩は 猫である "))
174
+ # ['▁', '▁', '吾', '輩', 'は', '▁', '▁', '猫', 'である', '▁', '▁', '▁']
175
+ # instead of ['▁', '吾', '輩', 'は', '▁猫', 'である'] as in rinna/japanese-gpt-1b
176
+ ~~~
177
+ * Don't forget to set `use_fast=False` to make the above features function correctly.
178
+ ~~~
179
+ good_tokenizer = AutoTokenizer.from_pretrained("rinna/japanese-gpt-neox-3.6b", use_fast=False)
180
+ bad_tokenizer = AutoTokenizer.from_pretrained("rinna/japanese-gpt-neox-3.6b")
181
+
182
+ print(good_tokenizer.decode(good_tokenizer.encode("გამარჯობა 吾輩は 猫である ")))
183
+ # 'გამარჯობა 吾輩は 猫である </s>'
184
+ print(bad_tokenizer.decode(bad_tokenizer.encode("გამარჯობა 吾輩は 猫である ")))
185
+ # 'გამარ[UNK]ობა 吾輩は 猫である </s>'
186
+ ~~~
187
+
188
+ # How to cite
189
+ ```bibtex
190
+ @misc{rinna-japanese-gpt-neox-3.6b-instruction-ppo,
191
+ title = {rinna/japanese-gpt-neox-3.6b-instruction-ppo},
192
+ author = {Zhao, Tianyu and Sawada, Kei},
193
+ url = {https://huggingface.co/rinna/japanese-gpt-neox-3.6b-instruction-ppo}
194
+ }
195
+
196
+ @inproceedings{sawada2024release,
197
+ title = {Release of Pre-Trained Models for the {J}apanese Language},
198
+ author = {Sawada, Kei and Zhao, Tianyu and Shing, Makoto and Mitsui, Kentaro and Kaga, Akio and Hono, Yukiya and Wakatsuki, Toshiaki and Mitsuda, Koh},
199
+ booktitle = {Proceedings of the 2024 Joint International Conference on Computational Linguistics, Language Resources and Evaluation (LREC-COLING 2024)},
200
+ month = {5},
201
+ year = {2024},
202
+ pages = {13898--13905},
203
+ url = {https://aclanthology.org/2024.lrec-main.1213},
204
+ note = {\url{https://arxiv.org/abs/2404.01657}}
205
+ }
206
+ ```
207
+
208
+ # Licenese
209
+ [The MIT license](https://opensource.org/licenses/MIT)
210
+