Update README.md
Browse files
README.md
CHANGED
@@ -24,13 +24,17 @@ language:
|
|
24 |
# 使用方法例
|
25 |
|
26 |
1. 依存関係のインストール:
|
27 |
-
```
|
28 |
-
|
|
|
|
|
|
|
|
|
29 |
```
|
30 |
|
31 |
2. モデルの読み込み:
|
32 |
|
33 |
-
```python
|
34 |
from unsloth import FastLanguageModel
|
35 |
from peft import PeftModel
|
36 |
|
@@ -51,17 +55,50 @@ model = PeftModel.from_pretrained(model, lola_adapter_id, token=hf_token)
|
|
51 |
```
|
52 |
3. 推論
|
53 |
|
54 |
-
|
|
|
55 |
FastLanguageModel.for_inference(model)
|
56 |
|
57 |
inputs = tokenizer([prompt], return_tensors = "pt").to(model.device)
|
58 |
|
59 |
outputs = model.generate(**inputs, max_new_tokens = max_token, use_cache = True, temperature=0.5, top_p=0.9,do_sample=False, repetition_penalty=1.2)
|
60 |
|
61 |
-
prediction =
|
62 |
|
63 |
```
|
64 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
|
66 |
This llama model was trained 2x faster with [Unsloth](https://github.com/unslothai/unsloth) and Huggingface's TRL library.
|
67 |
|
|
|
24 |
# 使用方法例
|
25 |
|
26 |
1. 依存関係のインストール:
|
27 |
+
```bash
|
28 |
+
# 必要なライブラリをインストール
|
29 |
+
pip install unsloth
|
30 |
+
pip uninstall unsloth -y && pip install --upgrade --no-cache-dir "unsloth[colab-new] @ git+https://github.com/unslothai/unsloth.git"
|
31 |
+
pip install -U torch
|
32 |
+
pip install -U peft
|
33 |
```
|
34 |
|
35 |
2. モデルの読み込み:
|
36 |
|
37 |
+
```python
|
38 |
from unsloth import FastLanguageModel
|
39 |
from peft import PeftModel
|
40 |
|
|
|
55 |
```
|
56 |
3. 推論
|
57 |
|
58 |
+
|
59 |
+
```python
|
60 |
FastLanguageModel.for_inference(model)
|
61 |
|
62 |
inputs = tokenizer([prompt], return_tensors = "pt").to(model.device)
|
63 |
|
64 |
outputs = model.generate(**inputs, max_new_tokens = max_token, use_cache = True, temperature=0.5, top_p=0.9,do_sample=False, repetition_penalty=1.2)
|
65 |
|
66 |
+
prediction = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
67 |
|
68 |
```
|
69 |
|
70 |
+
4. 評価データの読み込みと評価
|
71 |
+
|
72 |
+
```python
|
73 |
+
import pandas as pd
|
74 |
+
from datasets import Dataset
|
75 |
+
|
76 |
+
datasets = []
|
77 |
+
file_path = <評価データ(jsonl)>のパス
|
78 |
+
|
79 |
+
df = pd.read_json(filename, orient='records', lines=True)
|
80 |
+
|
81 |
+
results = []
|
82 |
+
|
83 |
+
for r in iterrows():
|
84 |
+
imput = r["input"]
|
85 |
+
prompt = f"""### 指示\n{input} 簡潔に回答してください \n### 回答\n"""
|
86 |
+
|
87 |
+
inputs = tokenizer([prompt], return_tensors = "pt").to(model.device)
|
88 |
+
|
89 |
+
outputs = model.generate(**inputs, max_new_tokens = max_token, use_cache = True, temperature=0.5, top_p=0.9,do_sample=False, repetition_penalty=1.2)
|
90 |
+
prediction = tokenizer.decode(outputs[0], skip_special_tokens=True).split('\n### 回答')[-1]
|
91 |
+
|
92 |
+
results.append({"task_id": r["task_id"], "input": input, "output": prediction})
|
93 |
+
|
94 |
+
# 結果をjsonlで保存。
|
95 |
+
json_file_id = <保存ファイル名>
|
96 |
+
with open(f"/content/{json_file_id}_output.jsonl", 'w', encoding='utf-8') as f:
|
97 |
+
for result in results:
|
98 |
+
json.dump(result, f, ensure_ascii=False)
|
99 |
+
f.write('\n')
|
100 |
+
|
101 |
+
```
|
102 |
|
103 |
This llama model was trained 2x faster with [Unsloth](https://github.com/unslothai/unsloth) and Huggingface's TRL library.
|
104 |
|