Add README
Browse files
README.md
CHANGED
@@ -1,3 +1,69 @@
|
|
1 |
-
#
|
2 |
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# LLM-JP-3.3.7B-IT LoRA Model
|
2 |
|
3 |
+
This is the LLM-JP-3.3.7B-IT model fine-tuned with LoRA.
|
4 |
+
|
5 |
+
# How to Use
|
6 |
+
|
7 |
+
```python
|
8 |
+
##################################################
|
9 |
+
import torch
|
10 |
+
from unsloth import FastLanguageModel
|
11 |
+
from peft import PeftModel
|
12 |
+
|
13 |
+
HF_TOKEN = ""
|
14 |
+
|
15 |
+
# モデルとトークナイザーの読み込み
|
16 |
+
model, tokenizer = FastLanguageModel.from_pretrained(
|
17 |
+
model_name="llm-jp/llm-jp-3-3.7b",
|
18 |
+
dtype=None,
|
19 |
+
load_in_4bit=True,
|
20 |
+
trust_remote_code=True,
|
21 |
+
)
|
22 |
+
model = PeftModel.from_pretrained(model, "nito78/llm-jp-3-3.7b-it_lora_all", token = HF_TOKEN)
|
23 |
+
|
24 |
+
# 推論モード
|
25 |
+
FastLanguageModel.for_inference(model)
|
26 |
+
##################################################
|
27 |
+
import json
|
28 |
+
|
29 |
+
# データの読み込み
|
30 |
+
datasets = []
|
31 |
+
with open("./elyza-tasks-100-TV_0.jsonl", "r") as f:
|
32 |
+
item = ""
|
33 |
+
for line in f:
|
34 |
+
line = line.strip()
|
35 |
+
item += line
|
36 |
+
if item.endswith("}"):
|
37 |
+
datasets.append(json.loads(item))
|
38 |
+
item = ""
|
39 |
+
##################################################
|
40 |
+
from tqdm import tqdm
|
41 |
+
|
42 |
+
# 推論
|
43 |
+
results = []
|
44 |
+
for dt in tqdm(datasets):
|
45 |
+
input = dt["input"]
|
46 |
+
|
47 |
+
prompt = f"""### 指示\n{input}\n### 回答\n"""
|
48 |
+
|
49 |
+
inputs = tokenizer([prompt], return_tensors = "pt").to(model.device)
|
50 |
+
|
51 |
+
outputs = model.generate(**inputs, max_new_tokens = 512, use_cache = True, do_sample=False, repetition_penalty=1.2)
|
52 |
+
prediction = tokenizer.decode(outputs[0], skip_special_tokens=True).split('\n### 回答')[-1]
|
53 |
+
|
54 |
+
results.append({"task_id": dt["task_id"], "input": input, "output": prediction})
|
55 |
+
##################################################
|
56 |
+
import re
|
57 |
+
import os
|
58 |
+
import json
|
59 |
+
|
60 |
+
# 保存先ディレクトリ
|
61 |
+
output_dir = "./results"
|
62 |
+
os.makedirs(output_dir, exist_ok=True)
|
63 |
+
|
64 |
+
# 結果を保存
|
65 |
+
output_file = os.path.join(output_dir, "result.jsonl")
|
66 |
+
with open(output_file, 'w', encoding='utf-8') as f:
|
67 |
+
for result in results:
|
68 |
+
json.dump(result, f, ensure_ascii=False)
|
69 |
+
f.write('\n')
|