Text Generation
Transformers
Japanese
English
Inference Endpoints
nakayama commited on
Commit
7b68403
1 Parent(s): 9a91d2a

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +81 -0
README.md CHANGED
@@ -1,3 +1,84 @@
1
  ---
2
  license: cc-by-sa-3.0
 
 
 
 
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: cc-by-sa-3.0
3
+ datasets:
4
+ - databricks/databricks-dolly-15k
5
+ - kunishou/databricks-dolly-69k-ja-en-translation
6
+ language:
7
+ - ja
8
+ - en
9
+ library_name: transformers
10
+ pipeline_tag: text-generation
11
  ---
12
+ [cyberagent/open-calm-7b](https://huggingface.co/cyberagent/open-calm-7b)に対して[kunishou/databricks-dolly-69k-ja-en-translation](https://huggingface.co/datasets/kunishou/databricks-dolly-69k-ja-en-translation)をpeftを用いて(というより[tloen/alpaca-lora](https://github.com/tloen/alpaca-lora)を改変して)チューニングしたものの差分です。
13
+ lora-alpacaから学習時のパラメータは特に変えていません。
14
+ ```
15
+ import torch
16
+ from peft import PeftModel
17
+ from transformers import AutoModelForCausalLM, AutoTokenizer
18
+
19
+ LOAD_8BIT = False
20
+ BASE_MODEL = "cyberagent/open-calm-7b"
21
+ LORA_WEIGHTS = "nakayama/lora-db-dolly-69k-ja-en-translation-for-open-calm-7b"
22
+
23
+ tokenizer = AutoTokenizer.from_pretrained(BASE_MODEL)
24
+
25
+ model = AutoModelForCausalLM.from_pretrained(
26
+ BASE_MODEL,
27
+ load_in_8bit=LOAD_8BIT,
28
+ torch_dtype=torch.float16,
29
+ device_map="auto",
30
+ )
31
+ model = PeftModel.from_pretrained(
32
+ model,
33
+ LORA_WEIGHTS,
34
+ torch_dtype=torch.float16,
35
+ adapter_name=LORA_WEIGHTS
36
+ )
37
+
38
+ def generate_prompt(instruction, input=None):
39
+ if input:
40
+ return f"""以下は、タスクを説明する命令と、さらなるコンテキストを提供する入力の組み合わせです。要求を適切に満たすような応答を書きなさい。
41
+
42
+ ### Instruction:
43
+ {instruction}
44
+
45
+ ### Input:
46
+ {input}
47
+
48
+ ### Response:"""
49
+ else:
50
+ return f"""以下は、ある作業を記述した指示です。依頼を適切に完了させる回答を書きなさい。
51
+
52
+ ### Instruction:
53
+ {instruction}
54
+
55
+ ### Response:"""
56
+
57
+ if not LOAD_8BIT:
58
+ model.half()
59
+
60
+ instruction="次に示す日本語の文章を英語に翻訳しなさい。"
61
+
62
+ input="富士山はとても高い山で、その高さは日本一と言われています。"
63
+
64
+ prompt = generate_prompt(instruction, input)
65
+ inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
66
+
67
+ with torch.no_grad():
68
+ generation_output = model.generate(
69
+ **inputs,
70
+ do_sample=True,
71
+ temperature=0.1,
72
+ top_p=0.75,
73
+ top_k=20,
74
+ return_dict_in_generate=True,
75
+ output_scores=True,
76
+ max_new_tokens=128,
77
+ repetition_penalty=1.5,
78
+ no_repeat_ngram_size=5,
79
+ pad_token_id=tokenizer.pad_token_id,
80
+ )
81
+ s = generation_output.sequences[0]
82
+ output = tokenizer.decode(s)
83
+ print(output.split("### Response:")[1].strip())
84
+ ```