从 Hugging Face 模型加载权重时出错
Error loading weights from a Hugging Face 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 模型,如您所见here,所以我不明白为什么不起作用。
编辑:我注意到我第一次 运行 它时,它适用于所有任务(仇恨、情感、情感),但如果我再次尝试 运行 它,那么我得到错误。
# PT
model = AutoModelForSequenceClassification.from_pretrained(MODEL)
model.save_pretrained(MODEL)
tokenizer.save_pretrained(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 模型,如您所见here,所以我不明白为什么不起作用。
编辑:我注意到我第一次 运行 它时,它适用于所有任务(仇恨、情感、情感),但如果我再次尝试 运行 它,那么我得到错误。
# PT
model = AutoModelForSequenceClassification.from_pretrained(MODEL)
model.save_pretrained(MODEL)
tokenizer.save_pretrained(MODEL)
将第三行添加到此部分,重命名或删除您已有的模型文件夹,然后重试。这次确实应该不止一次起作用。我希望这能让你滚动!