RichardErkhov commited on
Commit
ade7041
·
verified ·
1 Parent(s): e62eaad

uploaded readme

Browse files
Files changed (1) hide show
  1. README.md +297 -0
README.md ADDED
@@ -0,0 +1,297 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ Swallow-7b-instruct-hf - bnb 4bits
11
+ - Model creator: https://huggingface.co/tokyotech-llm/
12
+ - Original model: https://huggingface.co/tokyotech-llm/Swallow-7b-instruct-hf/
13
+
14
+
15
+
16
+
17
+ Original model description:
18
+ ---
19
+ language:
20
+ - en
21
+ - ja
22
+ library_name: transformers
23
+ pipeline_tag: text-generation
24
+ license: llama2
25
+ model_type: llama
26
+ ---
27
+
28
+ # Swallow
29
+
30
+ Our Swallow model has undergone continual pre-training from the [Llama 2 family](https://huggingface.co/meta-llama), primarily with the addition of Japanese language data. The tuned versions use supervised fine-tuning (SFT).
31
+ Links to other models can be found in the index.
32
+
33
+ # Model Release Updates
34
+
35
+ We are excited to share the release schedule for our latest models:
36
+ - **April 26, 2024**: Released version 0.1 of our enhanced instruction-tuned models: [Swallow-7b-instruct-v0.1](https://huggingface.co/tokyotech-llm/Swallow-7b-instruct-v0.1), [Swallow-13b-instruct-v0.1](https://huggingface.co/tokyotech-llm/Swallow-13b-instruct-v0.1), and [Swallow-70b-instruct-v0.1](https://huggingface.co/tokyotech-llm/Swallow-70b-instruct-v0.1) as preview versions.
37
+ - **March 2, 2024**: Released the [Swallow-7b-plus-hf](https://huggingface.co/tokyotech-llm/Swallow-7b-plus-hf), a model trained with approximately twice as many Japanese tokens as [Swallow-7b-hf](https://huggingface.co/tokyotech-llm/Swallow-7b-hf).
38
+ - **February 4, 2024**: Released the [Swallow-13b-NVE-hf](https://huggingface.co/tokyotech-llm/Swallow-13b-NVE-hf).
39
+ - **January 26, 2024**: Released the [Swallow-7b-NVE-hf](https://huggingface.co/tokyotech-llm/Swallow-7b-NVE-hf), [Swallow-7b-NVE-instruct-hf](https://huggingface.co/tokyotech-llm/Swallow-7b-NVE-instruct-hf), [Swallow-70b-NVE-hf](https://huggingface.co/tokyotech-llm/Swallow-70b-NVE-hf), and [Swallow-70b-NVE-instruct-hf](https://huggingface.co/tokyotech-llm/Swallow-70b-NVE-instruct-hf)
40
+ - **December 19, 2024**: Released the [Swallow-7b-hf](https://huggingface.co/tokyotech-llm/Swallow-7b-hf), [Swallow-7b-instruct-hf](https://huggingface.co/tokyotech-llm/Swallow-7b-instruct-hf), [Swallow-13b-hf](https://huggingface.co/tokyotech-llm/Swallow-13b-hf), [Swallow-13b-instruct-hf](https://huggingface.co/tokyotech-llm/Swallow-13b-instruct-hf), [Swallow-70b-hf](https://huggingface.co/tokyotech-llm/Swallow-70b-hf), and [Swallow-70b-instruct-hf](https://huggingface.co/tokyotech-llm/Swallow-70b-instruct-hf).
41
+
42
+ ## Swallow Model Index
43
+ |Model|Swallow-hf|Swallow-instruct-hf|Swallow-instruct-v0.1|
44
+ |---|---|---|---|
45
+ |7B| [Link](https://huggingface.co/tokyotech-llm/Swallow-7b-hf) | [Link](https://huggingface.co/tokyotech-llm/Swallow-7b-instruct-hf)|[Link](https://huggingface.co/tokyotech-llm/Swallow-7b-instruct-v1.0)|
46
+ |7B-Plus| [Link](https://huggingface.co/tokyotech-llm/Swallow-7b-plus-hf) | N/A | N/A |
47
+ |13B| [Link](https://huggingface.co/tokyotech-llm/Swallow-13b-hf) | [Link](https://huggingface.co/tokyotech-llm/Swallow-13b-instruct-hf)| [Link](https://huggingface.co/tokyotech-llm/Swallow-13b-instruct-v1.0)|
48
+ |70B| [Link](https://huggingface.co/tokyotech-llm/Swallow-70b-hf) | [Link](https://huggingface.co/tokyotech-llm/Swallow-70b-instruct-hf)| [Link](https://huggingface.co/tokyotech-llm/Swallow-70b-instruct-v1.0)|
49
+
50
+ ## Swallow Model Index NVE (No Vocabulary Expansion)
51
+ |Model|Swallow-NVE-hf|Swallow-NVE-instruct-hf|
52
+ |---|---|---|
53
+ |7B| [Link](https://huggingface.co/tokyotech-llm/Swallow-7b-NVE-hf) | [Link](https://huggingface.co/tokyotech-llm/Swallow-7b-NVE-instruct-hf)|
54
+ |13B| [Link](https://huggingface.co/tokyotech-llm/Swallow-13b-NVE-hf) | N/A |
55
+ |70B| [Link](https://huggingface.co/tokyotech-llm/Swallow-70b-NVE-hf) | [Link](https://huggingface.co/tokyotech-llm/Swallow-70b-NVE-instruct-hf)|
56
+
57
+ ![logo](./logo.png)
58
+
59
+ This repository provides large language models developed by [TokyoTech-LLM](https://tokyotech-llm.github.io/).
60
+ Read our [blog post](https://zenn.dev/tokyotech_lm/articles/d6cb3a8fdfc907) or our [paper](https://arxiv.org/abs/2404.17790)
61
+
62
+ ## Model Details
63
+
64
+ * **Model type**: Please refer to LLaMA-2 technical report for details on the model architecture.
65
+ * **Language(s)**: Japanese English
66
+ * **Library**: [Megatron-LM](https://github.com/rioyokotalab/Megatron-Llama2)
67
+ * **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.
68
+ * **Contact**: swallow[at]nlp.c.titech.ac.jp
69
+
70
+ ## Base Model Performance
71
+
72
+ ### Japanese tasks
73
+
74
+ |Model|Size|JCommonsenseQA|JEMHopQA|NIILC|JSQuAD|XL-Sum|MGSM|WMT20-en-ja|WMT20-ja-en|
75
+ |---|---|---|---|---|---|---|---|---|---|
76
+ | | |4-shot|4-shot|4-shot|4-shot|1-shot|4-shot|4-shot|4-shot|
77
+ | Llama 2 | 7B | 0.3852 | 0.4240 | 0.3410 | 0.7917 | 0.1905 | 0.0760 | 0.1783 | 0.1738 |
78
+ | Swallow | 7B | 0.4808 | 0.5078 | 0.5968 | 0.8573 | 0.1830 | 0.1240 | 0.2510 | 0.1511 |
79
+ | Swallow-Plus | 7B | 0.5478 | 0.5493 | 0.6030 | 0.8544 | 0.1806 | 0.1360 | 0.2568 | 0.1441 |
80
+ | Swallow-NVE | 7B | 0.5433 | 0.5425 | 0.5729 | 0.8684 | 0.2117 | 0.1200 | 0.2405 | 0.1512 |
81
+ | Llama 2 | 13B | 0.6997 | 0.4415 | 0.4170 | 0.8533 | 0.2139 | 0.1320 | 0.2146 | 0.1982 |
82
+ | Swallow | 13B | 0.7837 | 0.5063 | 0.6398 | 0.9005 | 0.2168 | 0.2040 | 0.2720 | 0.1771 |
83
+ | Swallow-NVE | 13B | 0.7712 | 0.5438 | 0.6351 | 0.9030 | 0.2294 | 0.2120 | 0.2735 | 0.1817 |
84
+ | Llama 2 | 70B | 0.8686 | 0.4656 | 0.5256 | 0.9080 | 0.2361 | 0.3560 | 0.2643 | **0.2398** |
85
+ | Swallow | 70B | 0.9348 | **0.6290** | 0.6960 | 0.9176 | 0.2266 | **0.4840** | **0.3043** | 0.2298 |
86
+ | Swallow-NVE | 70B | **0.9410** | 0.5759 | **0.7024** | **0.9254** | **0.2758** | 0.4720 | 0.3042 | 0.2322 |
87
+ ### English tasks
88
+
89
+ |Model|Size|OpenBookQA|TriviaQA|HellaSwag|SQuAD2.0|XWINO|GSM8K|
90
+ |---|---|---|---|---|---|---|---|
91
+ | | |8-shot|8-shot|8-shot|8-shot|8-shot|8-shot|
92
+ | Llama 2 | 7B | 0.3580 | 0.6265 | 0.5860 | 0.3207 | 0.9049 | 0.1410 |
93
+ | Swallow | 7B | 0.3180 | 0.4836 | 0.5308 | 0.3125 | 0.8817 | 0.1130 |
94
+ | Swallow-Plus | 7B | 0.3280 | 0.4558 | 0.5259 | 0.3134 | 0.8929 | 0.1061 |
95
+ | Swallow-NVE | 7B | 0.3180 | 0.5079 | 0.5329 | 0.2919 | 0.8817 | 0.0986 |
96
+ | Llama 2 | 13B | 0.3760 | 0.7255 | 0.6148 | 0.3681 | 0.9140 | 0.2403 |
97
+ | Swallow | 13B | 0.3500 | 0.5852 | 0.5660 | 0.3406 | 0.9075 | 0.2039 |
98
+ | Swallow-NVE | 13B | 0.3460 | 0.6025 | 0.5700 | 0.3478 | 0.9006 | 0.1751 |
99
+ | Llama 2 | 70B | **0.4280** | **0.8239** | **0.6742** | **0.3770** | **0.9290** | **0.5284** |
100
+ | Swallow | 70B | 0.4220 | 0.7756 | 0.6458 | 0.3745 | 0.9204 | 0.4867 |
101
+ | Swallow-NVE | 70B | 0.4240 | 0.7817 | 0.6439 | 0.3451 | 0.9256 | 0.4943 |
102
+
103
+ ## Evaluation Benchmarks
104
+
105
+ ### Japanese evaluation benchmarks
106
+
107
+ We used llm-jp-eval(v1.0.0) and JP Language Model Evaluation Harness(commit #9b42d41). The details are as follows:
108
+
109
+ - Multiple-choice question answering (JCommonsenseQA [Kurihara+, 2022])
110
+ - Open-ended question answering (JEMHopQA [Ishii+, 2023])
111
+ - Open-ended question answering (NIILC [Sekine, 2003])
112
+ - Machine reading comprehension (JSQuAD [Kurihara+, 2022])
113
+ - Automatic summarization (XL-Sum [Hasan+, 2021])
114
+ - Machine translation (WMT2020 ja-en [Barrault+, 2020])
115
+ - Machine translation (WMT2020 en-ja [Barrault+, 2020])
116
+ - Mathematical reasoning (MGSM [Shi+, 2023])
117
+
118
+ ### English evaluation benchmarks
119
+
120
+ We used the Language Model Evaluation Harness(v.0.3.0). The details are as follows:
121
+
122
+ - Multiple-choice question answering (OpenBookQA [Mihaylov+, 2018])
123
+ - Open-ended question answering (TriviaQA [Joshi+, 2017])
124
+ - Machine reading comprehension (SQuAD 2.0 [Rajpurkar+, 2018])
125
+ - Commonsense reasoning (XWINO [Tikhonov & Ryabinin, 2021])
126
+ - Natural language inference (HellaSwag [Zellers+, 2019])
127
+ - Mathematical reasoning (GSM8k [Cobbe+, 2021])
128
+
129
+
130
+ ## Usage
131
+
132
+ First install additional dependencies in [requirements.txt](./requirements.txt):
133
+
134
+ ```sh
135
+ pip install -r requirements.txt
136
+ ```
137
+
138
+ ### Use the instruct model
139
+
140
+ ```python
141
+ import torch
142
+ from transformers import AutoTokenizer, AutoModelForCausalLM
143
+
144
+ model_name = "tokyotech-llm/Swallow-7b-instruct-hf"
145
+
146
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
147
+ model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.bfloat16, low_cpu_mem_usage=True, device_map="auto")
148
+
149
+
150
+ PROMPT_DICT = {
151
+ "prompt_input": (
152
+ "以下に、あるタスクを説明する指示があり、それに付随する入力が更なる文脈を提供しています。"
153
+ "リクエストを適切に完了するための回答を記述してください。\n\n"
154
+ "### 指示:\n{instruction}\n\n### 入力:\n{input}\n\n### 応答:"
155
+
156
+ ),
157
+ "prompt_no_input": (
158
+ "以下に、あるタスクを説明する指示があります。"
159
+ "リクエストを適切に完了するための回答を記述してください。\n\n"
160
+ "### 指示:\n{instruction}\n\n### 応答:"
161
+ ),
162
+ }
163
+
164
+ def create_prompt(instruction, input=None):
165
+ """
166
+ Generates a prompt based on the given instruction and an optional input.
167
+ If input is provided, it uses the 'prompt_input' template from PROMPT_DICT.
168
+ If no input is provided, it uses the 'prompt_no_input' template.
169
+
170
+ Args:
171
+ instruction (str): The instruction describing the task.
172
+ input (str, optional): Additional input providing context for the task. Default is None.
173
+
174
+ Returns:
175
+ str: The generated prompt.
176
+ """
177
+ if input:
178
+ # Use the 'prompt_input' template when additional input is provided
179
+ return PROMPT_DICT["prompt_input"].format(instruction=instruction, input=input)
180
+ else:
181
+ # Use the 'prompt_no_input' template when no additional input is provided
182
+ return PROMPT_DICT["prompt_no_input"].format(instruction=instruction)
183
+
184
+ # Example usage
185
+ instruction_example = "以下のトピックに関する詳細な情報を提供してくだ���い。"
186
+ input_example = "東京工業大学の主なキャンパスについて教えてください"
187
+ prompt = create_prompt(instruction_example, input_example)
188
+
189
+ input_ids = tokenizer.encode(
190
+ prompt,
191
+ add_special_tokens=False,
192
+ return_tensors="pt"
193
+ )
194
+
195
+ tokens = model.generate(
196
+ input_ids.to(device=model.device),
197
+ max_new_tokens=128,
198
+ temperature=0.99,
199
+ top_p=0.95,
200
+ do_sample=True,
201
+ )
202
+
203
+ out = tokenizer.decode(tokens[0], skip_special_tokens=True)
204
+ print(out)
205
+
206
+ ```
207
+
208
+ ### Use the base model
209
+
210
+ ```python
211
+ import torch
212
+ from transformers import AutoTokenizer, AutoModelForCausalLM
213
+
214
+ model_name = "tokyotech-llm/Swallow-7b-hf"
215
+
216
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
217
+ model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.bfloat16, device_map="auto")
218
+
219
+ prompt = "東京工業大学の主なキャンパスは、"
220
+ input_ids = tokenizer.encode(
221
+ prompt,
222
+ add_special_tokens=False,
223
+ return_tensors="pt"
224
+ )
225
+ tokens = model.generate(
226
+ input_ids.to(device=model.device),
227
+ max_new_tokens=128,
228
+ temperature=0.99,
229
+ top_p=0.95,
230
+ do_sample=True,
231
+ )
232
+
233
+ out = tokenizer.decode(tokens[0], skip_special_tokens=True)
234
+ print(out)
235
+ ```
236
+
237
+ ## Training Datasets
238
+
239
+ ### Continual Pre-Training
240
+ The following datasets were used for continual pre-training.
241
+
242
+ - [Japanese Wikipedia](https://dumps.wikimedia.org/other/cirrussearch)
243
+ - [RefinedWeb](https://huggingface.co/datasets/tiiuae/falcon-refinedweb)
244
+ - [Swallow Corpus](https://arxiv.org/abs/2404.17733)
245
+ - [The Pile](https://huggingface.co/datasets/EleutherAI/pile)
246
+
247
+
248
+ ### Instruction Tuning
249
+
250
+ The following datasets were used for the instruction tuning.
251
+
252
+ - [Anthropic HH-RLHF](https://huggingface.co/datasets/kunishou/hh-rlhf-49k-ja)
253
+ - [Databricks Dolly 15-k](https://huggingface.co/datasets/kunishou/databricks-dolly-15k-ja)
254
+ - [OpenAssistant Conversations Dataset](https://huggingface.co/datasets/kunishou/oasst1-89k-ja)
255
+
256
+ ## Risks and Limitations
257
+
258
+ 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.
259
+
260
+ ## Acknowledgements
261
+
262
+ We thank Meta Research for releasing Llama 2 under an open license for others to build on.
263
+
264
+ 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.
265
+
266
+ ## License
267
+
268
+ Llama 2 is licensed under the LLAMA 2 Community License, Copyright © Meta Platforms, Inc. All Rights Reserved.
269
+
270
+ ## Authors
271
+
272
+ Here are the team members:
273
+ - From [Okazaki Laboratory](https://www.nlp.c.titech.ac.jp/index.en.html), the following members:
274
+ - [Naoaki Okazaki](https://www.chokkan.org/index.ja.html)
275
+ - [Sakae Mizuki](https://s-mizuki-nlp.github.io/)
276
+ - [Hiroki Iida](https://meshidenn.github.io/)
277
+ - [Mengsay Loem](https://loem-ms.github.io/)
278
+ - [Shota Hirai](https://huggingface.co/Kotemo428)
279
+ - [Kakeru Hattori](https://aya-se.vercel.app/)
280
+ - [Masanari Ohi](https://twitter.com/stjohn2007)
281
+ - From [YOKOTA Laboratory](https://www.rio.gsic.titech.ac.jp/en/index.html), the following members:
282
+ - [Rio Yokota](https://twitter.com/rioyokota)
283
+ - [Kazuki Fujii](https://twitter.com/okoge_kaz)
284
+ - [Taishi Nakamura](https://twitter.com/Setuna7777_2)
285
+
286
+ ## How to cite
287
+ ```
288
+ @misc{fujii2024continual,
289
+ title={Continual Pre-Training for Cross-Lingual LLM Adaptation: Enhancing Japanese Language Capabilities},
290
+ author={Kazuki Fujii and Taishi Nakamura and Mengsay Loem and Hiroki Iida and Masanari Ohi and Kakeru Hattori and Hirai Shota and Sakae Mizuki and Rio Yokota and Naoaki Okazaki},
291
+ year={2024},
292
+ eprint={2404.17790},
293
+ archivePrefix={arXiv},
294
+ primaryClass={cs.CL}
295
+ }
296
+ ```
297
+