KKFurudate
commited on
Commit
•
17ecdb6
1
Parent(s):
8844bbf
Update README.md
Browse files
README.md
CHANGED
@@ -8,7 +8,9 @@ tags:
|
|
8 |
- trl
|
9 |
license: apache-2.0
|
10 |
language:
|
11 |
-
-
|
|
|
|
|
12 |
---
|
13 |
|
14 |
# Uploaded model
|
@@ -18,7 +20,7 @@ language:
|
|
18 |
- **Finetuned from model :** llm-jp/llm-jp-3-13b
|
19 |
|
20 |
このモデルは日本語タスクに特化し、指示に基づく応答を行うためにファインチューニングされたLLM用アダプタです。
|
21 |
-
`llm-jp/llm-jp-3-13b`をベースモデルとして、ichikara-instruction
|
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)
|
@@ -30,32 +32,26 @@ This llama model was trained 2x faster with [Unsloth](https://github.com/unsloth
|
|
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 |
-
```
|
44 |
-
!pip install -U
|
45 |
-
!pip install -
|
46 |
-
!pip install -U
|
47 |
-
!pip install -U
|
48 |
```
|
49 |
|
50 |
```python
|
51 |
-
from
|
52 |
-
|
53 |
-
AutoTokenizer,
|
54 |
-
BitsAndBytesConfig,
|
55 |
-
)
|
56 |
import torch
|
57 |
-
from tqdm import tqdm
|
58 |
import json
|
|
|
59 |
import re
|
60 |
```
|
61 |
|
@@ -63,28 +59,28 @@ import re
|
|
63 |
HF_TOKEN = "YOUR-HF-TOKEN"
|
64 |
```
|
65 |
|
|
|
66 |
```python
|
67 |
-
|
|
|
68 |
```
|
69 |
|
70 |
```python
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
|
|
|
|
|
|
|
|
76 |
)
|
77 |
```
|
78 |
|
|
|
79 |
```python
|
80 |
-
model =
|
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
|
@@ -97,29 +93,30 @@ with open("./YOUR-DATA.jsonl", "r") as f:
|
|
97 |
if item.endswith("}"):
|
98 |
datasets.append(json.loads(item))
|
99 |
item = ""
|
|
|
|
|
|
|
|
|
|
|
100 |
|
101 |
results = []
|
102 |
-
for
|
103 |
-
|
104 |
-
|
105 |
-
{input}
|
106 |
-
|
107 |
-
""
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
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 |
-
|
122 |
-
with open(f"
|
123 |
for result in results:
|
124 |
json.dump(result, f, ensure_ascii=False)
|
125 |
f.write('\n')
|
@@ -143,6 +140,13 @@ base_model:- llm-jp/llm-jp-3-13b
|
|
143 |
year = {2023}
|
144 |
}
|
145 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
146 |
@misc{elyzatasks100,
|
147 |
title={ELYZA-tasks-100: 日本語instructionモデル評価データセット},
|
148 |
url={https://huggingface.co/elyza/ELYZA-tasks-100},
|
|
|
8 |
- trl
|
9 |
license: apache-2.0
|
10 |
language:
|
11 |
+
- ja
|
12 |
+
datasets:
|
13 |
+
- elyza/ELYZA-tasks-100
|
14 |
---
|
15 |
|
16 |
# Uploaded model
|
|
|
20 |
- **Finetuned from model :** llm-jp/llm-jp-3-13b
|
21 |
|
22 |
このモデルは日本語タスクに特化し、指示に基づく応答を行うためにファインチューニングされたLLM用アダプタです。
|
23 |
+
`llm-jp/llm-jp-3-13b`をベースモデルとして、ichikara-instructionデータとELYZA-tasks-100を用いて微調整を行っています。
|
24 |
|
25 |
This llama model was trained 2x faster with [Unsloth](https://github.com/unslothai/unsloth) and Huggingface's TRL library.
|
26 |
[<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth)
|
|
|
32 |
| Language | Dataset | Description |
|
33 |
|:---|:---|:---|
|
34 |
| 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/) | 手動構築の日本語指示データセット |
|
35 |
+
| Japanese | ichikara-instruction-003-003-1.fixed.json | ichikara-instruction-003-003-1.jsonの無効なエスケープシーケンスを手動修正したデータセット |
|
36 |
| Japanese | [elyza/ELYZA-tasks-100](https://huggingface.co/datasets/elyza/ELYZA-tasks-100) | 日本語多目的タスク用データセット |
|
37 |
|
|
|
|
|
|
|
38 |
## Usage
|
39 |
|
40 |
+
下記コマンドで環境整備(本コードはGoogle Colabでの動作を想定しています):
|
41 |
|
42 |
+
```python
|
43 |
+
!pip install -U unsloth
|
44 |
+
!pip uninstall unsloth -y && pip install --upgrade --no-cache-dir "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"
|
45 |
+
!pip install -U torch
|
46 |
+
!pip install -U peft
|
47 |
```
|
48 |
|
49 |
```python
|
50 |
+
from unsloth import FastLanguageModel
|
51 |
+
from peft import PeftModel
|
|
|
|
|
|
|
52 |
import torch
|
|
|
53 |
import json
|
54 |
+
from tqdm import tqdm
|
55 |
import re
|
56 |
```
|
57 |
|
|
|
59 |
HF_TOKEN = "YOUR-HF-TOKEN"
|
60 |
```
|
61 |
|
62 |
+
ベースのモデルと学習済みLoRAのアダプタ(Hugging FaceのIDを指定)。
|
63 |
```python
|
64 |
+
model_id = "llm-jp/llm-jp-3-13b"
|
65 |
+
adapter_id = "KKFurudate/llm-jp-3-13b-v6_lora"
|
66 |
```
|
67 |
|
68 |
```python
|
69 |
+
# unslothのFastLanguageModelで元のモデルをロード。
|
70 |
+
dtype = None
|
71 |
+
load_in_4bit = True
|
72 |
+
|
73 |
+
model, tokenizer = FastLanguageModel.from_pretrained(
|
74 |
+
model_name=model_id,
|
75 |
+
dtype=dtype,
|
76 |
+
load_in_4bit=load_in_4bit,
|
77 |
+
trust_remote_code=True,
|
78 |
)
|
79 |
```
|
80 |
|
81 |
+
ベースのモデルに学習済みLoRAのアダプタを統合。
|
82 |
```python
|
83 |
+
model = PeftModel.from_pretrained(model, adapter_id, token = HF_TOKEN)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
84 |
```
|
85 |
|
86 |
```python
|
|
|
93 |
if item.endswith("}"):
|
94 |
datasets.append(json.loads(item))
|
95 |
item = ""
|
96 |
+
```
|
97 |
+
|
98 |
+
モデルを用いてタスクの推論。
|
99 |
+
```python
|
100 |
+
FastLanguageModel.for_inference(model)
|
101 |
|
102 |
results = []
|
103 |
+
for dt in tqdm(datasets):
|
104 |
+
input = dt["input"]
|
105 |
+
|
106 |
+
prompt = f"""### 指示\n{input}\n### 回答\n"""
|
107 |
+
|
108 |
+
inputs = tokenizer([prompt], return_tensors = "pt").to(model.device)
|
109 |
+
|
110 |
+
outputs = model.generate(**inputs, max_new_tokens = 512, use_cache = True, do_sample=False, repetition_penalty=1.2)
|
111 |
+
prediction = tokenizer.decode(outputs[0], skip_special_tokens=True).split('\n### 回答')[-1]
|
112 |
+
|
113 |
+
results.append({"task_id": dt["task_id"], "input": input, "output": prediction})
|
|
|
|
|
|
|
|
|
|
|
114 |
```
|
115 |
|
116 |
+
結果をjsonlで保存。
|
117 |
```python
|
118 |
+
json_file_id = re.sub(".*/", "", adapter_id)
|
119 |
+
with open(f"{outdir}/{json_file_id}_output.jsonl", 'w', encoding='utf-8') as f:
|
120 |
for result in results:
|
121 |
json.dump(result, f, ensure_ascii=False)
|
122 |
f.write('\n')
|
|
|
140 |
year = {2023}
|
141 |
}
|
142 |
|
143 |
+
@misc{ichikara-instruction,
|
144 |
+
title={ichikara-instruction:LLMのための日本語インストラクションデータの構築. 言語処理学会第30回年次大会(2024)}
|
145 |
+
url={https://liat-aip.sakura.ne.jp/wp/llmのための日本語インストラクションデータ作成/llmのための日本語インストラクションデータ-公開/}
|
146 |
+
author={関根聡, 安藤まや, 後藤美知子, 鈴木久美, 河原大輔, 井之上直也, 乾健太郎},
|
147 |
+
year={2024},
|
148 |
+
}
|
149 |
+
|
150 |
@misc{elyzatasks100,
|
151 |
title={ELYZA-tasks-100: 日本語instructionモデル評価データセット},
|
152 |
url={https://huggingface.co/elyza/ELYZA-tasks-100},
|