Update README.md
Browse files
README.md
CHANGED
@@ -42,7 +42,7 @@ import json
|
|
42 |
Specify the base model and the adapter for LoRA fine-tuning. Replace <adapter_id> and <HF_TOKEN> with appropriate values.
|
43 |
``` python
|
44 |
# Base model
|
45 |
-
model_name = "kkkeee/llm-jp-3-13b-
|
46 |
|
47 |
# Hugging Face Token
|
48 |
HF_TOKEN = "<your_hf_token>" # Obtain token from https://huggingface.co/settings/tokens
|
@@ -65,7 +65,7 @@ FastLanguageModel.for_inference(model)
|
|
65 |
```
|
66 |
# Step 4: Load Dataset
|
67 |
Prepare your dataset in .jsonl format and upload it to your environment.
|
68 |
-
|
69 |
# Load task data
|
70 |
datasets = []
|
71 |
with open("./elyza-tasks-100-TV_0.jsonl", "r") as f:
|
@@ -76,34 +76,33 @@ with open("./elyza-tasks-100-TV_0.jsonl", "r") as f:
|
|
76 |
if item.endswith("}"):
|
77 |
datasets.append(json.loads(item))
|
78 |
item = ""
|
79 |
-
|
80 |
# Step 5: Perform Inference
|
81 |
Set the model to inference mode and generate predictions.
|
|
|
|
|
82 |
|
83 |
-
#
|
84 |
-
FastLanguageModel.for_inference(model)
|
85 |
-
|
86 |
results = []
|
87 |
-
for
|
88 |
-
|
89 |
-
|
90 |
-
prompt = f"""### 指示\n{input}\n### 回答\n"""
|
91 |
|
92 |
-
|
93 |
|
94 |
-
|
95 |
-
**inputs, max_new_tokens=512, use_cache=True, do_sample=False, repetition_penalty=1.2
|
96 |
-
)
|
97 |
-
prediction = tokenizer.decode(outputs[0], skip_special_tokens=True).split('\n### 回答')[-1]
|
98 |
|
99 |
-
|
|
|
100 |
|
|
|
|
|
101 |
# Step 6: Save Results
|
102 |
Save the inference results to a .jsonl file. Replace <adapter_id> with the appropriate identifier.
|
103 |
-
|
104 |
# Save results to JSONL
|
105 |
json_file_id = re.sub(".*/", "", adapter_id)
|
106 |
with open(f"/content/{json_file_id}_output.jsonl", 'w', encoding='utf-8') as f:
|
107 |
for result in results:
|
108 |
json.dump(result, f, ensure_ascii=False)
|
109 |
-
f.write('\n')
|
|
|
|
42 |
Specify the base model and the adapter for LoRA fine-tuning. Replace <adapter_id> and <HF_TOKEN> with appropriate values.
|
43 |
``` python
|
44 |
# Base model
|
45 |
+
model_name = "kkkeee/llm-jp-3-13b-it15"
|
46 |
|
47 |
# Hugging Face Token
|
48 |
HF_TOKEN = "<your_hf_token>" # Obtain token from https://huggingface.co/settings/tokens
|
|
|
65 |
```
|
66 |
# Step 4: Load Dataset
|
67 |
Prepare your dataset in .jsonl format and upload it to your environment.
|
68 |
+
```python
|
69 |
# Load task data
|
70 |
datasets = []
|
71 |
with open("./elyza-tasks-100-TV_0.jsonl", "r") as f:
|
|
|
76 |
if item.endswith("}"):
|
77 |
datasets.append(json.loads(item))
|
78 |
item = ""
|
79 |
+
```
|
80 |
# Step 5: Perform Inference
|
81 |
Set the model to inference mode and generate predictions.
|
82 |
+
```python
|
83 |
+
from tqdm import tqdm
|
84 |
|
85 |
+
# 推論
|
|
|
|
|
86 |
results = []
|
87 |
+
for data in tqdm(datasets):
|
88 |
+
input = data["input"]
|
|
|
|
|
89 |
|
90 |
+
prompt = f"""### 指示\n{input}\n### 回答\n"""
|
91 |
|
92 |
+
inputs = tokenizer([prompt], return_tensors = "pt").to(model.device)
|
|
|
|
|
|
|
93 |
|
94 |
+
outputs = model.generate(**inputs, max_new_tokens = 512, use_cache = True, do_sample=False, repetition_penalty=1.2)
|
95 |
+
output = tokenizer.decode(outputs[0], skip_special_tokens=True).split('\n### 回答')[-1]
|
96 |
|
97 |
+
results.append({"task_id": data["task_id"], "input": input, "output": output})
|
98 |
+
```
|
99 |
# Step 6: Save Results
|
100 |
Save the inference results to a .jsonl file. Replace <adapter_id> with the appropriate identifier.
|
101 |
+
```python
|
102 |
# Save results to JSONL
|
103 |
json_file_id = re.sub(".*/", "", adapter_id)
|
104 |
with open(f"/content/{json_file_id}_output.jsonl", 'w', encoding='utf-8') as f:
|
105 |
for result in results:
|
106 |
json.dump(result, f, ensure_ascii=False)
|
107 |
+
f.write('\n')
|
108 |
+
```
|