abcd1234-3 commited on
Commit
a04549a
·
verified ·
1 Parent(s): 9e3f637

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +39 -0
README.md CHANGED
@@ -20,3 +20,42 @@ 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
+ # How to use
25
+
26
+ ```python
27
+ import json
28
+ datasets = []
29
+ with open("./elyza-tasks-100-TV_0.jsonl", "r") as f:
30
+ item = ""
31
+ for line in f:
32
+ line = line.strip()
33
+ item += line
34
+ if item.endswith("}"):
35
+ datasets.append(json.loads(item))
36
+ item = ""
37
+
38
+ # 学習したモデルを用いてタスクを実行
39
+ from tqdm import tqdm
40
+
41
+ # 推論するためにモデルのモードを変更
42
+ FastLanguageModel.for_inference(model)
43
+
44
+ results = []
45
+ for dt in tqdm(datasets):
46
+ input = dt["input"]
47
+
48
+ prompt = f"""### 指示\n{input}\n### 回答\n"""
49
+
50
+ inputs = tokenizer([prompt], return_tensors = "pt").to(model.device)
51
+
52
+ outputs = model.generate(**inputs, max_new_tokens = 512, use_cache = True, do_sample=False, repetition_penalty=1.2)
53
+ prediction = tokenizer.decode(outputs[0], skip_special_tokens=True).split('\n### 回答')[-1]
54
+
55
+ results.append({"task_id": dt["task_id"], "input": input, "output": prediction})
56
+
57
+ # jsonlで保存
58
+ with open(f"{new_model_id}_output.jsonl", 'w', encoding='utf-8') as f:
59
+ for result in results:
60
+ json.dump(result, f, ensure_ascii=False)
61
+ f.write('\n')