ken2147 commited on
Commit
927025f
·
verified ·
1 Parent(s): 8fefeaf

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +85 -0
README.md CHANGED
@@ -20,3 +20,88 @@ 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
+ ## Instruction tuning
25
+ The models have been fine-tuned on the following datasets.
26
+ | Language | Dataset | description |
27
+ |:---|:---|:---|
28
+ |Japanese|[ichikara-instruction-003-001-1.json](https://liat-aip.sakura.ne.jp/wp/llm%E3%81%AE%E3%81%9F%E3%82%81%E3%81%AE%E6%97%A5%E6%9C%AC%E8%AA%9E%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%A9%E3%82%AF%E3%82%B7%E3%83%A7%E3%83%B3%E3%83%87%E3%83%BC%E3%82%BF%E4%BD%9C%E6%88%90/llm%E3%81%AE%E3%81%9F%E3%82%81%E3%81%AE%E6%97%A5%E6%9C%AC%E8%AA%9E%E3%82%A4%E3%83%B3%E3%82%B9%E3%83%88%E3%83%A9%E3%82%AF%E3%82%B7%E3%83%A7%E3%83%B3%E3%83%87%E3%83%BC%E3%82%BF-%E5%85%AC%E9%96%8B/)| A manually constructed instruction dataset |
29
+
30
+ データセット作成チーム:
31
+ 関根聡, 安藤まや, 後藤美知子, 鈴木久美, 河原大輔, 井之上直也, 乾健太郎. ichikara-instruction: LLMのための日本語インストラクションデータの構築. 言語処理学会第30回年次大会(2024)
32
+
33
+
34
+ # Usage
35
+
36
+ 下記は、/elyza-tasks-100-TV_0.jsonlの回答出力のためのコードです。
37
+
38
+ ```python
39
+ # 必要なライブラリをインストール
40
+ !pip install unsloth
41
+ !pip uninstall unsloth -y && pip install --upgrade --no-cache-dir "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"
42
+ !pip install -U torch
43
+ !pip install -U peft
44
+
45
+ # 必要なライブラリを読み込み
46
+ from unsloth import FastLanguageModel
47
+ from peft import PeftModel
48
+ import torch
49
+ import json
50
+ from tqdm import tqdm
51
+ import re
52
+
53
+ # ベースとなるモデルと学習したLoRAのアダプタ。
54
+ model_id = "llm-jp/llm-jp-3-13b"
55
+ adapter_id = "ken2147/llm-jp-3-13b-it_lora"
56
+
57
+ # Hugging Face Token を指定。
58
+ HF_TOKEN = "Your_HF_Token"
59
+
60
+ # unslothのFastLanguageModelで元のモデルをロード。
61
+ dtype = None # Noneにしておけば自動で設定
62
+ load_in_4bit = True # 今回は13Bモデルを扱うためTrue
63
+
64
+ model, tokenizer = FastLanguageModel.from_pretrained(
65
+ model_name=model_id,
66
+ dtype=dtype,
67
+ load_in_4bit=load_in_4bit,
68
+ trust_remote_code=True,
69
+ )
70
+
71
+ # 元のモデルにLoRAのアダプタを統合。
72
+ model = PeftModel.from_pretrained(model, adapter_id, token = HF_TOKEN)
73
+
74
+ # タスクとなるデータの読み込み。
75
+ datasets = []
76
+ with open("./elyza-tasks-100-TV_0.jsonl", "r") as f: # 環境に合わせてpathを変更
77
+ item = ""
78
+ for line in f:
79
+ line = line.strip()
80
+ item += line
81
+ if item.endswith("}"):
82
+ datasets.append(json.loads(item))
83
+ item = ""
84
+
85
+ # モデルを用いてタスクの推論。
86
+ FastLanguageModel.for_inference(model)
87
+ results = []
88
+ for dt in tqdm(datasets):
89
+ input = dt["input"]
90
+
91
+ prompt = f"""### 指示\n{input}\n### 回答\n"""
92
+
93
+ inputs = tokenizer([prompt], return_tensors = "pt").to(model.device)
94
+
95
+ outputs = model.generate(**inputs, max_new_tokens = 512, use_cache = True, do_sample=False, repetition_penalty=1.2)
96
+ prediction = tokenizer.decode(outputs[0], skip_special_tokens=True).split('\n### 回答')[-1]
97
+
98
+ results.append({"task_id": dt["task_id"], "input": input, "output": prediction})
99
+
100
+ # 結果をjsonlで保存。
101
+ # ファイル名は任意で問題なし。
102
+ json_file_id = re.sub(".*/", "", adapter_id)
103
+ with open(f"/content/{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
+ ```