tianyuz commited on
Commit
3d06736
1 Parent(s): 49e410f

init commit

Browse files
Files changed (7) hide show
  1. README.md +132 -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,135 @@
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
18
+
19
+ ![rinna-icon](./rinna.png)
20
+
21
+ 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 a instruction-following conversational agent.
22
+
23
+ A special format has been adopted to construct inputs.
24
+ * An input prompt is formatted as a conversation between `ユーザー` and `システム`.
25
+ * Each input utterance consists of (1) its speaker (`"ユーザー"` or `"システム"`), (2) a colon (`":"`), (3) a whitespace (`" "`), and (4) utterance text (e.g. `"世界で一番高い山は?"`).
26
+ * The input prompt should be ended with `"システム: "` to acknowledge the model to generate a response.
27
+ * Since the model's tokenizer does not recognize `"\n"`, a special newline symbol `"<NL>"` is used instead.
28
+ * All the newlines in input and output utterances should be replaced with `"<NL>"`.
29
+ * All the utterances in the input prompt should be separated by `"<NL>"`.
30
+
31
+ Following is an example to construct an input from a conversation.
32
+ ~~~python
33
+ prompt = [
34
+ {
35
+ "speaker": "ユーザー",
36
+ "text": "日本のおすすめの観光地を教えてください。"
37
+ },
38
+ {
39
+ "speaker": "システム",
40
+ "text": "どの地域の観光地が知りたいですか?"
41
+ },
42
+ {
43
+ "speaker": "ユーザー",
44
+ "text": "渋谷の観光地を教えてください。"
45
+ }
46
+ ]
47
+ prompt = [
48
+ f"{uttr['speaker']}: {uttr['text']}"
49
+ for uttr in prompt
50
+ ]
51
+ prompt = "<NL>".join(prompt)
52
+ prompt = (
53
+ prompt
54
+ + "<NL>"
55
+ + "システム: "
56
+ )
57
+ print(prompt)
58
+ # "ユーザー: 日本のおすすめの観光地を教えてください。<NL>システム: どの地域の観光地が知りたいですか?<NL>ユーザー: 渋谷の観光地を教えてください。<NL>システム: "
59
+ ~~~
60
+
61
+ # How to use the model
62
+
63
+ ~~~~python
64
+ import torch
65
+ from transformers import AutoTokenizer, AutoModelForCausalLM
66
+
67
+ tokenizer = AutoTokenizer.from_pretrained(".", use_fast=False)
68
+ model = AutoModelForCausalLM.from_pretrained(".")
69
+
70
+ if torch.cuda.is_available():
71
+ model = model.to("cuda")
72
+
73
+ token_ids = tokenizer.encode(prompt, add_special_tokens=False, return_tensors="pt")
74
+
75
+ with torch.no_grad():
76
+ output_ids = model.generate(
77
+ token_ids.to(model.device),
78
+ do_sample=True,
79
+ max_new_tokens=128,
80
+ temperature=0.7,
81
+ pad_token_id=tokenizer.pad_token_id,
82
+ bos_token_id=tokenizer.bos_token_id,
83
+ eos_token_id=tokenizer.eos_token_id
84
+ )
85
+
86
+ output = tokenizer.decode(output_ids.tolist()[0][token_ids.size(1):])
87
+ output = output.replace("<NL>", "\n")
88
+ print(output)
89
+ """分かりました。いくつかのおすすめを紹介します。
90
+ 1. ハチ公像です。ハチ公像は、日本の観光スポットの1つとして人気があります。
91
+ 2. スクランブル交差点です。多くの人々が行き交う大きな交差点で、観光客に人気のスポットです。
92
+ 3. 109です。109は、ショッピングやエンターテイメント施設です。
93
+ 4. 道玄坂です。道玄坂は、日本の商業地区である坂道です。</s>"""
94
+ ~~~~
95
+
96
+ # Model architecture
97
+ A 36-layer, 2816-hidden-size transformer-based language model.
98
+
99
+ # Finetuning
100
+ The finetuning data is the subset of the following datasets and has been translated into Japanese.
101
+ * [Anthropic HH RLHF data](https://huggingface.co/datasets/Anthropic/hh-rlhf)
102
+ * [FLAN Instruction Tuning data](https://github.com/google-research/FLAN)
103
+ * [Stanford Human Preferences Dataset](https://huggingface.co/datasets/stanfordnlp/SHP)
104
+
105
+ The data will **not** be released.
106
+
107
+ # Tokenization
108
+ The model uses a [sentencepiece](https://github.com/google/sentencepiece)-based tokenizer.
109
+ * The tokenizer has a vocabulary size of 32,000.
110
+ * It uses sentencepiece's byte fallback feature to decompose unknown text pieces into UTF-8 byte pieces and to avoid producing `<UNK>` tokens.
111
+ * sentencepiece's `--add_dummy_prefix` option was turned off so that a leading whitespace will not be prepended automatically.
112
+ ~~~
113
+ print(tokenizer.tokenize("吾輩は猫である"))
114
+ # ['吾', '輩', 'は', '猫', 'である']
115
+ # instead of ['▁', '吾', '輩', 'は', '猫', 'である'] as in rinna/japanese-gpt-1b
116
+ ~~~
117
+ * sentencepiece's `--remove_extra_whitespaces` option was turned off so that leading, trailing, and duplicate whitespaces are reserved.
118
+ ~~~
119
+ print(tokenizer.tokenize(" 吾輩は 猫である "))
120
+ # ['▁', '▁', '吾', '輩', 'は', '▁', '▁', '猫', 'である', '▁', '▁', '▁']
121
+ # instead of ['▁', '吾', '輩', 'は', '▁猫', 'である'] as in rinna/japanese-gpt-1b
122
+ ~~~
123
+ * Don't forget to set `use_fast=False` to make the above features function correctly.
124
+ ~~~
125
+ good_tokenizer = AutoTokenizer.from_pretrained("rinna/japanese-gpt-neox-3.6b", use_fast=False)
126
+ bad_tokenizer = AutoTokenizer.from_pretrained("rinna/japanese-gpt-neox-3.6b")
127
+
128
+ print(good_tokenizer.decode(good_tokenizer.encode("გამარჯობა 吾輩は 猫である ")))
129
+ # 'გამარჯობა 吾輩は 猫である </s>'
130
+ print(bad_tokenizer.decode(bad_tokenizer.encode("გამარჯობა 吾輩は 猫である ")))
131
+ # 'გამარ[UNK]ობა 吾輩は 猫である </s>'
132
+ ~~~
133
+
134
+ # Licenese
135
+ [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:0c6124c628f8ecc29be1b6ee0625670062340f5b99cfe543ccf049fa90e6207b
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"}