尝试使用Electra而不是BERT模型运行NLP模型



我想用Electra模型而不是Bert模型来运行wl-coref模型。但是,我得到了一个关于Electra模型的错误消息,并且无法在Huggingface文档中找到如何修复它的提示。

我尝试了不同的BERT模型,如roberta-base, BERT -base-german-case或SpanBERT/SpanBERT -base-case。所有的作品。但是如果我尝试一个Electra模型,比如google/Electra -base-discriminator或german-nlp-group/Electra -base-german-uncase,那么它就不起作用了。

显示错误:

out, _ = self.bert(subwords_batches_tensor,  attention_mask=torch.tensor(attention_mask, device=self.config.device))
ValueError: not enough values to unpack (expected 2, got 1)

这就是产生错误的方法:第349行_bertify。

去掉下划线_。ELECTRA不会像BERT或RoBerta那样返回池输出:

from transformers import AutoTokenizer, AutoModel
def bla(model_id:str):
t = AutoTokenizer.from_pretrained(model_id)
m = AutoModel.from_pretrained(model_id)
print(m(**t("this is a test", return_tensors="pt")).keys())
bla("google/electra-base-discriminator")
bla("roberta-base")

输出:

odict_keys(['last_hidden_state'])
odict_keys(['last_hidden_state', 'pooler_output'])

最新更新