Taishi-N324 commited on
Commit
3544cc5
1 Parent(s): 7a303ca

Upload README.md

Browse files
Files changed (1) hide show
  1. README.md +216 -0
README.md ADDED
@@ -0,0 +1,216 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ |13B| [Link](https://huggingface.co/tokyotech-llm/Swallow-13b-hf) | [Link](https://huggingface.co/tokyotech-llm/Swallow-13b-instruct-hf)|
21
+ |70B| [Link](https://huggingface.co/tokyotech-llm/Swallow-70b-hf) | [Link](https://huggingface.co/tokyotech-llm/Swallow-70b-instruct-hf)|
22
+
23
+ ## Swallow Model Index NVE (No Vocabulary Expansion)
24
+ |Model|Swallow-NVE-hf|Swallow-NVE-instruct-hf|
25
+ |---|---|---|
26
+ |7B| [Link](https://huggingface.co/tokyotech-llm/Swallow-7b-NVE-hf) | [Link](https://huggingface.co/tokyotech-llm/Swallow-7b-NVE-instruct-hf)|
27
+ |13B| Coming Soon | Coming Soon |
28
+ |70B| [Link](https://huggingface.co/tokyotech-llm/Swallow-70b-NVE-hf) | [Link](https://huggingface.co/tokyotech-llm/Swallow-70b-NVE-instruct-hf)|
29
+
30
+ We released the 7B and 70B models without vocabulary expansion on January 26th, 2024.
31
+ The 13B model will be released soon.
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
+ |Llama 2|13B|0.6997|0.4415|0.4170|0.8533|0.2139|0.1320|0.2146|0.1982|
58
+ |Swallow|13B|0.7837|0.5063|0.6398|0.9005|0.2168|0.2040|0.2720|0.1771|
59
+ |Llama 2|70B|0.8686|0.4656|0.5256|0.9080|**0.2361**|0.3560|0.2643|**0.2398**|
60
+ |Swallow|70B|**0.9348**|**0.6290**|**0.6960**|**0.9176**|0.2266|**0.4840**|**0.3043**|0.2298|
61
+
62
+ ## Usage
63
+
64
+ First install additional dependencies in [requirements.txt](./requirements.txt):
65
+
66
+ ```sh
67
+ pip install -r requirements.txt
68
+ ```
69
+
70
+ ### Use the instruct model
71
+
72
+ ```python
73
+ import torch
74
+ from transformers import AutoTokenizer, AutoModelForCausalLM
75
+
76
+ model_name = "tokyotech-llm/Swallow-7b-instruct-hf"
77
+
78
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
79
+ model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.bfloat16, low_cpu_mem_usage=True, device_map="auto")
80
+
81
+
82
+ PROMPT_DICT = {
83
+ "prompt_input": (
84
+ "以下に、あるタスクを説明する指示があり、それに付随する入力が更なる文脈を提供しています。"
85
+ "リクエストを適切に完了するための回答を記述してください。\n\n"
86
+ "### 指示:\n{instruction}\n\n### 入力:\n{input}\n\n### 応答:"
87
+
88
+ ),
89
+ "prompt_no_input": (
90
+ "以下に、あるタスクを説明する指示があります。"
91
+ "リクエストを適切に完了するための回答を記述してください。\n\n"
92
+ "### 指示:\n{instruction}\n\n### 応答:"
93
+ ),
94
+ }
95
+
96
+ def create_prompt(instruction, input=None):
97
+ """
98
+ Generates a prompt based on the given instruction and an optional input.
99
+ If input is provided, it uses the 'prompt_input' template from PROMPT_DICT.
100
+ If no input is provided, it uses the 'prompt_no_input' template.
101
+
102
+ Args:
103
+ instruction (str): The instruction describing the task.
104
+ input (str, optional): Additional input providing context for the task. Default is None.
105
+
106
+ Returns:
107
+ str: The generated prompt.
108
+ """
109
+ if input:
110
+ # Use the 'prompt_input' template when additional input is provided
111
+ return PROMPT_DICT["prompt_input"].format(instruction=instruction, input=input)
112
+ else:
113
+ # Use the 'prompt_no_input' template when no additional input is provided
114
+ return PROMPT_DICT["prompt_no_input"].format(instruction=instruction)
115
+
116
+ # Example usage
117
+ instruction_example = "以下のトピックに関する詳細な情報を提供してください。"
118
+ input_example = "東京工業大学の主なキャンパスについて教えてください"
119
+ prompt = create_prompt(instruction_example, input_example)
120
+
121
+ input_ids = tokenizer.encode(
122
+ prompt,
123
+ add_special_tokens=False,
124
+ return_tensors="pt"
125
+ )
126
+
127
+ tokens = model.generate(
128
+ input_ids.to(device=model.device),
129
+ max_new_tokens=128,
130
+ temperature=0.99,
131
+ top_p=0.95,
132
+ do_sample=True,
133
+ )
134
+
135
+ out = tokenizer.decode(tokens[0], skip_special_tokens=True)
136
+ print(out)
137
+
138
+ ```
139
+
140
+ ### Use the base model
141
+
142
+ ```python
143
+ import torch
144
+ from transformers import AutoTokenizer, AutoModelForCausalLM
145
+
146
+ model_name = "tokyotech-llm/Swallow-7b-hf"
147
+
148
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
149
+ model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.bfloat16, device_map="auto")
150
+
151
+ prompt = "東京工業大学の主なキャンパスは、"
152
+ input_ids = tokenizer.encode(
153
+ prompt,
154
+ add_special_tokens=False,
155
+ return_tensors="pt"
156
+ )
157
+ tokens = model.generate(
158
+ input_ids.to(device=model.device),
159
+ max_new_tokens=128,
160
+ temperature=0.99,
161
+ top_p=0.95,
162
+ do_sample=True,
163
+ )
164
+
165
+ out = tokenizer.decode(tokens[0], skip_special_tokens=True)
166
+ print(out)
167
+ ```
168
+
169
+ ## Training Datasets
170
+
171
+ ### Continual Pre-Training
172
+ The following datasets were used for continual pre-training.
173
+
174
+ - [Japanese Wikipedia](https://dumps.wikimedia.org/other/cirrussearch)
175
+ - [RefinedWeb](https://huggingface.co/datasets/tiiuae/falcon-refinedweb)
176
+ - Swallow Corpus
177
+ - [The Pile](https://huggingface.co/datasets/EleutherAI/pile)
178
+
179
+
180
+ ### Instruction Tuning
181
+
182
+ The following datasets were used for the instruction tuning.
183
+
184
+ - [Anthropic HH-RLHF](https://huggingface.co/datasets/kunishou/hh-rlhf-49k-ja)
185
+ - [Databricks Dolly 15-k](https://huggingface.co/datasets/kunishou/databricks-dolly-15k-ja)
186
+ - [OpenAssistant Conversations Dataset](https://huggingface.co/datasets/kunishou/oasst1-89k-ja)
187
+
188
+ ## Risks and Limitations
189
+
190
+ 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.
191
+
192
+ ## Acknowledgements
193
+
194
+ We thank Meta Research for releasing Llama 2 under an open license for others to build on.
195
+
196
+ 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.
197
+
198
+ ## License
199
+
200
+ Llama 2 is licensed under the LLAMA 2 Community License, Copyright © Meta Platforms, Inc. All Rights Reserved.
201
+
202
+ ## Authors
203
+
204
+ Here are the team members:
205
+ - From [Okazaki Laboratory](https://www.nlp.c.titech.ac.jp/index.en.html), the following members:
206
+ - [Naoaki Okazaki](https://www.chokkan.org/index.ja.html)
207
+ - [Sakae Mizuki](https://s-mizuki-nlp.github.io/)
208
+ - [Hiroki Iida](https://meshidenn.github.io/)
209
+ - [Mengsay Loem](https://loem-ms.github.io/)
210
+ - [Shota Hirai](https://huggingface.co/Kotemo428)
211
+ - [Kakeru Hattori](https://aya-se.vercel.app/)
212
+ - [Masanari Ohi](https://twitter.com/stjohn2007)
213
+ - From [YOKOTA Laboratory](https://www.rio.gsic.titech.ac.jp/en/index.html), the following members:
214
+ - [Rio Yokota](https://twitter.com/rioyokota)
215
+ - [Kazuki Fujii](https://twitter.com/okoge_kaz)
216
+ - [Taishi Nakamura](https://twitter.com/Setuna7777_2)