Now Reading
How I Created A Python Package – text2emotion

How I Created A Python Package – text2emotion

Did you ever wonder about how important or useful it is to know the emotions of a person behind his thoughts? Or how can humans benefit if we know about the emotions of a person? No doubt, a human can itself understand the emotions by reading the text.

But in this digital era where we have an ocean of data-generating everyday through text, messages, social media, etc. is it possible for humans to analyze the emotions of people through manually reading everything? Obviously not! This is when text2emotion comes into the picture.

Follow us on Google News>>

Table Of Contents:

  1. what is text2emotion?
  2. Sample Industrial Use Case
  3. How does it work?
  4. How to use it?

1. What is text2emotion?

text2emotion is a python package, developed by me along with three other colleagues with a motivation of uncovering hidden human emotions behind the text. One very obvious question that would come in your mind can be how this is different from sentiment analysis?

Well, sentimental analysis just interprets and classifies text as positive, negative or natural, whereas text2emotion helps you to classify the tone of text into five basic human emotions i.e Happy, Angry, Surprise, Fear and Sad. 

To summarize, text2emotion is the python package which will help you to extract the emotions from the content.

Looking for a job change? Let us help you.
  • Processes any textual message and recognize the emotions embedded in it.
  • Compatible with 5 different emotion categories as Happy, Angry, Sad, Surprise and Fear.

2. Sample Industrial Use Case

Let us now discuss a sample industrial use case where determining emotion can play a very important role. This will give us more clarity.

E-Commerce Industry: Customer Engagement Endpoint

An E-Commerce industry receives input from customers through various sources such as textual data from chat-bots, logs from contact centres, emails etc. One can assume that a customer may be angry initially while he complaints, but the progression of his tone, tracking his emotions throughout can be very helpful. If the customer is still angry when the conversation ends, that is bad news. If he is happy, then that’s a success from the customer service end.

Tracking these tone signals can help Customer Service Managers improve how their teams interact with customers. Do the agents need more training in content or in communication style? 

We can surely customize and make more improvements in text2emotion package to develop it into a full-fledged service that suits this use case.

I hope, by this time you might have got a bit of clarity about the importance of knowing the emotions of a person.

3. How does it work?

Now, let’s talk about bit technical details and working of this package.


At first, we have the major goal to perform data cleaning and make the content suitable for emotion analysis.

  • Remove the unwanted textual part from the message.
  • Perform the natural language processing techniques.
  • Bring out the well-pre-processed text from the text pre-processing.


Detect emotion from every word that we got from pre-processed text and take a count of it for further analytical process.

  • Find the appropriate words that express emotions or feelings.
  • Check the emotion category of each word.
  • Store the count of emotions relevant to the words found.


After emotion investigation, there is the time of getting the significant output for the textual message we input earlier.

  • The output will be in the form of a dictionary.
  • There will be keys as emotion categories and values as an emotion score.
  • Higher the score of a particular emotion category, we can conclude that the message belongs to that category.

4. How to use it?

Check Google Colab Demo:

App Deployment

Here’s the demo of code implementation with Streamlit App for the users.

  1. Enter the text.

Enter the text in the box and click on submit button.

2. Hit the submit button.

3. Tada!! Get the output in visual form.

It identifies the emotions in the text and gives you output in visual form accordingly.

Check Demo Web App below:

Let’s get hands-on experience on the library.

For more information visit:

What Do You Think?

Join Our Discord Server. Be part of an engaging online community. Join Here.

Subscribe to our Newsletter

Get the latest updates and relevant offers by sharing your email.

Copyright Analytics India Magazine Pvt Ltd

Scroll To Top