Ticker

6/recent/ticker-posts

BAIL657C - Generative AI Lab 6

 

Program 6:

Aim:

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.

Theory:

Sentiment Analysis using a Pre-trained Hugging Face Model

Sentiment analysis is a Natural Language Processing (NLP) technique used to determine the emotional tone of a piece of text. It helps identify whether the text expresses a positive, negative, or neutral opinion.

In real-world applications, sentiment analysis is widely used to analyze customer reviews, social media posts, product feedback, and survey responses. Companies use it to understand customer satisfaction and public opinion about their products or services.

Hugging Face Transformers provides many pre-trained language models that can perform sentiment analysis without training a model from scratch. These models are trained on large text datasets and can quickly classify the sentiment of new text.

The Hugging Face pipeline is a simple interface that allows users to apply NLP tasks such as sentiment analysis with just a few lines of code. By loading the sentiment-analysis pipeline, we can input sentences and the model will predict whether the sentiment is positive or negative, along with a confidence score.

Thus, using a pre-trained Hugging Face model makes sentiment analysis fast, efficient, and easy to implement in real-world applications.

Program:

1. Import Required Library

First import the Hugging Face pipeline from the transformers library.

2. Load the Pre-trained Sentiment Analysis Model

Load the sentiment analysis pipeline.

Hugging Face automatically loads a pre-trained model (DistilBERT) that is trained to classify text as POSITIVE or NEGATIVE.

3. Provide Input Sentences

Give some sentences as input for analysis.

4. Perform Sentiment Analysis

Pass the sentences to the pipeline.

5. Display the Results

Print the sentiment and confidence score.

6. Output

Post a Comment

0 Comments