0% found this document useful (0 votes)
3 views1 page

Program 6

The document outlines a program that utilizes a pre-trained Hugging Face model for sentiment analysis of text. It demonstrates how to load the sentiment analysis pipeline and analyze various sentences, providing labels and scores for each. The output indicates the sentiment classification and confidence scores for the analyzed sentences.

Uploaded by

suhaspr2004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views1 page

Program 6

The document outlines a program that utilizes a pre-trained Hugging Face model for sentiment analysis of text. It demonstrates how to load the sentiment analysis pipeline and analyze various sentences, providing labels and scores for each. The output indicates the sentiment classification and confidence scores for the analyzed sentences.

Uploaded by

suhaspr2004
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Program 6:

Use a pre-trained Hugging Face model to analyze sentiment in text. Assume a


real-world application, Load the sentiment analysis pipeline. Analyze the
sentiment by giving sentences to input.
!pip install transformers

from transformers import pipeline

classifier = pipeline("sentiment-analysis", model="distilbert-base-uncased-


finetuned-sst-2-english")

sentences = [
"This is a great product! I love it.",
"I am very disappointed with this service.",
"The weather is not okay today.but still gotta adjust the place"
]

results = classifier(sentences)
for sentence, result in zip(sentences, results):
print(f"'{sentence}' -> Label: {result['label']}, Score: {result['score']:.3f}")

OUTPUT:
Device set to use cpu
'This is a great product! I love it.' -> Label: POSITIVE, Score: 1.000
'I am very disappointed with this service.' -> Label: NEGATIVE, Score: 1.000
'The weather is not okay today.but still gotta adjust the place' -> Label:
NEGATIVE, Score: 0.990

You might also like