我正在尝试从拥抱面导入模型,并在Visual代码中使用它们。我安装了变压器tensorflow和手电筒。我试过在网上查看多个教程,但什么也没有发现。我试图运行以下代码:
from transformers import pipeline
classifier = pipeline('sentiment-analysis')
result = classifier("I hate it when I'm sitting under a tree and an apple hits my head.")
print(result)但是,我得到以下错误:
No model was supplied, defaulted to distilbert-base-uncased-finetuned-sst-2-english and revision af0f99b (https://huggingface.co/distilbert-base-uncased-finetuned-sst-2-english).
Using a pipeline without specifying a model name and revision in production is not recommended.
Traceback (most recent call last):
File "c:\Users\user\Desktop\Artificial Intelligence\transformers\Workshops\workshop_3.py", line 4, in <module>
classifier = pipeline('sentiment-analysis')
File "C:\Users\user\Desktop\Artificial Intelligence\transformers\src\transformers\pipelines\__init__.py", line 702, in pipeline
framework, model = infer_framework_load_model(
File "C:\Users\user\Desktop\Artificial Intelligence\transformers\src\transformers\pipelines\base.py", line 266, in infer_framework_load_model
raise ValueError(f"Could not load model {model} with any of the following classes: {class_tuple}.")
ValueError: Could not load model distilbert-base-uncased-finetuned-sst-2-english with any of the following classes: (<class 'transformers.models.auto.modeling_auto.AutoModelForSequenceClassification'>, <class 'transformers.models.auto.modeling_tf_auto.TFAutoModelForSequenceClassification'>, <class 'transformers.models.distilbert.modeling_distilbert.DistilBertForSequenceClassification'>, <class 'transformers.models.distilbert.modeling_tf_distilbert.TFDistilBertForSequenceClassification'>).我已经在网上搜索了设置在Visual代码中使用的转换器的方法,但是没有任何帮助。
您知道如何修复此错误吗?或者,如果有人知道如何在我的代码中成功地使用模型,我们将不胜感激。
发布于 2022-09-27 21:07:04
这个问题不是关于拥抱面板本身,而是更多地涉及安装和您采取的安装步骤(可能是您的程序访问模型自动下载到的缓存文件)。
从我看到的情况来看: 1/您的程序无法访问模型2/您的程序正在抛出一些边缘情况下的特定值错误。
如果1/请看这里: https://huggingface.co/docs/transformers/installation#cache-setup
请注意,文档在下载经过预先培训的模型的位置。检查它是在这里下载的:C:\Users\username\.cache\huggingface\hub (当然,你的电脑上有你自己的用户名)。签入缓存位置以确保已下载?(您可以签入提到的缓存位置。)
第二,如果由于某种原因,下载有问题,您可以尝试手动下载并通过脱机模式进行下载(更多的是让它启动和运行):https://huggingface.co/docs/transformers/installation#offline-mode
第三,如果下载了它,您是否有访问.cache的正确权限?(尝试以管理员身份在Windows终端上运行程序(如果是您信任的程序)。)各种方法--找到您满意的方法,下面是Stackoverflow/StackExchange的几个提示:Opening up Windows Terminal with elevated privileges, from within Windows Terminal或这个:https://superuser.com/questions/1560049/open-windows-terminal-as-admin-with-winr
如果我看到人们提出了非常具体的问题,比如找不到特定的值(与您的值不一样,但是很相似),那么通过安装PyTorch就可以解决这个问题,因为有些模型只作为PyTorch模型存在。您可以在@YokoHono这里看到完整的回复:Transformers model from Hugging-Face throws error that specific classes couldn t be loaded
https://stackoverflow.com/questions/73873233
复制相似问题