1.安装transformers
!pip install transformers
2.调用接口进行情感分析
from transformers import pipeline
classifier = pipeline("sentiment-analysis") # 情感分析
classifier("I've been waiting for a HuggingFace course my whole life.")
No model was supplied, defaulted to distilbert-base-uncased-finetuned-sst-2-english and revision af0f99b (https://huggingface.co/distilbert-base-uncased-finetuned-sst-2-english). Using a pipeline without specifying a model name and revision in production is not recommended. [{'label': 'POSITIVE', 'score': 0.9598048329353333}]
classifier("We are all in the gutter, but some of us are looking at the stars.")
[{'label': 'POSITIVE', 'score': 0.9934802055358887}]文章来源:https://www.toymoban.com/news/detail-543134.html
classifier("Sometimes ever, sometimes never.")
[{'label': 'NEGATIVE', 'score': 0.6318379640579224}]文章来源地址https://www.toymoban.com/news/detail-543134.html
到了这里,关于使用HuggingFace进行情感分类的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!