transformers icon indicating copy to clipboard operation
transformers copied to clipboard

How to finetune ELECTRA on glue?

Open elyesmanai opened this issue 6 years ago • 8 comments

After pretraining my own electra model, I wanted to test it out in Glue using run_glue.py. However I got this:

ValueError: Unrecognized configuration class <class 'transformers.configuration_electra.ElectraConfig'> for this kind of AutoModel: AutoModelForSequenceClassification.
Model type should be one of DistilBertConfig, AlbertConfig, CamembertConfig, XLMRobertaConfig, BartConfig, RobertaConfig, BertConfig, XLNetConfig, FlaubertConfig, XLMConfig.

After taking a look at the source code, It seems like ElectraConfig isn't available for sequence classification, is there a reason for that? Did anyone finetune electra on glue?

elyesmanai avatar May 21 '20 15:05 elyesmanai

I have a pull request here https://github.com/huggingface/transformers/pull/4257

liuzzi avatar May 22 '20 04:05 liuzzi

I just cloned your repo an tried to test with my model and it keeps saying the same: image

Could you tell me how it's used?

elyesmanai avatar May 22 '20 09:05 elyesmanai

@liuzzi's PR was merged this morning. The ElectraForSequenceClassification model is now available, so you can use it directly in run_glue.py.

Please make sure to pull the latest changes from the repo, or to wait for v2.10 which should be released in a few hours.

LysandreJik avatar May 22 '20 13:05 LysandreJik

awesome, it works perfectly, thank you very much!

elyesmanai avatar May 22 '20 14:05 elyesmanai

@elyesmanai Could you please share the code for pretraining Electra from scratch?

glakshmidhar avatar May 27 '20 19:05 glakshmidhar

I'm using the simpletransformers library for the pretraining since transformers doesn't support it yet. here's a link to how you can do it, it's super easy. It's built on top of transformers so you can load the model into transformers and use the rest of the lib

elyesmanai avatar May 28 '20 02:05 elyesmanai

The pre-training from scratch for transformers is available here. It is being tested right now.

LysandreJik avatar May 29 '20 15:05 LysandreJik

This problem happened again, when I use ELECTRA on question-answering pipeline. My Transformers version is 2.11.0.

from transformers import pipeline, AutoTokenizer, AutoModelForQuestionAnswering

tokenizer = AutoTokenizer.from_pretrained("ahotrod/electra_large_discriminator_squad2_512")

model = AutoModelForQuestionAnswering.from_pretrained("ahotrod/electra_large_discriminator_squad2_512")

albert_qa = pipeline('question-answering', model=model, tokenizer=tokenizer)

image

cktsangal avatar Jul 14 '20 14:07 cktsangal