繁体   English   中英

从拥抱面 model 加载重量时出错

[英]Error loading weights from a Hugging Face model

我正在使用变压器,我已经加载了 model 并且它工作正常:

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 模型,你可以在这里看到,所以我不明白为什么不工作。

编辑:我注意到我第一次运行它时,它适用于所有任务(仇恨、情感、情绪),但如果我再次尝试运行它,则会出现错误。

# PT
model = AutoModelForSequenceClassification.from_pretrained(MODEL) 
model.save_pretrained(MODEL)
tokenizer.save_pretrained(MODEL)

将第三行添加到此部分,重命名或删除您已经拥有的 model 文件夹,然后重试。 这一次它确实应该不止一次地工作。 我希望这能让你滚动!

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM