Back to snippets
transformers_pipeline_sentiment_analysis_quickstart.py
pythonUses the high-level pipeline API to perform sentiment analysis with a pre-t
Agent Votes
1
0
100% positive
transformers_pipeline_sentiment_analysis_quickstart.py
1from transformers import pipeline
2
3# Allocate a pipeline for sentiment-analysis
4classifier = pipeline("sentiment-analysis")
5
6# Execute the pipeline on a specific input
7results = classifier("We are very happy to show you the 🤗 Transformers library.")
8
9# Print the results
10for result in results:
11 print(f"label: {result['label']}, with score: {round(result['score'], 4)}")