Charles1973 commited on
Commit
b233041
·
1 Parent(s): e590d0d

ソースコードの追加

Browse files
Files changed (1) hide show
  1. app.py +35 -0
app.py CHANGED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # りんなGPT-2-medium ファインチューニングやってみた
2
+
3
+ # パッケージのインストール
4
+ !git clone https://github.com/huggingface/transformers -b v4.23.1
5
+ !pip install transformers==4.23.1
6
+ !pip install evaluate==0.3.0
7
+ !pip install sentencepiece==0.1.97
8
+
9
+ %%time
10
+
11
+ # ファインチューニングの実行
12
+ !python ./transformers/examples/pytorch/language-modeling/run_clm.py \
13
+ --model_name_or_path=rinna/japanese-gpt2-medium \
14
+ --train_file=natsumesouseki.txt \
15
+ --validation_file=natsumesouseki.txt \
16
+ --do_train \
17
+ --do_eval \
18
+ --num_train_epochs=3 \
19
+ --save_steps=5000 \
20
+ --save_total_limit=3 \
21
+ --per_device_train_batch_size=1 \
22
+ --per_device_eval_batch_size=1 \
23
+ --output_dir=output/
24
+
25
+ from transformers import T5Tokenizer, AutoModelForCausalLM
26
+
27
+ # トークナイザーとモデルの準備
28
+ tokenizer = T5Tokenizer.from_pretrained("rinna/japanese-gpt2-medium")
29
+ model = AutoModelForCausalLM.from_pretrained("rinna/japanese-gpt2-medium")
30
+
31
+ # 推論の実行
32
+ def Chat(prompt, ):
33
+ input = tokenizer.encode(prompt, return_tensors="pt")
34
+ output = model.generate(input, do_sample=True, max_length=300, num_return_sequences=5)
35
+ return print(tokenizer.batch_decode(output))