[英]Setting up Visual Studio Code to run models from Hugging Face
I am trying to import models from hugging face and use them in Visual Studio Code.我正在尝试从拥抱脸导入模型并在 Visual Studio Code 中使用它们。 I installed transformers, tensorflow, and torch.
我安装了变压器 tensorflow 和手电筒。 I have tried looking at multiple tutorials online but have found nothing.
我曾尝试在网上查看多个教程,但一无所获。 I am trying to run the following code:
我正在尝试运行以下代码:
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)
However, I get the following error:但是,我收到以下错误:
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'>).
I have already searched online for ways to set up transformers to use in Visual Studio Code but nothing is helping.我已经在网上搜索了设置转换器以在 Visual Studio Code 中使用的方法,但没有任何帮助。
Do you know how to fix this error, or if someone knows how to successfully use models from Hugging Face into my code, it would be appreciated?您是否知道如何解决此错误,或者如果有人知道如何成功地将 Hugging Face 中的模型用于我的代码中,将不胜感激?
This question is a little less about Hugging Face itself and likely more about installation and the installation steps you took (and potentially your program's access to the cache file where the models are automatically downloaded to.).这个问题与 Hugging Face 本身有关,可能更多与安装和您采取的安装步骤有关(以及您的程序可能对模型自动下载到的缓存文件的访问。)。
From what I am seeing either: 1/ your program is unable to access the model 2/ your program is throwing specific value errors in a bit of an edge case从我所看到的:1/您的程序无法访问 model 2/您的程序在一些边缘情况下抛出特定值错误
If 1/ Take a look here: [https://huggingface.co/docs/transformers/installation#cache-setup][1]如果 1/ 看看这里:[https://huggingface.co/docs/transformers/installation#cache-setup][1]
Notice that it the docs walks through where the pre-trained models are downloaded.请注意,文档会遍历预训练模型的下载位置。 Check that it was downloaded here:
C:\Users\username\.cache\huggingface\hub
(of course with your own username on your computer instead. Check in the cache location to make sure it was downloaded? (You can check in the cache locations mentioned.)检查它是否在此处下载:
C:\Users\username\.cache\huggingface\hub
(当然是在您的计算机上使用您自己的用户名。检查缓存位置以确保它已下载?(您可以检查提到的缓存位置。)
Second, if for some reason, there is an issue with downloading, you can try downloading manually and doing it via offline mode (this is more to get it up and running): https://huggingface.co/docs/transformers/installation#offline-mode其次,如果由于某种原因,下载出现问题,您可以尝试手动下载并通过离线模式进行(这更多是为了让它运行起来): https://huggingface.co/docs/transformers/installation #离线模式
Third, if it is downloaded, do you have the right permissions to access the.cache?三、如果是下载的,是否有权限访问.cache? (Try running your program (if it is a program that you trust) on Windows Terminal as an administrator.).
(尝试以管理员身份在 Windows 终端上运行您的程序(如果它是您信任的程序)。)。 Various ways - find one that you're comfortable with, here are a couple hints from Stackoverflow/StackExchange: Opening up Windows Terminal with elevated privileges, from within Windows Terminal or this: https://superuser.com/questions/1560049/open-windows-terminal-as-admin-with-winr
各种方法 - 找到一个你觉得舒服的方法,这里有一些来自 Stackoverflow/StackExchange 的提示: Opening up Windows Terminal with提升权限,从 Windows 终端或这个: Z5E056C500A1C4B6A71010B50D807BADE56//superuser/comquestions/107BADE550B50D807BADE5。 -windows-terminal-as-admin-with-winr
If 2/ I have seen people bring up very specific issues on not finding specific values (not the same as yours but similar) and the issue was solved by installing PyTorch because some models only exist as PyTorch models.如果 2/ 我看到人们在找不到特定值(与您的不同但相似)方面提出了非常具体的问题,并且通过安装 PyTorch 解决了该问题,因为某些型号仅作为 PyTorch 型号存在。 You can see the full response from @YokoHono here: Transformers model from Hugging-Face throws error that specific classes couldn t be loaded
您可以在此处查看@YokoHono 的完整回复: Hugging-Face 的 Transformers model 引发无法加载特定类的错误
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.