Many a time, for real-world projects, emotion recognition is often just the start of the project. That time writing a whole code on that will not only increase time but also efficiency is hindered.
NRCLexicon is an MIT-approved pypi project by Mark M. Bailey which predicts the sentiments and emotion of a given text. The package contains approximately 27,000 words and is based on the National Research Council Canada (NRC) affect lexicon and the NLTK library’s WordNet synonym sets.
To install this module type the below command in the terminal.
pip install NRCLex
Even after the installation of this module, MissingCorpusError may occur while running programs. So it is advised to also install textblob.download_corpora by using the below command on the command prompt.
python -m textblob.download_corpora
- Import the module
- Assign input text
- Create NRCLex object for each input text.
- Apply methods to classify emotions.
|1||emotion.words||Return words list.|
|2||emotion.sentences||Return sentences list.|
|3||emotion.affect_list||Return affect list.|
|4||emotion.affect_dict||Return affect dictionary.|
|5||emotion.raw_emotion_scores||Return raw emotional counts.|
|6||emotion.top_emotions||Return highest emotions.|
|7||emotion.affect_frequencies||Return affect frequencies.|
- Emotional affects measured include the following:
Below is the Implementation.
Based on the above approach, the below example classifies various emotions using top_emotions.
Here a single emotion love is classified using all the methods of NCRLex module.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- Get emotions of images using Microsoft emotion API in Python
- Movie recommendation based on emotion in Python
- Python | Image Classification using keras
- ML | Cancer cell classification using Scikit-learn
- Sentiment Classification Using BERT
- ML | Why Logistic Regression in Classification ?
- ML | Logistic Regression v/s Decision Tree Classification
- OpenCV and Keras | Traffic Sign Classification for Self-Driving Car
- An introduction to MultiLabel classification
- Multi-Label Image Classification - Prediction of image labels
- One-vs-Rest strategy for Multi-Class Classification
- Image Classification with Web App
- Advantages and Disadvantages of different Classification Models
- Python | Create video using multiple images using OpenCV
- Python | Create a stopwatch using clock object in kivy using .kv file
- Image resizing using Seam carving using OpenCV in Python
- Visualizing Tiff File Using Matplotlib and GDAL using Python
- Python | Visualizing O(n) using Python
- Python - Read blob object in python using wand library
- Creating and updating PowerPoint Presentations in Python using python - pptx
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.