yasuokaの日記: JGLUEをtransformers 4.19.2でムリヤリ動かすには
栗原健太郎・河原大輔・柴田知秀『JGLUE: 日本語言語理解ベンチマーク』(言語処理学会第28回年次大会発表論文集(2022年3月), pp.2023-2028)で予告されていたJGLUEが無事に公開されたので、早速、日本語DeBERTa(V2)モデル(これとかこれ)を、評価してみることにした。ただ、JGLUEはtransformers 4.9.2での動作が想定されていて、ちょっと困った。というのも、私(安岡孝一)の日本語DeBERTa(V2)モデルは、トークナイザにDebertaV2TokenizerFastを使っているので、transformers 4.19.0以降でなければ動作しないのだ。そこで、JGLUEを無理矢理transformers 4.19.2で動かしてみることにした。とりあえずは、deberta-base-japanese-aozoraをJCommonSenseQAで評価すべく、以下のプログラムをGoogle Colaboratory (GPU)で動かしてみた。
!test -d transformers-4.19.2 || git clone -b v4.19.2 --depth=1 https://github.com/huggingface/transformers transformers-4.19.2
!test -d JGLUE || ( git clone --depth=1 https://github.com/yahoojapan/JGLUE && cat JGLUE/fine-tuning/patch/transformers-4.9.2_jglue-1.0.0.patch | ( cd transformers-4.19.2 && patch -p1 ) )
!cd transformers-4.19.2 && pip install .
!pip install -r transformers-4.19.2/examples/pytorch/text-classification/requirements.txt
!python transformers-4.19.2/examples/pytorch/multiple-choice/run_swag.py --model_name_or_path KoichiYasuoka/deberta-base-japanese-aozora --do_train --do_eval --do_predict --max_seq_length 64 --per_device_train_batch_size 32 --learning_rate 5e-05 --num_train_epochs 4 --output_dir ./output_jcommonsenseqa --overwrite_output_dir --train_file JGLUE/datasets/jcommonsenseqa-v1.0/train-v1.0.json --validation_file JGLUE/datasets/jcommonsenseqa-v1.0/valid-v1.0.json --test_file JGLUE/datasets/jcommonsenseqa-v1.0/valid-v1.0.json --use_fast_tokenizer True --evaluation_strategy epoch --warmup_ratio 0.1
さすがに色々とウォーニングが出まくったものの、20分強でファインチューニングが終了し、以下の「eval metrics」が出力された。
***** eval metrics *****
epoch = 4.0
eval_accuracy = 0.5085
eval_loss = 1.6801
eval_runtime = 0:00:10.90
eval_samples = 1119
eval_samples_per_second = 102.577
eval_steps_per_second = 12.834
うーむ、JCommonSenseQAが0.5085…。まあ、元データが青空文庫なので、こんなものなのだろう。でも、JGLUEのタスクのうち、JSQuADはDebertaV2TokenizerFastを受け付けてくれないようだ。うーん、せっかく作ったDebertaV2TokenizerFastなのだけど、ここはDebertaV2Tokenizerに戻すべきかしら。
JGLUEをtransformers 4.19.2でムリヤリ動かすには More ログイン