Add README
Browse files
README.md
CHANGED
@@ -1,69 +1,87 @@
|
|
1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
-
|
4 |
|
5 |
-
|
|
|
|
|
|
|
|
|
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
|
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 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
from tqdm import tqdm
|
41 |
|
42 |
-
#
|
43 |
results = []
|
44 |
for dt in tqdm(datasets):
|
45 |
-
|
|
|
|
|
46 |
|
47 |
-
|
48 |
|
49 |
-
|
|
|
50 |
|
51 |
-
|
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,
|
67 |
for result in results:
|
68 |
json.dump(result, f, ensure_ascii=False)
|
69 |
-
f.write(
|
|
|
1 |
+
---
|
2 |
+
language: ja
|
3 |
+
tags:
|
4 |
+
- text-generation
|
5 |
+
- japanese
|
6 |
+
- llm
|
7 |
+
- lora
|
8 |
+
- instruction-tuning
|
9 |
+
license: cc-by-nc-sa-4.0
|
10 |
+
datasets:
|
11 |
+
- ichikara-instruction
|
12 |
+
- Ego/jpflan-raw
|
13 |
+
base_model: llm-jp/llm-jp-3-3.7b
|
14 |
+
model_name: llm-jp-3-3.7b-it_lora_all
|
15 |
+
widget:
|
16 |
+
- text: ""
|
17 |
+
---
|
18 |
|
19 |
+
# LLM-JP-3.3.7B LoRA Model
|
20 |
|
21 |
+
This is the **LLM-JP-3.3.7B** model fine-tuned with LoRA for instruction-based Japanese text generation tasks. The model has been fine-tuned on datasets **ichikara-instruction** and **Ego/jpflan-raw**.
|
22 |
+
|
23 |
+
## How to Use
|
24 |
+
|
25 |
+
Below is an example of how to use the model for inference:
|
26 |
|
27 |
```python
|
|
|
28 |
import torch
|
29 |
from unsloth import FastLanguageModel
|
30 |
from peft import PeftModel
|
31 |
|
32 |
+
HF_TOKEN = "" # Add your Hugging Face token here
|
33 |
|
34 |
+
# Load the base model and tokenizer
|
35 |
model, tokenizer = FastLanguageModel.from_pretrained(
|
36 |
model_name="llm-jp/llm-jp-3-3.7b",
|
37 |
dtype=None,
|
38 |
load_in_4bit=True,
|
39 |
trust_remote_code=True,
|
40 |
)
|
41 |
+
model = PeftModel.from_pretrained(model, "nito78/llm-jp-3-3.7b-it_lora_all", token=HF_TOKEN)
|
42 |
|
43 |
+
# Switch to inference mode
|
44 |
FastLanguageModel.for_inference(model)
|
45 |
+
|
46 |
+
# Example usage
|
47 |
import json
|
48 |
|
49 |
+
# Load dataset
|
50 |
datasets = []
|
51 |
with open("./elyza-tasks-100-TV_0.jsonl", "r") as f:
|
52 |
item = ""
|
53 |
for line in f:
|
54 |
+
line = line.strip()
|
55 |
+
item += line
|
56 |
+
if item.endswith("}"):
|
57 |
+
datasets.append(json.loads(item))
|
58 |
+
item = ""
|
59 |
+
|
60 |
from tqdm import tqdm
|
61 |
|
62 |
+
# Perform inference
|
63 |
results = []
|
64 |
for dt in tqdm(datasets):
|
65 |
+
input = dt["input"]
|
66 |
+
|
67 |
+
prompt = f"""### 指示\n{input}\n### 回答\n"""
|
68 |
|
69 |
+
inputs = tokenizer([prompt], return_tensors="pt").to(model.device)
|
70 |
|
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 |
|
74 |
+
results.append({"task_id": dt["task_id"], "input": input, "output": prediction})
|
|
|
75 |
|
|
|
|
|
|
|
76 |
import os
|
77 |
import json
|
78 |
|
79 |
+
# Save results
|
80 |
output_dir = "./results"
|
81 |
os.makedirs(output_dir, exist_ok=True)
|
82 |
|
|
|
83 |
output_file = os.path.join(output_dir, "result.jsonl")
|
84 |
+
with open(output_file, "w", encoding="utf-8") as f:
|
85 |
for result in results:
|
86 |
json.dump(result, f, ensure_ascii=False)
|
87 |
+
f.write("\n")
|