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

发布于 2025-02-09 00:19:43 字数 801 浏览 2 评论 0 原文

我想运行 wl-coref 带有电气模型的模型而不是bert模型。但是,我通过Electra模型收到一条错误消息,并且找不到有关如何修复它的HuggingFace文档中的提示。

我尝试了不同的BERT模型,例如Roberta-Base,Bert-Base-German cassed或Spanbert/Spanbert-Base Cashed。所有工作。 但是,如果我尝试使用Electra模型,例如Google/Electra-Base-Discisiminator或Derman-NLP组/元基层 - 基德 - 荷兰语,则不起作用。

显示的错误:

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)

这是错误来自: _ bertify 在第349行中。

I want to run the wl-coref model with an Electra model instead of a Bert model. However, I get an error message with the Electra model and can't find a hint in the Huggingface documentation on how to fix it.

I try different BERT models such like roberta-base, bert-base-german-cased or SpanBERT/spanbert-base-cased. All works.
But if I try an Electra model, like google/electra-base-discriminator or german-nlp-group/electra-base-german-uncased then it doesn't work.

The error that is displayed:

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)

And this is the method where the error comes from:_bertify in line 349.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

硪扪都還晓 2025-02-16 00:19:43

只需删除下划线 _ electra electra 不像 bert or 或 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'])

Just remove the underscore _. ELECTRA does not return a pooling output like BERT or 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")

Output:

odict_keys(['last_hidden_state'])
odict_keys(['last_hidden_state', 'pooler_output'])
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文