text2emotion: Uncovering human emotions from textual data in Python
By: Karan Bilakhiya
Tags: NLP, Emotion Analysis, Sentiment Analysis, Naturallanguageprocessing, Data Science

Introduction

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.

Table Of Contents:

what is text2emotion? Sample Industrial Use Case How does it work? 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.

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.

A. TEXT PRE-PROCESSING

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.

B. EMOTION INVESTIGATION

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.

C. EMOTION ANALYSIS

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 Collab Demo:

Google Collab : text2emotion

App Deployment

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

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.

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

For more information visit:

text2emotion Documentation