Update README.md
Browse files
README.md
CHANGED
@@ -90,7 +90,7 @@ FastLanguageModel.for_inference(model)
|
|
90 |
results = []
|
91 |
for dt in tqdm(datasets):
|
92 |
input = dt["input"]
|
93 |
-
prompt = f"""
|
94 |
# 推論処理
|
95 |
```
|
96 |
|
@@ -112,4 +112,53 @@ JSONLファイルとして保存
|
|
112 |
"input": "入力テキスト",
|
113 |
"output": "モデルの出力"
|
114 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
115 |
```
|
|
|
90 |
results = []
|
91 |
for dt in tqdm(datasets):
|
92 |
input = dt["input"]
|
93 |
+
prompt = f"""以下は、タスクを説明する指示です。要求を適切に満たす回答を書きなさい。### 指示\n{input}\n### 回答\n"""
|
94 |
# 推論処理
|
95 |
```
|
96 |
|
|
|
112 |
"input": "入力テキスト",
|
113 |
"output": "モデルの出力"
|
114 |
}
|
115 |
+
```
|
116 |
+
|
117 |
+
```
|
118 |
+
model_id = "llm-jp/llm-jp-3-13b"
|
119 |
+
adapter_id = "154teru/llm-jp-3-13b-it15a4_fullset2048_lora"
|
120 |
+
|
121 |
+
HF_TOKEN = ""
|
122 |
+
|
123 |
+
dtype = None
|
124 |
+
load_in_4bit = True
|
125 |
+
|
126 |
+
model, tokenizer = FastLanguageModel.from_pretrained(
|
127 |
+
model_name=model_id,
|
128 |
+
dtype=dtype,
|
129 |
+
load_in_4bit=load_in_4bit,
|
130 |
+
trust_remote_code=True,
|
131 |
+
)
|
132 |
+
|
133 |
+
model = PeftModel.from_pretrained(model, adapter_id, token = HF_TOKEN)
|
134 |
+
|
135 |
+
datasets = []
|
136 |
+
with open("/content/elyza-tasks-100-TV_0.jsonl", "r") as f:
|
137 |
+
item = ""
|
138 |
+
for line in f:
|
139 |
+
line = line.strip()
|
140 |
+
item += line
|
141 |
+
if item.endswith("}"):
|
142 |
+
datasets.append(json.loads(item))
|
143 |
+
item = ""
|
144 |
+
|
145 |
+
FastLanguageModel.for_inference(model)
|
146 |
+
|
147 |
+
results = []
|
148 |
+
for dt in tqdm(datasets):
|
149 |
+
input = dt["input"]
|
150 |
+
|
151 |
+
prompt = f"""以下は、タスクを説明する指示です。要求を適切に満たす回答を書きなさい。### 指示\n{input}\n### 回答\n"""
|
152 |
+
|
153 |
+
inputs = tokenizer([prompt], return_tensors = "pt").to(model.device)
|
154 |
+
|
155 |
+
outputs = model.generate(**inputs, max_new_tokens = 1024, use_cache = True, do_sample=False, repetition_penalty=1.2)
|
156 |
+
prediction = tokenizer.decode(outputs[0], skip_special_tokens=True).split('\n### 回答')[-1]
|
157 |
+
|
158 |
+
results.append({"task_id": dt["task_id"], "input": input, "output": prediction})
|
159 |
+
|
160 |
+
with open("/content/prompt1024.jsonl", 'w', encoding='utf-8') as f:
|
161 |
+
for result in results:
|
162 |
+
json.dump(result, f, ensure_ascii=False)
|
163 |
+
f.write('\n')
|
164 |
```
|