当前位置: 首页> 汽车> 维修 > 企业服务平台工程建设云_网络优化排名培训_现在学seo课程多少钱_在百度上怎么发布广告

企业服务平台工程建设云_网络优化排名培训_现在学seo课程多少钱_在百度上怎么发布广告

时间:2025/7/14 3:50:09来源:https://blog.csdn.net/pwp032984/article/details/142876965 浏览次数: 0次
企业服务平台工程建设云_网络优化排名培训_现在学seo课程多少钱_在百度上怎么发布广告

1 需求

需求1:基于pipeline使用预训练模型

需求2:基于BertTokenizer/BertForSequenceClassification使用预训练模型


2 接口


3.1 基于pipeline使用预训练模型

from transformers import pipelinepipeline = pipeline("text-classification", model="./model", tokenizer="./model")
output = pipeline("今天天气不错")
print(output)

3.2 

text = "今天天气不错"# 第一步:数据预处理(Raw text -》Input IDs)
from transformers import BertTokenizertokenizer = BertTokenizer.from_pretrained("./model")
input = tokenizer(text, padding=True, truncation=True, return_tensors="pt")
print(input)# 第二步:模型调用(Input IDs -》Logits)
from transformers import BertForSequenceClassificationmodel = BertForSequenceClassification.from_pretrained("./model")
output = model(**input)
logits = output.logits
print(logits)# 第三步:结果后处理(Logits -》Predictions)
import torchpredictions = torch.nn.functional.softmax(logits, dim=-1)
predictions_class = torch.argmax(predictions).item()
print(predictions_class)
print(model.config.id2label.get(predictions_class))

4 参考资料

transformers库的使用【一】——pipeline的简单使用_transformer pipeline-CSDN博客

【人工智能】Transformers之Pipeline(十七):文本分类(text-classification)_文本分类模型排名-CSDN博客

【人工智能】Transformers之Pipeline(十八):文本生成(text-generation)_pipeline('text2text-generation')-CSDN博客

关键字:企业服务平台工程建设云_网络优化排名培训_现在学seo课程多少钱_在百度上怎么发布广告

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: