【发布时间】:2021-07-15 13:50:41
【问题描述】:
我正在使用变压器,我已经加载了一个模型,它工作正常:
from transformers import AutoModelForSequenceClassification
from transformers import AutoTokenizer
task='sentiment'
MODEL = "cardiffnlp/twitter-roberta-base-{task}"
tokenizer = AutoTokenizer.from_pretrained(MODEL)
# PT
model = AutoModelForSequenceClassification.from_pretrained(MODEL)
model.save_pretrained(MODEL)
但如果我尝试加载另一个任务,如“情感”或“仇恨”,我会收到以下错误:
from transformers import AutoModelForSequenceClassification
from transformers import AutoTokenizer
task='emotion'
MODEL = "cardiffnlp/twitter-roberta-base-{task}"
tokenizer = AutoTokenizer.from_pretrained(MODEL)
# PT
model = AutoModelForSequenceClassification.from_pretrained(MODEL) ## Here I get the error
model.save_pretrained(MODEL)
这个错误:
OSError: Can't load weights for 'cardiffnlp/twitter-roberta-base-emotion'. Make sure that:
- 'cardiffnlp/twitter-roberta-base-emotion' is a correct model identifier listed on 'https://huggingface.co/models'
- or 'cardiffnlp/twitter-roberta-base-emotion' is the correct path to a directory containing a file named one of pytorch_model.bin, tf_model.h5, model.ckpt.
我已经检查过了,这些模型实际上是 Hugging Face 模型,你可以看到 here,所以我不明白为什么不工作。
编辑:我注意到我第一次运行它时,它适用于所有任务(仇恨、情感、情绪),但如果我再次尝试运行它,则会出现错误。
【问题讨论】:
-
我无法用 4.5.1 重现这个。您使用的是哪个变压器版本?如果您还没有使用 4.5.1,可以尝试升级它吗?
-
我使用的是 3.1.0 版本。现在有了 4.5.1。我没有问题,代码运行。谢谢@cronoik
-
编辑:使用 4.5.1。版本我也得到了错误。错误出现在我第二次运行代码时,从未在开始时出现。
标签: python error-handling model huggingface-transformers