Taishi-N324 commited on
Commit
d6120ba
1 Parent(s): 629d47f

Upload README.md

Browse files
Files changed (1) hide show
  1. README.md +235 -0
README.md ADDED
@@ -0,0 +1,235 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - en
4
+ - ja
5
+ library_name: transformers
6
+ pipeline_tag: text-generation
7
+ license: llama2
8
+ model_type: llama
9
+ ---
10
+
11
+ # Swallow
12
+
13
+ Our Swallow model has undergone continuous pre-training from the Llama 2 family, primarily with the addition of Japanese language data. The tuned versions use supervised fine-tuning (SFT).
14
+ Links to other models can be found in the index.
15
+
16
+ ## Swallow Model Index
17
+ |Model|Swallow-hf|Swallow-instruct-hf|
18
+ |---|---|---|
19
+ |7B| [Link](https://huggingface.co/tokyotech-llm/Swallow-7b-hf) | [Link](https://huggingface.co/tokyotech-llm/Swallow-7b-instruct-hf)|
20
+ |7B-Plus| [Link](https://huggingface.co/tokyotech-llm/Swallow-7b-plus-hf) | Coming Soon |
21
+ |13B| [Link](https://huggingface.co/tokyotech-llm/Swallow-13b-hf) | [Link](https://huggingface.co/tokyotech-llm/Swallow-13b-instruct-hf)|
22
+ |70B| [Link](https://huggingface.co/tokyotech-llm/Swallow-70b-hf) | [Link](https://huggingface.co/tokyotech-llm/Swallow-70b-instruct-hf)|
23
+
24
+ ## Swallow Model Index NVE (No Vocabulary Expansion)
25
+ |Model|Swallow-NVE-hf|Swallow-NVE-instruct-hf|
26
+ |---|---|---|
27
+ |7B| [Link](https://huggingface.co/tokyotech-llm/Swallow-7b-NVE-hf) | [Link](https://huggingface.co/tokyotech-llm/Swallow-7b-NVE-instruct-hf)|
28
+ |13B| [Link](https://huggingface.co/tokyotech-llm/Swallow-13b-NVE-hf) | Coming Soon |
29
+ |70B| [Link](https://huggingface.co/tokyotech-llm/Swallow-70b-NVE-hf) | [Link](https://huggingface.co/tokyotech-llm/Swallow-70b-NVE-instruct-hf)|
30
+
31
+ We released the 7B and 70B models without vocabulary expansion on January 26th, 2024. The 13B model was released on February 4th, 2024, and its instruction-tuned version is coming soon. Swallow-7B-Plus is a model that has been trained with a larger number of Japanese tokens compared to Swallow-7B and its release date is March 2nd, 2024.
32
+
33
+
34
+ ![logo](./logo.png)
35
+
36
+ This repository provides large language models developed by [TokyoTech-LLM](https://tokyotech-llm.github.io/).
37
+ Read our [blog post](https://zenn.dev/tokyotech_lm/articles/d6cb3a8fdfc907) or our paper (preprint coming soon) for more details!
38
+
39
+
40
+ ## Model Details
41
+
42
+ * **Model type**: Please refer to LLaMA-2 technical report for details on the model architecture.
43
+ * **Language(s)**: Japanese English
44
+ * **Library**: [Megatron-LM](https://github.com/rioyokotalab/Megatron-Llama2)
45
+ * **Tokenizer**: This model employs a tokenizer that features a broadened vocabulary based on Japanese data. This allows for a more efficient representation of text using fewer tokens, leading to a notably faster inference process.
46
+ * **Contact**: swallow[at]nlp.c.titech.ac.jp
47
+
48
+ ## Base Model Performance
49
+
50
+ ### Japanese version
51
+
52
+ |Model|Size|JCommonsenseQA|JEMHopQA|NIILC|JSQuAD|XL-Sum|MGSM|WMT20-en-ja|WMT20-ja-en|
53
+ |---|---|---|---|---|---|---|---|---|---|
54
+ | | |4-shot|4-shot|4-shot|4-shot|1-shot|4-shot|4-shot|4-shot|
55
+ | Llama 2 | 7B | 0.3852 | 0.4240 | 0.3410 | 0.7917 | 0.1905 | 0.0760 | 0.1783 | 0.1738 |
56
+ | Swallow | 7B | 0.4808 | 0.5078 | 0.5968 | 0.8573 | 0.1830 | 0.1240 | 0.2510 | 0.1511 |
57
+ | Swallow-Plus | 7B | 0.5478 | 0.5493 | 0.6030 | 0.8544 | 0.1806 | 0.1360 | 0.2568 | 0.1441 |
58
+ | Swallow-NVE | 7B | 0.5433 | 0.5425 | 0.5729 | 0.8684 | 0.2117 | 0.1200 | 0.2405 | 0.1512 |
59
+ | Llama 2 | 13B | 0.6997 | 0.4415 | 0.4170 | 0.8533 | 0.2139 | 0.1320 | 0.2146 | 0.1982 |
60
+ | Swallow | 13B | 0.7837 | 0.5063 | 0.6398 | 0.9005 | 0.2168 | 0.2040 | 0.2720 | 0.1771 |
61
+ | Swallow-NVE | 13B | 0.7712 | 0.5438 | 0.6351 | 0.9030 | 0.2294 | 0.2120 | 0.2735 | 0.1817 |
62
+ | Llama 2 | 70B | 0.8686 | 0.4656 | 0.5256 | 0.9080 | 0.2361 | 0.3560 | 0.2643 | **0.2398** |
63
+ | Swallow | 70B | 0.9348 | **0.6290** | 0.6960 | 0.9176 | 0.2266 | **0.4840** | **0.3043** | 0.2298 |
64
+ | Swallow-NVE | 70B | **0.9410** | 0.5759 | **0.7024** | **0.9254** | **0.2758** | 0.4720 | 0.3042 | 0.2322 |
65
+ ### English version
66
+
67
+ |Model|Size|OpenBookQA|TriviaQA|HellaSwag|SQuAD2.0|XWINO|GSM8K|
68
+ |---|---|---|---|---|---|---|---|
69
+ | | |8-shot|8-shot|8-shot|8-shot|8-shot|8-shot|
70
+ | Llama 2 | 7B | 0.3580 | 0.6265 | 0.5860 | 0.3207 | 0.9049 | 0.1410 |
71
+ | Swallow | 7B | 0.3180 | 0.4836 | 0.5308 | 0.3125 | 0.8817 | 0.1130 |
72
+ | Swallow-Plus | 7B | 0.3280 | 0.4558 | 0.5259 | 0.3134 | 0.8929 | 0.1061 |
73
+ | Swallow-NVE | 7B | 0.3180 | 0.5079 | 0.5329 | 0.2919 | 0.8817 | 0.0986 |
74
+ | Llama 2 | 13B | 0.3760 | 0.7255 | 0.6148 | 0.3681 | 0.9140 | 0.2403 |
75
+ | Swallow | 13B | 0.3500 | 0.5852 | 0.5660 | 0.3406 | 0.9075 | 0.2039 |
76
+ | Swallow-NVE | 13B | 0.3460 | 0.6025 | 0.5700 | 0.3478 | 0.9006 | 0.1751 |
77
+ | Llama 2 | 70B | **0.4280** | **0.8239** | **0.6742** | **0.3770** | **0.9290** | **0.5284** |
78
+ | Swallow | 70B | 0.4220 | 0.7756 | 0.6458 | 0.3745 | 0.9204 | 0.4867 |
79
+ | Swallow-NVE | 70B | 0.4240 | 0.7817 | 0.6439 | 0.3451 | 0.9256 | 0.4943 |
80
+
81
+ ## Usage
82
+
83
+ First install additional dependencies in [requirements.txt](./requirements.txt):
84
+
85
+ ```sh
86
+ pip install -r requirements.txt
87
+ ```
88
+
89
+ ### Use the instruct model
90
+
91
+ ```python
92
+ import torch
93
+ from transformers import AutoTokenizer, AutoModelForCausalLM
94
+
95
+ model_name = "tokyotech-llm/Swallow-7b-instruct-hf"
96
+
97
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
98
+ model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.bfloat16, low_cpu_mem_usage=True, device_map="auto")
99
+
100
+
101
+ PROMPT_DICT = {
102
+ "prompt_input": (
103
+ "以下に、あるタスクを説明する指示があり、それに付随する入力が更なる文脈を提供しています。"
104
+ "リクエストを適切に完了するための回答を記述してください。\n\n"
105
+ "### 指示:\n{instruction}\n\n### 入力:\n{input}\n\n### 応答:"
106
+
107
+ ),
108
+ "prompt_no_input": (
109
+ "以下に、あるタスクを説明する指示があります。"
110
+ "リクエストを適切に完了するための回答を記述してください。\n\n"
111
+ "### 指示:\n{instruction}\n\n### 応答:"
112
+ ),
113
+ }
114
+
115
+ def create_prompt(instruction, input=None):
116
+ """
117
+ Generates a prompt based on the given instruction and an optional input.
118
+ If input is provided, it uses the 'prompt_input' template from PROMPT_DICT.
119
+ If no input is provided, it uses the 'prompt_no_input' template.
120
+
121
+ Args:
122
+ instruction (str): The instruction describing the task.
123
+ input (str, optional): Additional input providing context for the task. Default is None.
124
+
125
+ Returns:
126
+ str: The generated prompt.
127
+ """
128
+ if input:
129
+ # Use the 'prompt_input' template when additional input is provided
130
+ return PROMPT_DICT["prompt_input"].format(instruction=instruction, input=input)
131
+ else:
132
+ # Use the 'prompt_no_input' template when no additional input is provided
133
+ return PROMPT_DICT["prompt_no_input"].format(instruction=instruction)
134
+
135
+ # Example usage
136
+ instruction_example = "以下のトピックに関する詳細な情報を提供してください。"
137
+ input_example = "東京工業大学の主なキャンパスについて教えてください"
138
+ prompt = create_prompt(instruction_example, input_example)
139
+
140
+ input_ids = tokenizer.encode(
141
+ prompt,
142
+ add_special_tokens=False,
143
+ return_tensors="pt"
144
+ )
145
+
146
+ tokens = model.generate(
147
+ input_ids.to(device=model.device),
148
+ max_new_tokens=128,
149
+ temperature=0.99,
150
+ top_p=0.95,
151
+ do_sample=True,
152
+ )
153
+
154
+ out = tokenizer.decode(tokens[0], skip_special_tokens=True)
155
+ print(out)
156
+
157
+ ```
158
+
159
+ ### Use the base model
160
+
161
+ ```python
162
+ import torch
163
+ from transformers import AutoTokenizer, AutoModelForCausalLM
164
+
165
+ model_name = "tokyotech-llm/Swallow-7b-hf"
166
+
167
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
168
+ model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.bfloat16, device_map="auto")
169
+
170
+ prompt = "東京工業大学の主なキャンパスは、"
171
+ input_ids = tokenizer.encode(
172
+ prompt,
173
+ add_special_tokens=False,
174
+ return_tensors="pt"
175
+ )
176
+ tokens = model.generate(
177
+ input_ids.to(device=model.device),
178
+ max_new_tokens=128,
179
+ temperature=0.99,
180
+ top_p=0.95,
181
+ do_sample=True,
182
+ )
183
+
184
+ out = tokenizer.decode(tokens[0], skip_special_tokens=True)
185
+ print(out)
186
+ ```
187
+
188
+ ## Training Datasets
189
+
190
+ ### Continual Pre-Training
191
+ The following datasets were used for continual pre-training.
192
+
193
+ - [Japanese Wikipedia](https://dumps.wikimedia.org/other/cirrussearch)
194
+ - [RefinedWeb](https://huggingface.co/datasets/tiiuae/falcon-refinedweb)
195
+ - Swallow Corpus
196
+ - [The Pile](https://huggingface.co/datasets/EleutherAI/pile)
197
+
198
+
199
+ ### Instruction Tuning
200
+
201
+ The following datasets were used for the instruction tuning.
202
+
203
+ - [Anthropic HH-RLHF](https://huggingface.co/datasets/kunishou/hh-rlhf-49k-ja)
204
+ - [Databricks Dolly 15-k](https://huggingface.co/datasets/kunishou/databricks-dolly-15k-ja)
205
+ - [OpenAssistant Conversations Dataset](https://huggingface.co/datasets/kunishou/oasst1-89k-ja)
206
+
207
+ ## Risks and Limitations
208
+
209
+ The models released here are still in the early stages of our research and development and have not been tuned to ensure outputs align with human intent and safety considerations.
210
+
211
+ ## Acknowledgements
212
+
213
+ We thank Meta Research for releasing Llama 2 under an open license for others to build on.
214
+
215
+ Our project is supported by the [ABCI Large-scale Language Model Building Support Program](https://abci.ai/en/link/llm_support_program.html) of the National Institute of Advanced Industrial Science and Technology.
216
+
217
+ ## License
218
+
219
+ Llama 2 is licensed under the LLAMA 2 Community License, Copyright © Meta Platforms, Inc. All Rights Reserved.
220
+
221
+ ## Authors
222
+
223
+ Here are the team members:
224
+ - From [Okazaki Laboratory](https://www.nlp.c.titech.ac.jp/index.en.html), the following members:
225
+ - [Naoaki Okazaki](https://www.chokkan.org/index.ja.html)
226
+ - [Sakae Mizuki](https://s-mizuki-nlp.github.io/)
227
+ - [Hiroki Iida](https://meshidenn.github.io/)
228
+ - [Mengsay Loem](https://loem-ms.github.io/)
229
+ - [Shota Hirai](https://huggingface.co/Kotemo428)
230
+ - [Kakeru Hattori](https://aya-se.vercel.app/)
231
+ - [Masanari Ohi](https://twitter.com/stjohn2007)
232
+ - From [YOKOTA Laboratory](https://www.rio.gsic.titech.ac.jp/en/index.html), the following members:
233
+ - [Rio Yokota](https://twitter.com/rioyokota)
234
+ - [Kazuki Fujii](https://twitter.com/okoge_kaz)
235
+ - [Taishi Nakamura](https://twitter.com/Setuna7777_2)