LoginSignup
1
2

More than 3 years have passed since last update.

Transformersの__init__() got an unexpected keyword argument 'prediction loss only'エラーを解決した件について

Posted at

はじめに

Huggingface Transformersを勉強しているのですが、Transformersが新しくなったようで、公式に乗っているコードも動かないものが多く、そちらの対処をしましたので記事にします。

私はこちらの記事を動かしている途中でエラーに遭遇しました。

問題

以下のコードで学習を実行したところ

# 学習
!python transformers/examples/language-modeling/run_language_modeling.py \
    --output_dir=output \
    --model_type=gpt2 \
    --model_name_or_path=gpt2 \
    --do_train \
    --train_data_file=train.txt \
    --do_eval \
    --eval_data_file=eval.txt \
    --per_device_train_batch_size=2 \
    --per_device_eval_batch_size=2 \
    --num_train_epochs=10 \
    --save_steps=5000 \
    --save_total_limit=3

以下のようなエラーがでた

__init__() got an unexpected keyword argument 'prediction loss only'

解決方法

こちらの記事を参考に対処を行っていました。

transformers/examples/legacy/run_language_modeling.pyを開いて以下の行をコメントアウトします。

# 318行目
# prediction_loss_onlyをコメントアウトする
    # Initialize our Trainer
    trainer = Trainer(
        model=model,
        args=training_args,
        data_collator=data_collator,
        train_dataset=train_dataset,
        eval_dataset=eval_dataset,
        # prediction_loss_only=True,
    )

おわりに

prediction_loss_only=Trueが何を表しているのか、理解できていないのでがんばりたいです。
なんとか記事通りに動きました。めでたしめでたし。

参考サイト

https://note.com/npaka/n/nad450e772a84?magazine_key=mdf3ce11e35b9
https://www.gitmemory.com/issue/huggingface/blog/72/785454524

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2