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