赞
踩
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]])}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。