国内使用transformers库的方法
使用镜像网站
import os
os.environ["HF_ENDPOINT"] = "https://hf-mirror.com"
from transformers import pipeline
classifier = pipeline("sentiment-analysis", framework="pt", trust_remote_code=True)
result = classifier(
"We are very happy to introduce pipeline to the transformers repository."
)
print(result)
使用本地模型
from transformers import (
pipeline,
DistilBertTokenizer,
DistilBertForSequenceClassification,
)
path = "E:\\temp\\models\\models--distilbert--distilbert-base-uncased-finetuned-sst-2-english\\snapshots\\714eb0fa89d2f80546fda750413ed43d93601a13"
tokenizer = DistilBertTokenizer.from_pretrained(path)
model = DistilBertForSequenceClassification.from_pretrained(path)
classifier = pipeline(
"sentiment-analysis", model=model, tokenizer=tokenizer, framework="pt"
)
result = classifier(
"We are very happy to introduce pipeline to the transformers repository."
)
print(result)
最后更新于1年前
本文由人工编写,AI优化,转载请注明原文地址: 国内使用transformers库的方法
推荐阅读
大模型完全指南:开源与商业模型、本地部署、微调实战
3312025-11-02
深信服VPN客户端下载:EasyConnect与aTrust零信任访问指南
18992025-10-17
程序员常用技术大全:从编程语言到开发工具完整指南
4992025-10-19
Windows系统PyTorch安装教程:CUDA 12.1环境配置与TorchText版本兼容性指南
24642025-10-08
IntelliJ IDEA常见问题解决方案大全:服务面板、Maven报错、启动故障处理
3542026-04-14
使用Cesium.js加载vtu格式(UnstructuredGrid)的文件
282025-12-06