ikedachin commited on
Commit
8f6c9af
·
verified ·
1 Parent(s): f3f9ce1

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +39 -1
README.md CHANGED
@@ -31,4 +31,42 @@ lora_alpha:512
31
  lr:3e-4
32
  embedding_lr: 3e-5
33
 
34
- 狙い: r、lora_alphaを大きくして、SFTによる記憶忘却に耐えられるようにCPTによるベースモデルへの知識埋め込みの影響を大きくする
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
  lr:3e-4
32
  embedding_lr: 3e-5
33
 
34
+ 狙い: r、lora_alphaを大きくして、SFTによる記憶忘却に耐えられるようにCPTによるベースモデルへの知識埋め込みの影響を大きくする
35
+
36
+
37
+ ```python
38
+ # import libraries
39
+ import tqdm
40
+ import torch
41
+ from datasets import load_dataset
42
+ from transformers import AutoModelForCausalLM, AutoTokenizer
43
+
44
+ # config
45
+ model_id = "ikedachin/llm-jp-3-13b-october-news-250311-merged"
46
+
47
+ # set Token of Huggingface
48
+ HF_TOKEN = <<YOUR_TOKEN>>
49
+
50
+ # download model and tokenizer
51
+ model = AutoModelForCausalLM.from_pretrained(
52
+ model_id,
53
+ device_map = "auto",
54
+ torch_dtype = torch.bfloat16,
55
+ token = HF_TOKEN
56
+ )
57
+ tokenizer = AutoTokenizer.from_pretrained(model_id, token=HF_TOKEN)
58
+
59
+
60
+ # define inference function
61
+ def generate_from_model(input):
62
+ prompt = f"""{input}"""
63
+ input = tokenizer(prompt, return_tensors='pt', add_special_tokens=True).to(model.device)
64
+ input.pop('token_type_ids')
65
+ output = model.generate(**input, max_new_tokens = 1000, use_cache = False, do_sample=False, repetition_penalty=1.2)
66
+ return tokenizer.decode(output[0], skip_special_tokens=True)
67
+
68
+ # input prompt and inference
69
+ print(generate_from_model('石破茂さんは'))
70
+ # 石破茂さんは総裁選の最中に「国会で議論すべき」と発言を撤回。\n石破新首相は10月27日投開票の日程で、衆議院総選挙を行う意向を表明しました。9月30日の記者会見で<省略>
71
+
72
+ ```