SusumuDou commited on
Commit
1884d0f
·
verified ·
1 Parent(s): da55fdd

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +38 -3
README.md CHANGED
@@ -22,10 +22,9 @@ This llama model was trained 2x faster with [Unsloth](https://github.com/unsloth
22
 
23
  [<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth)
24
 
25
- ファインチューニングした本モデルを使用して推論するモデルとトークナイザを読み出すコードの例を以下に示します。
26
 
27
  from unsloth import FastLanguageModel
28
-
29
  model_name = "SusumuDou/llm-jp-3-13b-finetune-2"
30
 
31
  max_seq_length = 2048
@@ -40,5 +39,41 @@ model, tokenizer = FastLanguageModel.from_pretrained(
40
  token = HF TOKEN,
41
  )
42
 
43
-
44
  FastLanguageModel.for_inference(model)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
 
23
  [<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth)
24
 
25
+ 1.ファインチューニングした本モデルを使用して推論するモデルとトークナイザを読み出すコードの例を以下に示します。
26
 
27
  from unsloth import FastLanguageModel
 
28
  model_name = "SusumuDou/llm-jp-3-13b-finetune-2"
29
 
30
  max_seq_length = 2048
 
39
  token = HF TOKEN,
40
  )
41
 
 
42
  FastLanguageModel.for_inference(model)
43
+
44
+ 2.上記1の推論モデルとトークナイザを使って推論したjson Linesファイルoutput.jsonlの出力方法を以下に示します。
45
+  入力ファイル:LLM_2024/最終課題/elyza-tasks-100-TV_0.jsonl
46
+ (1) モデルに推論させる入力ファイルの読み込み
47
+   コードは以下の通りです。 
48
+ datasets = []
49
+ with open("/content/drive/MyDrive/LLM_2024/最終課題/elyza-tasks-100-TV_0.jsonl", "r") as f:
50
+ item = ""
51
+ for line in f:
52
+ line = line.strip()
53
+ item += line
54
+ if item.endswith("}"):
55
+ datasets.append(json.loads(item))
56
+ item = ""
57
+
58
+ (2) 推論
59
+   コードは以下の通りです。
60
+ results = []
61
+ for dt in tqdm(datasets):
62
+ input = dt["input"]
63
+
64
+ prompt = f"""### 指示\n{input}\n### 回答\n"""
65
+
66
+ inputs = tokenizer([prompt], return_tensors = "pt").to(model.device)
67
+
68
+ outputs = model.generate(**inputs, max_new_tokens = 512, use_cache = True, do_sample=False, repetition_penalty=1.2)
69
+ prediction = tokenizer.decode(outputs[0], skip_special_tokens=True).split('\n### 回答')[-1]
70
+
71
+ results.append({"task_id": dt["task_id"], "input": input, "output": prediction})
72
+
73
+ (3) 推論結果output.jsonlの出力
74
+   コードは以下の通りです。
75
+ with open(f"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
+