Update README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,82 @@
|
|
1 |
---
|
2 |
license: cc-by-sa-4.0
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
---
|
2 |
license: cc-by-sa-4.0
|
3 |
+
datasets:
|
4 |
+
- databricks/databricks-dolly-15k
|
5 |
+
- kunishou/databricks-dolly-15k-ja
|
6 |
+
language:
|
7 |
+
- ja
|
8 |
+
---
|
9 |
+
```
|
10 |
+
import torch
|
11 |
+
from peft import PeftModel
|
12 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
13 |
+
|
14 |
+
LOAD_8BIT = False
|
15 |
+
BASE_MODEL = "cyberagent/open-calm-7b"
|
16 |
+
LORA_WEIGHTS = "nakayama/lora-db-dolly-15k-ja-for-open-calm-7b"
|
17 |
+
|
18 |
+
tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL)
|
19 |
+
|
20 |
+
model = AutoModelForCausalLM.from_pretrained(
|
21 |
+
BASE_MODEL,
|
22 |
+
load_in_8bit=LOAD_8BIT,
|
23 |
+
torch_dtype=torch.float16,
|
24 |
+
device_map="auto",
|
25 |
+
)
|
26 |
+
model = PeftModel.from_pretrained(
|
27 |
+
model,
|
28 |
+
LORA_WEIGHTS,
|
29 |
+
torch_dtype=torch.float16,
|
30 |
+
adapter_name=LORA_WEIGHTS
|
31 |
+
)
|
32 |
+
|
33 |
+
def generate_prompt(instruction, input=None):
|
34 |
+
if input:
|
35 |
+
return f"""以下は、タスクを説明する命令と、さらなるコンテキストを提供する入力の組み合わせです。要求を適切に満たすような応答を書きなさい。
|
36 |
+
|
37 |
+
### Instruction:
|
38 |
+
{instruction}
|
39 |
+
|
40 |
+
### Input:
|
41 |
+
{input}
|
42 |
+
|
43 |
+
### Response:"""
|
44 |
+
else:
|
45 |
+
return f"""以下は、ある作業を記述した指示です。依頼を適切に完了させる回答を書きなさい。
|
46 |
+
|
47 |
+
### Instruction:
|
48 |
+
{instruction}
|
49 |
+
|
50 |
+
### Response:"""
|
51 |
+
|
52 |
+
if not LOAD_8BIT:
|
53 |
+
model.half()
|
54 |
+
|
55 |
+
instruction="次の日本の観光地について説明してください。"
|
56 |
+
|
57 |
+
input="富士山"
|
58 |
+
|
59 |
+
prompt = generate_prompt(instruction, input)
|
60 |
+
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
61 |
+
|
62 |
+
with torch.no_grad():
|
63 |
+
generation_output = model.generate(
|
64 |
+
**inputs,
|
65 |
+
do_sample=True,
|
66 |
+
temperature=0.1,
|
67 |
+
top_p=0.75,
|
68 |
+
top_k=20,
|
69 |
+
return_dict_in_generate=True,
|
70 |
+
output_scores=True,
|
71 |
+
max_new_tokens=128,
|
72 |
+
repetition_penalty=1.5,
|
73 |
+
no_repeat_ngram_size=5,
|
74 |
+
pad_token_id=tokenizer.pad_token_id,
|
75 |
+
)
|
76 |
+
s = generation_output.sequences[0]
|
77 |
+
output = tokenizer.decode(s)
|
78 |
+
print(output.split("### Response:")[1].strip())
|
79 |
+
|
80 |
+
#富士山は静岡県の駿河湾沿いに位置する活火山である[1]。標高3,776メートル(1338フィート)で、[2]世界最高峰の山であり [4]、世
|
81 |
+
界で最も高い山と考えられている。[5][7](ただし、「世界で一番美しい」という評価は誤りであることが証明されている)。また「日本のマッターホルン」、「世界の七不思議」(ユネスコ世界遺産委員会によって認定)、そして西半球で最も有名な自然の観光名所の一つである。「Mount Fuji is the world's most beautiful mountain in Japan. It has been said that it was a national park of historical faith and well-
|
82 |
+
```
|