huggingface / transformers

šŸ¤— Transformers: State-of-the-art Machine Learning for Pytorch, TensorFlow, and JAX.
https://huggingface.co/transformers
Apache License 2.0
135.62k stars 27.15k forks source link

metric is uninitialized when csv data is supplied to example/pytorch/text-classification/run_glue_no_trainer.py #11403

Closed daraghhartnett closed 3 years ago

daraghhartnett commented 3 years ago

Environment info

Who can help

Information

Model I am using (Bert, XLNet ...): distilbert-base-uncased

The problem arises when using:

Yields the error:

` Some weights of the model checkpoint at distilbert-base-uncased were not used when initializing DistilBertForSequenceClassification: ['vocab_transform.weight', 'vocab_transform.bias', 'vocab_layer_norm.weight', 'vocab_layer_norm.bias', 'vocab_projector.weight', 'vocab_projector.bias']

The tasks I am working on is:

Simple single sentence text classification

To reproduce

Steps to reproduce the behavior:

  1. Pick any csv dataset with a train and validation files and run the transformers/examples/pytorch/text-classification/run_glue_no_trainer.py script using the following parameters:
  2. --model_name_or_path distilbert-base-uncased --per_device_train_batch_size 32 --learning_rate 2e-5 --num_train_epochs 3 --train_file piracy_train.csv --validation_file piracy_validation.csv --output_dir /data/output/distilbert-base-uncased-piracy-no-trainer
  3. This will yield an error as the metric variable is not initialized when an optional args.task_name is not specified.

` Some weights of the model checkpoint at distilbert-base-uncased were not used when initializing DistilBertForSequenceClassification: ['vocab_transform.weight', 'vocab_transform.bias', 'vocab_layer_norm.weight', 'vocab_layer_norm.bias', 'vocab_projector.weight', 'vocab_projector.bias']

Expected behavior

Since providing your own csv files is allowed, the metric object should be initialized when no task_name is provided.

sgugger commented 3 years ago

Thanks for flagging. The PR mentioned above will make it default to accuracy. Of course, you're free to change it to whatever you need!

daraghhartnett commented 3 years ago

Glad to be of help! Ah, I did not see that - I only looked in the Issues to see if it had already been reported. I will check the PR's as well the next time. Thanks very much!

sgugger commented 3 years ago

The PR did not exist before you flagged the issue ;-) I opened it to fix it!

daraghhartnett commented 3 years ago

Ah! Excellent! I am using the PR you proposed locally so I am back in business :)