Update README.md
Browse files
README.md
CHANGED
@@ -21,6 +21,87 @@ This llama model was trained 2x faster with [Unsloth](https://github.com/unsloth
|
|
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 |
入力における必須フィールド: {"input": "処理するテキスト"}
|
26 |
出力形式:jsonl形式 {"task_id":タスク番号,"input":処理するテキスト,"output":出力されたテキスト}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
# llm-jp-13b-ver1.2
|
25 |
+
llm-jp/llm-jp-3-13b(https://huggingface.co/llm-jp/llm-jp-3-13b)をSFTしたモデルです。
|
26 |
+
|
27 |
+
松尾研大規模言語モデル講座2024(https://weblab.t.u-tokyo.ac.jp/lecture/course-list/large-language-model/)のコンペ用の提出モデル作成の一環として作成・公開しています。
|
28 |
+
|
29 |
+
## 推論方法
|
30 |
+
|
31 |
入力における必須フィールド: {"input": "処理するテキスト"}
|
32 |
出力形式:jsonl形式 {"task_id":タスク番号,"input":処理するテキスト,"output":出力されたテキスト}
|
33 |
+
|
34 |
+
```bash
|
35 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
|
36 |
+
from unsloth import FastLanguageModel
|
37 |
+
import torch
|
38 |
+
from huggingface_hub import login
|
39 |
+
|
40 |
+
max_seq_length = 512
|
41 |
+
dtype = None
|
42 |
+
load_in_4bit = True
|
43 |
+
|
44 |
+
token = "" #huggingfaceトークンを入力
|
45 |
+
if token:
|
46 |
+
login(token=token)
|
47 |
+
else:
|
48 |
+
raise ValueError("環境変数 'HUGGINGFACE_TOKEN' にアクセストークンを設定してください。")
|
49 |
+
|
50 |
+
model_id = "izumiharu/llm-jp-3-3.7b-ver1.1"
|
51 |
+
|
52 |
+
# FastLanguageModel インスタンスを作成
|
53 |
+
model, tokenizer = FastLanguageModel.from_pretrained(
|
54 |
+
model_name=model_id,
|
55 |
+
dtype=dtype,
|
56 |
+
load_in_4bit=load_in_4bit,
|
57 |
+
trust_remote_code=True,
|
58 |
+
)
|
59 |
+
#プロンプトの設定
|
60 |
+
prompt = """### 指示
|
61 |
+
{}
|
62 |
+
### 回答
|
63 |
+
{}"""
|
64 |
+
|
65 |
+
import json
|
66 |
+
datasets = []
|
67 |
+
#任意のデータセットを指定
|
68 |
+
with open("", "r") as f:
|
69 |
+
item = ""
|
70 |
+
for line in f:
|
71 |
+
line = line.strip()
|
72 |
+
item += line
|
73 |
+
if item.endswith("}"):
|
74 |
+
datasets.append(json.loads(item))
|
75 |
+
item = ""
|
76 |
+
|
77 |
+
# 学習したモデルを用いてタスクを実行
|
78 |
+
from tqdm import tqdm
|
79 |
+
|
80 |
+
# 推論するためにモデルのモードを変更
|
81 |
+
FastLanguageModel.for_inference(model)
|
82 |
+
|
83 |
+
results = []
|
84 |
+
count=0
|
85 |
+
for dt in tqdm(datasets):
|
86 |
+
input = dt["input"]
|
87 |
+
|
88 |
+
prompt = f"""### 指示\n{input}\n### 回答\n"""
|
89 |
+
|
90 |
+
inputs = tokenizer([prompt], return_tensors = "pt").to(model.device)
|
91 |
+
|
92 |
+
outputs = model.generate(**inputs, max_new_tokens = 512, use_cache = True, do_sample=False, repetition_penalty=1.2)
|
93 |
+
prediction = tokenizer.decode(outputs[0], skip_special_tokens=True).split('\n### 回答')[-1]
|
94 |
+
|
95 |
+
results.append({"task_id": count, "input": input, "output": prediction})
|
96 |
+
|
97 |
+
output_file = "output.jsonl"
|
98 |
+
|
99 |
+
# JSONLファイルに書き込み
|
100 |
+
with open(output_file, 'w', encoding='utf-8') as f:
|
101 |
+
for item in results:
|
102 |
+
# 各辞書をJSON文字列に変換し、ファイルに書き込む
|
103 |
+
json_line = json.dumps(item, ensure_ascii=False)
|
104 |
+
f.write(json_line + "\n")
|
105 |
+
|
106 |
+
print(f"データが'{output_file}'に保存されました。")
|
107 |
+
```
|