【发布时间】:2021-11-02 23:42:56
【问题描述】:
我正在尝试使用thishuggingface 模型并一直按照提供的示例进行操作,但在加载标记器时出现错误:
from transformers import AutoTokenizer
task = 'sentiment'
MODEL = f"cardiffnlp/twitter-roberta-base-{task}"
tokenizer = AutoTokenizer.from_pretrained(MODEL)
OSError:无法为“cardiffnlp/twitter-roberta-base-sentiment”加载标记器。确保:
“cardiffnlp/twitter-roberta-base-sentiment”是“https://huggingface.co/models”上列出的正确模型标识符
或“cardiffnlp/twitter-roberta-base-sentiment”是包含相关标记器文件的目录的正确路径
我觉得非常奇怪的是,我能够多次运行我的脚本,但在一段时间后遇到了错误,而我不记得在此期间进行了任何更改。有谁知道这里的解决方案是什么?
编辑:这是我的整个脚本:
from transformers import AutoTokenizer
from transformers import AutoModelForSequenceClassification
from transformers import TFAutoModelForSequenceClassification
import numpy as np
from scipy.special import softmax
import csv
import urllib.request
task = 'sentiment'
MODEL = f"nlptown/bert-base-multilingual-uncased-{task}"
tokenizer = AutoTokenizer.from_pretrained(MODEL)
labels = ['very_negative', 'negative', 'neutral', 'positive', 'very_positive']
model = AutoModelForSequenceClassification.from_pretrained(MODEL)
model.save_pretrained(MODEL)
text = "I love you"
encoded_input = tokenizer(text, return_tensors='pt')
output = model(**encoded_input)
scores = output[0][0].detach().numpy()
scores = softmax(scores)
print(scores)
当我运行model.save_pretrained(MODEL) 时,错误似乎开始发生,但这可能是巧合。
【问题讨论】:
-
变形金刚版?
-
版本 4.10.0 @cronoik
-
我还尝试了另一个model,我认为一旦我运行
model.save_pretrained(MODEL),这个错误就会开始发生。我将编辑我的问题并添加我的整个脚本 -
是的,请。我无法使用您发布的代码重现此问题。
-
即使你的脚本也不会对我造成错误。也许你应该重置你的 python 会话?
标签: python huggingface-transformers