使用HuggingFace进行情感分类

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}]

classifier("Sometimes ever, sometimes never.")

[{'label': 'NEGATIVE', 'score': 0.6318379640579224}]

你可能感兴趣的:(python,nlp)