Update README.md
Browse files
README.md
CHANGED
@@ -20,3 +20,60 @@ language:
|
|
20 |
This llama model was trained 2x faster with [Unsloth](https://github.com/unslothai/unsloth) and Huggingface's TRL library.
|
21 |
|
22 |
[<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
This llama model was trained 2x faster with [Unsloth](https://github.com/unslothai/unsloth) and Huggingface's TRL library.
|
21 |
|
22 |
[<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth)
|
23 |
+
|
24 |
+
# Instruction tuning
|
25 |
+
|
26 |
+
The models have been fine-tuned using the following datasets.
|
27 |
+
|
28 |
+
| Language | Dataset | description |
|
29 |
+
|:---|:---|:---|
|
30 |
+
|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%E4%BD%9C%E6%88%90/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/)| A manually constructed instruction dataset |
|
31 |
+
|
32 |
+
データセット作成チーム:
|
33 |
+
関根聡, 安藤まや, 後藤美知子, 鈴木久美, 河原大輔, 井之上直也, 乾健太郎. ichikara-instruction: LLMのための日本語インストラクションデータの構築. 言語処理学会第30回年次大会(2024)
|
34 |
+
|
35 |
+
# Usage
|
36 |
+
```python
|
37 |
+
from unsloth import FastLanguageModel
|
38 |
+
import torch
|
39 |
+
import json
|
40 |
+
from tqdm import tqdm
|
41 |
+
# config
|
42 |
+
max_seq_length = 2048
|
43 |
+
dtype = None
|
44 |
+
load_in_4bit = True
|
45 |
+
model_name = "https://huggingface.co/kaitoto/llm-jp-3-13b-finetune-2"
|
46 |
+
# モデルの読み込み
|
47 |
+
model, tokenizer = FastLanguageModel.from_pretrained(
|
48 |
+
model_name = model_name,
|
49 |
+
max_seq_length = max_seq_length,
|
50 |
+
dtype = dtype,
|
51 |
+
load_in_4bit = load_in_4bit,
|
52 |
+
token = "HF token",
|
53 |
+
)
|
54 |
+
FastLanguageModel.for_inference(model)
|
55 |
+
# データセットの読み込み。
|
56 |
+
datasets = []
|
57 |
+
with open("./elyza-tasks-100-TV_0.jsonl", "r") as f:
|
58 |
+
item = ""
|
59 |
+
for line in f:
|
60 |
+
line = line.strip()
|
61 |
+
item += line
|
62 |
+
if item.endswith("}"):
|
63 |
+
datasets.append(json.loads(item))
|
64 |
+
item = ""
|
65 |
+
# 推論
|
66 |
+
results = []
|
67 |
+
for dt in tqdm(data):
|
68 |
+
input = dt["input"]
|
69 |
+
prompt = f"""### 指示\n{input}\n### 回答\n"""
|
70 |
+
inputs = tokenizer([prompt], return_tensors = "pt").to(model.device)
|
71 |
+
outputs = model.generate(**inputs, max_new_tokens = 512, use_cache = True, do_sample=False, repetition_penalty=1.2)
|
72 |
+
prediction = tokenizer.decode(outputs[0], skip_special_tokens=True).split('\n### 回答')[-1]
|
73 |
+
results.append({"task_id": data["task_id"], "input": input, "output": output})
|
74 |
+
# 保存
|
75 |
+
with open(f"/content/{model_name}_output.jsonl", 'w', encoding='utf-8') as f:
|
76 |
+
for result in results:
|
77 |
+
json.dump(result, f, ensure_ascii=False)
|
78 |
+
f.write('\n')
|
79 |
+
```
|