Taishi-N324 commited on
Commit
4c6d2fd
1 Parent(s): 6905393

Upload README.md

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