【问题标题】:OSError when loading tokenizer for huggingface model为拥抱脸模型加载标记器时出现 OSError
【发布时间】: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


【解决方案1】:

我刚刚遇到了同样的问题。正如您所指出的,这似乎是 model.save_pretrained() 的一个错误。

我能够通过删除保存模型的目录 (cardiffnlp/) 并再次运行来解决问题没有 model.save_pretrained()

不确定您的应用程序是什么。对我来说,每次重新下载模型大约需要 5 秒,这是可以接受的。

【讨论】:

    猜你喜欢
    • 2022-01-04
    • 2021-08-08
    • 1970-01-01
    • 2020-10-26
    • 2022-08-15
    • 2022-01-17
    • 2020-12-18
    • 2021-12-12
    • 2020-09-30
    相关资源
    最近更新 更多