naoyatakahashii commited on
Commit
64cd754
1 Parent(s): 3f9d210

update readme

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
+ # 実行方法
26
+ 以下のコードを実行します。
27
+
28
+ ```
29
+ %%capture
30
+ !pip install unsloth
31
+ !pip uninstall unsloth -y && pip install --upgrade --no-cache-dir "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"
32
+ from unsloth import FastLanguageModel
33
+ import json
34
+ model_name = "naoyatakahashii/llm-jp-3-13b-it"
35
+ max_seq_length = 2048
36
+ dtype = None
37
+ load_in_4bit = True
38
+
39
+ model, tokenizer = FastLanguageModel.from_pretrained(
40
+ model_name = model_name,
41
+ max_seq_length = max_seq_length,
42
+ dtype = dtype,
43
+ load_in_4bit = load_in_4bit,
44
+ token = "HF token",
45
+ )
46
+ FastLanguageModel.for_inference(model)
47
+
48
+ # データセットの読み込み。
49
+ # ./elyza-tasks-100-TV_0.jsonlに対象ファイルを配置してください。
50
+ datasets = []
51
+ with open("./elyza-tasks-100-TV_0.jsonl", "r") as f:
52
+ item = ""
53
+ for line in f:
54
+ line = line.strip()
55
+ item += line
56
+ if item.endswith("}"):
57
+ datasets.append(json.loads(item))
58
+ item = ""
59
+
60
+ from tqdm import tqdm
61
+
62
+ from tqdm import tqdm
63
+
64
+ # 推論
65
+ results = []
66
+ for dt in tqdm(datasets):
67
+ input = dt["input"]
68
+
69
+ prompt = f"""### 指示\n{input}\n### 回答\n"""
70
+
71
+ inputs = tokenizer([prompt], return_tensors = "pt").to(model.device)
72
+
73
+ outputs = model.generate(**inputs, max_new_tokens = 512, use_cache = True, do_sample=False, repetition_penalty=1.2)
74
+ prediction = tokenizer.decode(outputs[0], skip_special_tokens=True).split('\n### 回答')[-1]
75
+
76
+ results.append({"task_id": dt["task_id"], "input": input, "output": prediction})
77
+
78
+ with open(f"/content/{model_name}_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
+ ```