SENTIMENT ANALYSIS USING HUGGING FACE TRANSFORMERS PIPELINE.

The Huggingface transformer is a popular library in python which are useful in many variety of Natural language processing(NLP) and Natural language understanding(NLU) tasks. As a human beings , we normally express each and every moments through emotions in all our communications. Emotions are also known as sentiments. The task of Sentiment Analysis is hence to determine emotions in text. Sentiment analysis are used for expressing a feeling, emotion or a mood in the form of text. It also has wide applications in different sources of information, including product reviews, online social media, survey feedback, etc.

Here we are going to implement Sentiment analysis pipeline with python.  So, the pipeline are a great and easy way to use models for inference. These pipelines are objects that abstract most of the complex code from the library, offering a simple API dedicated to several tasks, including sentiment analysis, question answering, masked language modeling, named entity recognition,  summarization.

Let’s go through the simple code. Firstly, let’s  install transformers

pip install transformers

Now we are ready to use transformers library . Let’s now import pipeline library

from transformers import pipeline

Now we’ll go through the actual code where we have created an instance of the class pipeline and have passed an argument “sentiment-analysis” which is saved as variable.

senti_pipeline = pipeline(“sentiment-analysis”)
senti_pipeline = (“I am very excited to work in Zummitlabs.”)
o/p - label:'positive'

senti_pipeline = (“ I am sad that am able to work only for 4 hours per day.”)
o/p - label:'negative'

Conclusion:

So here we can see the power of pipelines by hugging face transformers which can be used in various platforms.

Leave a Comment

Your email address will not be published. Required fields are marked *