0% found this document useful (0 votes)
2 views3 pages

Program6 Lab

Uploaded by

Shreyas R
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)
2 views3 pages

Program6 Lab

Uploaded by

Shreyas R
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

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.
Aim
To implement sentiment analysis on customer reviews using the Hugging Face Transformers
library in Python.
Objective
 To understand the concept of sentiment analysis.
 To use a pre-trained NLP model for classifying text as Positive or Negative.
 To analyze real-world customer feedback automatically.
Theory
Sentiment Analysis
Sentiment Analysis is a Natural Language Processing (NLP) technique used to determine
whether a piece of text expresses positive, negative, or neutral sentiment. It is widely used in:
 Customer feedback analysis
 Product review evaluation
 Social media monitoring
 Market research
Transformers Library
The transformers library by Hugging Face provides pre-trained models for various NLP tasks,
such as:
 Sentiment Analysis
 Text Classification
 Question Answering
 Text Generation
In this program, we use the pipeline() function, which simplifies the use of pre-trained models.
Pipeline
The pipeline("sentiment-analysis") automatically loads a pre-trained sentiment classification
model and tokenizer.
The model:
 Takes text as input
 Predicts sentiment (POSITIVE / NEGATIVE)
 Returns confidence score
Algorithm
1. Install the required library (transformers).
2. Import the pipeline function from the transformer’s module.
3. Load the pre-trained sentiment analysis model.
4. Define a function to analyze sentiment.
5. Provide customer review inputs.
6. Pass each review to the sentiment analyzer.
7. Display sentiment label and confidence score.
Source Code:
OUTPUT:

Result
Thus, the sentiment analysis model was successfully implemented using the Hugging Face
Transformers library, and customer reviews were classified as Positive or Negative with
confidence scores.
Applications
 E-commerce product review analysis
 Brand reputation monitoring
 Social media sentiment tracking
 Automated feedback evaluation

You might also like