sam-murayama commited on
Commit
c83dd0c
·
verified ·
1 Parent(s): 4023c6a

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
+ # Sample Use
25
+
26
+ 以下は、elyza-tasks-100-TV_0.jsonlの回答のためのコードです。
27
+
28
+ ```python
29
+ import json
30
+ datasets = []
31
+ with open("./elyza-tasks-100-TV_0.jsonl", "r") as f:
32
+ item = ""
33
+ for line in f:
34
+ line = line.strip()
35
+ item += line
36
+ if item.endswith("}"):
37
+ datasets.append(json.loads(item))
38
+ item = ""
39
+
40
+ from tqdm import tqdm
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
+ with open(f"{new_model_id}_output.jsonl", 'w', encoding='utf-8') as f:
58
+ for result in results:
59
+ json.dump(result, f, ensure_ascii=False)
60
+ f.write('\n')
61
+ ````