KKFurudate
commited on
Update README.md
Browse files
README.md
CHANGED
@@ -17,6 +17,135 @@ language:
|
|
17 |
- **License:** apache-2.0
|
18 |
- **Finetuned from model :** llm-jp/llm-jp-3-13b
|
19 |
|
20 |
-
|
|
|
21 |
|
|
|
22 |
[<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
- **License:** apache-2.0
|
18 |
- **Finetuned from model :** llm-jp/llm-jp-3-13b
|
19 |
|
20 |
+
このモデルは日本語タスクに特化し、指示に基づく応答を行うためにファインチューニングされたLLM用アダプタです。
|
21 |
+
`llm-jp/llm-jp-3-13b`をベースモデルとして、ichikara-instructionデータやELYZA-tasks-100を用いて微調整を行っています。
|
22 |
|
23 |
+
This llama model was trained 2x faster with [Unsloth](https://github.com/unslothai/unsloth) and Huggingface's TRL library.
|
24 |
[<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth)
|
25 |
+
|
26 |
+
# Instruction Tuning
|
27 |
+
|
28 |
+
以下の日本語データセットで微調整を行いました:
|
29 |
+
|
30 |
+
| Language | Dataset | Description |
|
31 |
+
|:---|:---|:---|
|
32 |
+
| Japanese | [ichikara-instruction-003-001-1.json](https://liat-aip.sakura.ne.jp/wp/llm%E3%81%AE%E3%81%9F%E3%82%81%E3%81%AE%E6%97%A5%E6%9C%AC%E8%AA%9E%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%A9%E3%82%AF%E3%82%B7%E3%83%A7%E3%83%B3%E3%83%87%E3%83%BC%E3%82%BF-%E5%85%AC%E9%96%8B/) | 手動構築の日本語指示データセット |
|
33 |
+
| Japanese | ichikara-instruction-003-003-1.fixed.json | 手動修正・拡張データセット |
|
34 |
+
| Japanese | [elyza/ELYZA-tasks-100](https://huggingface.co/datasets/elyza/ELYZA-tasks-100) | 日本語多目的タスク用データセット |
|
35 |
+
|
36 |
+
ichikara-instruction:
|
37 |
+
関根聡, 安藤まや, 後藤美知子, 鈴木久美, 河原大輔, 井之上直也, 乾健太郎. ichikara-instruction: LLMのための日本語インストラクションデータの構築. 言語処理学会第30回年次大会(2024)
|
38 |
+
|
39 |
+
## Usage
|
40 |
+
|
41 |
+
下記コマンドで環境整備:
|
42 |
+
|
43 |
+
```bash
|
44 |
+
!pip install -U bitsandbytes
|
45 |
+
!pip install -U transformers
|
46 |
+
!pip install -U accelerate
|
47 |
+
!pip install -U datasets
|
48 |
+
```
|
49 |
+
|
50 |
+
```python
|
51 |
+
from transformers import (
|
52 |
+
AutoModelForCausalLM,
|
53 |
+
AutoTokenizer,
|
54 |
+
BitsAndBytesConfig,
|
55 |
+
)
|
56 |
+
import torch
|
57 |
+
from tqdm import tqdm
|
58 |
+
import json
|
59 |
+
import re
|
60 |
+
```
|
61 |
+
|
62 |
+
```python
|
63 |
+
HF_TOKEN = "YOUR-HF-TOKEN"
|
64 |
+
```
|
65 |
+
|
66 |
+
```python
|
67 |
+
model_name = "KKFurudate/llm-jp-3-13b-v6_lora"
|
68 |
+
```
|
69 |
+
|
70 |
+
```python
|
71 |
+
bnb_config = BitsAndBytesConfig(
|
72 |
+
load_in_4bit=True,
|
73 |
+
bnb_4bit_quant_type="nf4",
|
74 |
+
bnb_4bit_compute_dtype=torch.bfloat16,
|
75 |
+
bnb_4bit_use_double_quant=False,
|
76 |
+
)
|
77 |
+
```
|
78 |
+
|
79 |
+
```python
|
80 |
+
model = AutoModelForCausalLM.from_pretrained(
|
81 |
+
model_name,
|
82 |
+
quantization_config=bnb_config,
|
83 |
+
device_map="auto",
|
84 |
+
token=HF_TOKEN
|
85 |
+
)
|
86 |
+
|
87 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True, token=HF_TOKEN)
|
88 |
+
```
|
89 |
+
|
90 |
+
```python
|
91 |
+
datasets = []
|
92 |
+
with open("./YOUR-DATA.jsonl", "r") as f:
|
93 |
+
item = ""
|
94 |
+
for line in f:
|
95 |
+
line = line.strip()
|
96 |
+
item += line
|
97 |
+
if item.endswith("}"):
|
98 |
+
datasets.append(json.loads(item))
|
99 |
+
item = ""
|
100 |
+
|
101 |
+
results = []
|
102 |
+
for data in tqdm(datasets):
|
103 |
+
input = data["input"]
|
104 |
+
prompt = f"""### 指示
|
105 |
+
{input}
|
106 |
+
### 回答:
|
107 |
+
"""
|
108 |
+
tokenized_input = tokenizer.encode(prompt, add_special_tokens=False, return_tensors="pt").to(model.device)
|
109 |
+
with torch.no_grad():
|
110 |
+
outputs = model.generate(
|
111 |
+
tokenized_input,
|
112 |
+
max_new_tokens=512,
|
113 |
+
do_sample=False,
|
114 |
+
repetition_penalty=1.2
|
115 |
+
)[0]
|
116 |
+
output = tokenizer.decode(outputs[tokenized_input.size(1):], skip_special_tokens=True)
|
117 |
+
results.append({"task_id": data["task_id"], "input": input, "output": output})
|
118 |
+
```
|
119 |
+
|
120 |
+
```python
|
121 |
+
model_name_clean = re.sub(".*/", "", model_name)
|
122 |
+
with open(f"./{model_name_clean}-outputs.jsonl", 'w', encoding='utf-8') as f:
|
123 |
+
for result in results:
|
124 |
+
json.dump(result, f, ensure_ascii=False)
|
125 |
+
f.write('\n')
|
126 |
+
```
|
127 |
+
|
128 |
+
## License
|
129 |
+
|
130 |
+
[Apache License, Version 2.0](https://www.apache.org/licenses/LICENSE-2.0)
|
131 |
+
|
132 |
+
|
133 |
+
## Base Model
|
134 |
+
|
135 |
+
base_model:- llm-jp/llm-jp-3-13b
|
136 |
+
|
137 |
+
## Citations
|
138 |
+
|
139 |
+
@software{unsloth,
|
140 |
+
author = {Daniel Han, Michael Han and Unsloth team},
|
141 |
+
title = {Unsloth},
|
142 |
+
url = {http://github.com/unslothai/unsloth},
|
143 |
+
year = {2023}
|
144 |
+
}
|
145 |
+
|
146 |
+
@misc{elyzatasks100,
|
147 |
+
title={ELYZA-tasks-100: 日本語instructionモデル評価データセット},
|
148 |
+
url={https://huggingface.co/elyza/ELYZA-tasks-100},
|
149 |
+
author={Akira Sasaki and Masato Hirakawa and Shintaro Horie and Tomoaki Nakamura},
|
150 |
+
year={2023},
|
151 |
+
}
|