当前位置: 代码网 > 科技>操作系统>Windows > pycharm通过hf mirror镜像访问huggingface模型(无需翻墙)

pycharm通过hf mirror镜像访问huggingface模型(无需翻墙)

2024年08月02日 Windows 我要评论
window下 pycharm如何通过hf mirror镜像访问huggingface模型,无需翻墙!!!无需翻墙!!

参考: huggingface下载模型的最正确方法

huggingface镜像网站:https://hf-mirror.com (感觉大佬们)

通过修改环境变量访问镜像网站加载模型

import os
os.environ['hf_endpoint'] = 'https://hf-mirror.com'

注意:修改环境变量一定要放到最上方!!!放到 import transformers前修改!!!

完整代码

import os
os.environ['hf_endpoint'] = 'https://hf-mirror.com'
from transformers import autotokenizer

check_point = 'distilbert-base-uncased-finetuned-sst-2-english'
tokenizer = autotokenizer.from_pretrained(check_point)
inputs = [
    'i‘m hunger',
    'nice to meet you, lihua'
]
input = tokenizer(inputs, padding=true, truncation=true, return_tensors='pt')
print('input: ',input)

打印结果

input: {'input_ids': tensor([[  101,  1045,  1520,  1049,  9012,   102,     0,     0,     0],
        [  101,  3835,  2000,  3113,  2017,  1010,  5622, 14691,   102]]), 'attention_mask': tensor([[1, 1, 1, 1, 1, 1, 0, 0, 0],
        [1, 1, 1, 1, 1, 1, 1, 1, 1]])}

(0)

相关文章:

版权声明:本文内容由互联网用户贡献,该文观点仅代表作者本人。本站仅提供信息存储服务,不拥有所有权,不承担相关法律责任。 如发现本站有涉嫌抄袭侵权/违法违规的内容, 请发送邮件至 2386932994@qq.com 举报,一经查实将立刻删除。

发表评论

验证码:
Copyright © 2017-2025  代码网 保留所有权利. 粤ICP备2024248653号
站长QQ:2386932994 | 联系邮箱:2386932994@qq.com