nishimura999 commited on
Commit
cefc663
·
verified ·
1 Parent(s): 626852f

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +92 -1
README.md CHANGED
@@ -8,7 +8,9 @@ tags:
8
  - trl
9
  license: apache-2.0
10
  language:
11
- - en
 
 
12
  ---
13
 
14
  # Uploaded model
@@ -20,3 +22,92 @@ 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)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
  - trl
9
  license: apache-2.0
10
  language:
11
+ - ja
12
+ datasets:
13
+ - kinokokoro/ichikara-instruction-003
14
  ---
15
 
16
  # Uploaded model
 
22
  This llama model was trained 2x faster with [Unsloth](https://github.com/unslothai/unsloth) and Huggingface's TRL library.
23
 
24
  [<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth)
25
+
26
+
27
+
28
+ # usage
29
+ ## -import
30
+ ```python
31
+ # 必要なライブラリを読み込み
32
+ from unsloth import FastLanguageModel
33
+ from peft import PeftModel
34
+ import torch
35
+ import json
36
+ from tqdm import tqdm
37
+ import re
38
+ ```
39
+
40
+ ## -setting
41
+ ```python
42
+ # Hugging Faceで取得したToken
43
+ HF_TOKEN = "{Your hugging face token}"
44
+
45
+ # モデルのIDと、LoRAのアダプタ名
46
+ model_id = "llm-jp/llm-jp-3-13b"
47
+ adapter_id = "nishimura999/llm-jp-3-13b-it-v107_lora"
48
+ ```
49
+
50
+ ## -load
51
+ ```python
52
+ # unslothのFastLanguageModelで元のモデルをロード。
53
+ dtype = None
54
+ load_in_4bit = True
55
+ model, tokenizer = FastLanguageModel.from_pretrained(
56
+ model_name=model_id,
57
+ dtype=dtype,
58
+ load_in_4bit=load_in_4bit,
59
+ trust_remote_code=True,
60
+ )
61
+ # 元のモデルにLoRAのアダプタを統合。
62
+ model = PeftModel.from_pretrained(model, adapter_id, token = HF_TOKEN)
63
+ ```
64
+
65
+ ## -dataset
66
+ ```python
67
+ # データセットの読み込み。
68
+ datasets = []
69
+ with open("./elyza-tasks-100-TV_0.jsonl", "r") as f:
70
+ item = ""
71
+ for line in f:
72
+ line = line.strip()
73
+ item += line
74
+ if item.endswith("}"):
75
+ datasets.append(json.loads(item))
76
+ item = ""
77
+ ```
78
+
79
+ ## -generate
80
+ ```python
81
+ # モデルを用いてタスクの推論。
82
+
83
+ FastLanguageModel.for_inference(model)
84
+
85
+ results = []
86
+ for dt in tqdm(datasets):
87
+ input = dt["input"]
88
+
89
+ prompt = f"""### 指示\n{input}\n### 回答\n"""
90
+
91
+ inputs = tokenizer([prompt], return_tensors = "pt").to(model.device)
92
+
93
+ outputs = model.generate(**inputs, max_new_tokens = 1024, use_cache = True, do_sample=False, repetition_penalty=1.2)
94
+ prediction = tokenizer.decode(outputs[0], skip_special_tokens=True).split('\n### 回答')[-1]
95
+
96
+ results.append({"task_id": dt["task_id"], "input": input, "output": prediction})
97
+ ```
98
+
99
+ ## -output
100
+ ```python
101
+ # 結果をjsonlで保存。
102
+ json_file_id = re.sub(".*/", "", adapter_id)
103
+ with open(f"./{json_file_id}_output.jsonl", 'w', encoding='utf-8') as f:
104
+ for result in results:
105
+ json.dump(result, f, ensure_ascii=False)
106
+ f.write('\n')
107
+ ```
108
+
109
+ # ref
110
+ ### 本モデルは下記のデータを使ってファインチューニングしております。ここでデータ提供者に感謝申し上げます。
111
+ (https://liat-aip.sakura.ne.jp/wp/llmのための日本語インストラクションデータ作成/llmのための日本語インストラクションデータ-公開/)
112
+ 関根聡, 安藤まや, 後藤美知子, 鈴木久美, 河原大輔, 井之上直也, 乾健太郎.
113
+ ichikara-instruction: LLMのための日本語インストラクションデータの構築. 言語処理学会第30回年次大会(2024)