下载Huggingface的cardiffnlp/twitter-roberta-base-sentiment模型

发布于:2025-02-16 ⋅ 阅读:(36) ⋅ 点赞:(0)

因 Huggingface 为国外网站,我们从该网站下载模型和数据集时总会因网络不稳定、限速等问题下载模型和数据失败。

法一:网页下载cardiffnlp/twitter-roberta-base-sentiment at main

法二:huggingface-cli下载

python版本至少为3.8

1.进入python环境:

我的python在D:\anaconda\envs\hf_env中

查看python版本

2.huggingface-cli下载

(1)安装依赖

pip install -U huggingface_hub

(2)设置环境变量

# Windows
$env:HF_ENDPOINT = "https://hf-mirror.com"
Add-Content -Path $PROFILE -Value '$env:HF_ENDPOINT = "https://hf-mirror.com"'
#若Add-Content命令执行时提示:未能找到“xxx”路径的一部分。则执行如下命令
new-item -path $profile -itemtype file -force #新建该配置文件
Add-Content -Path $PROFILE -Value '$env:HF_ENDPOINT = "https://hf-mirror.com"' #写入配置到该文件
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser #设置执行策略以便配置文件可加载

(3)下载模型和数据

#下载模型
huggingface-cli download --resume-download <modelName> --local-dir <本地路径>
#示例
huggingface-cli download --resume-download gpt2 --local-dir /data/gpt2

#下载数据
huggingface-cli download --repo-type dataset --resume-download <datasetName> --local-dir <本地路径>
#示例
huggingface-cli download --repo-type dataset --resume-download wikitext --local-dir wikitext

 下载成功:

huggingface下载 | 文档中心 - 趋动云

点击链接查看和 Kimi 智能助手的对话 https://kimi.moonshot.cn/share/cuoa7fschmtp1t280qug