qcube commited on
Commit
8075812
·
verified ·
1 Parent(s): e2fc490

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +60 -0
README.md CHANGED
@@ -20,3 +20,63 @@ language:
20
  This llama model was trained 2x faster with [Unsloth](https://github.com/unslothai/unsloth) and Huggingface's TRL library.
21
 
22
  [<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  This llama model was trained 2x faster with [Unsloth](https://github.com/unslothai/unsloth) and Huggingface's TRL library.
21
 
22
  [<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth)
23
+
24
+
25
+ # Sample use
26
+
27
+ 以下は、elyza-tasks-100-TV_0.jsonl の回答のためのコードです。
28
+
29
+ ```python
30
+ # ELYZA-tasks-100-TVの読み込み。事前にファイルをアップロードしてください
31
+ # データセットの読み込み。
32
+ # omnicampusの開発環境では、左にタスクのjsonlをドラッグアンドドロップしてから実行。
33
+ import json
34
+
35
+ datasets = []
36
+ with open("./elyza-tasks-100-TV_0.jsonl", "r") as f:
37
+ item = ""
38
+ for line in f:
39
+ line = line.strip()
40
+ item += line
41
+ if item.endswith("}"):
42
+ datasets.append(json.loads(item))
43
+ item = ""
44
+
45
+
46
+ # 学習したモデルを用いてタスクを実行
47
+ from tqdm import tqdm
48
+
49
+ # 推論するためにモデルのモードを変更
50
+ FastLanguageModel.for_inference(model)
51
+
52
+ results = []
53
+ for dt in tqdm(datasets):
54
+ input = dt["input"]
55
+
56
+ prompt = f"""### 指示\n{input}\n### 回答\n"""
57
+
58
+ inputs = tokenizer([prompt], return_tensors="pt").to(model.device)
59
+
60
+ outputs = model.generate(
61
+ **inputs,
62
+ max_new_tokens=512,
63
+ use_cache=True,
64
+ do_sample=False,
65
+ repetition_penalty=1.2,
66
+ )
67
+ prediction = tokenizer.decode(
68
+ outputs[0],
69
+ skip_special_tokens=True,
70
+ ).split(
71
+ "\n### 回答"
72
+ )[-1]
73
+
74
+ results.append({"task_id": dt["task_id"], "input": input, "output": prediction})
75
+
76
+
77
+ # jsonlで保存
78
+ with open(f"{new_model_id}_output.jsonl", 'w', encoding='utf-8') as f:
79
+ for result in results:
80
+ json.dump(result, f, ensure_ascii=False)
81
+ f.write('\n')
82
+ ```