Update README.md
Browse files
README.md
CHANGED
@@ -282,3 +282,43 @@ trainer = SFTTrainer(
|
|
282 |
torch.cuda.empty_cache()
|
283 |
#@title 学習実行
|
284 |
trainer_stats = trainer.train()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
282 |
torch.cuda.empty_cache()
|
283 |
#@title 学習実行
|
284 |
trainer_stats = trainer.train()
|
285 |
+
|
286 |
+
# ELYZA-tasks-100-TVの読み込み。事前にファイルをアップロードしてください
|
287 |
+
# データセットの読み込み。
|
288 |
+
# omnicampusの開発環境では、左にタスクのjsonlをドラッグアンドドロップしてから実行。
|
289 |
+
import json
|
290 |
+
datasets = []
|
291 |
+
#with open("./elyza-tasks-100-TV_0.jsonl", "r") as f:
|
292 |
+
with open("/content/elyza-tasks-100-TV_0.jsonl", "r") as f:
|
293 |
+
item = ""
|
294 |
+
for line in f:
|
295 |
+
line = line.strip()
|
296 |
+
item += line
|
297 |
+
if item.endswith("}"):
|
298 |
+
datasets.append(json.loads(item))
|
299 |
+
item = ""
|
300 |
+
|
301 |
+
# 学習したモデルを用いてタスクを実行
|
302 |
+
from tqdm import tqdm
|
303 |
+
|
304 |
+
# 推論するためにモデルのモードを変更
|
305 |
+
FastLanguageModel.for_inference(model)
|
306 |
+
|
307 |
+
results = []
|
308 |
+
for dt in tqdm(datasets):
|
309 |
+
input = dt["input"]
|
310 |
+
|
311 |
+
prompt = f"""### 指示\n{input}\n### 回答\n"""
|
312 |
+
|
313 |
+
inputs = tokenizer([prompt], return_tensors = "pt").to(model.device)
|
314 |
+
|
315 |
+
outputs = model.generate(**inputs, max_new_tokens = 512, use_cache = True, do_sample=False, repetition_penalty=1.2)
|
316 |
+
prediction = tokenizer.decode(outputs[0], skip_special_tokens=True).split('\n### 回答')[-1]
|
317 |
+
|
318 |
+
results.append({"task_id": dt["task_id"], "input": input, "output": prediction})
|
319 |
+
|
320 |
+
# jsonlで保存
|
321 |
+
with open(f"{new_model_id}_output.jsonl", 'w', encoding='utf-8') as f:
|
322 |
+
for result in results:
|
323 |
+
json.dump(result, f, ensure_ascii=False)
|
324 |
+
f.write('\n')
|