Skip to content

Emotion Detection App

I built an application that detects and classifies emotions in text inputs using a fine-tuned NLP model (1) — and you can try it live at the bottom of this page.

The app uses Hugging Face Transformers (2) and a Gradio interface (3) to classify text into six emotions: anger, fear, joy, love, sadness, and surprise.

  1. NLP models are mathematical algorithms designed to understand, interpret, and generate human language. They power applications like chatbots, language translation, and sentiment analysis.
  2. Hugging Face Transformers are advanced NLP models that enable computers to perform tasks like text generation, translation, and question answering. They provide a flexible, open-source library for implementing and fine-tuning these models.
  3. Gradio interfaces are user-friendly tools for creating interactive demos of machine learning models. They allow developers to build and share web-based interfaces that let users input data and see model predictions in real-time.

Motivation

The Emotion dataset on Hugging Face includes English Twitter messages labeled with six basic emotions: anger, fear, joy, love, sadness, and surprise.

I fine-tuned a pre-trained DistilBERT model on this dataset and built a user-friendly interface using Gradio, deployed on Hugging Face Spaces.

The prediction quality can be improved by fine-tuning with better resources (I used Google Colab for this project).

The project is modular and adaptable — you can modify it to explore other models and fine-tuning techniques.

Project Overview

  • Tools & Technologies
    • Hugging Face Transformers, Gradio, PyTorch, Pandas, Matplotlib
  • Steps Involved
    1. Dataset Selection and Exploration: Understanding the structure and distribution of the Emotion dataset.
    2. Model Selection: Using DistilBERT for its efficiency in text classification tasks.
    3. Model Fine-tuning: Enhancing the model's performance by training on the Emotion dataset.
    4. Model Evaluation: Assessing the model using accuracy, precision, recall, and F1-score.
    5. Uploading Model: Sharing the fine-tuned model on Hugging Face.
    6. Gradio Interface Development: Creating a user-friendly interface for the model.
    7. Deployment: Making the app accessible on Hugging Face Spaces.

All steps are consolidated in a single Jupyter Notebook, making it accessible and modifiable for anyone interested in emotion detection or similar NLP tasks.

Project Artefacts