Skip to content

This project applies Convolutional Neural Networks (CNNs) to a Natural Language Processing (NLP) task: classifying emotions from text data.

Notifications You must be signed in to change notification settings

Cs944612/Emotion-Detection-using-CNN

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Emotion Detection using CNN for NLP

πŸ“Œ Project Overview

This project demonstrates how to use Convolutional Neural Networks (CNNs) for emotion classification from text dataβ€”a Natural Language Processing (NLP) task. The model is trained to recognize emotions such as joy, sadness, anger, fear, love, and surprise from short sentences.

🎯 Objectives

  • Preprocess text data (tokenization, padding)
  • Use an Embedding layer to convert words into dense vectors
  • Build a CNN-based model to capture local patterns in text
  • Train and evaluate the model on the dataset
  • Visualize performance and analyze metrics like accuracy, precision, recall, and F1-score

πŸ“‚ Dataset

πŸ›  Tools & Libraries

  • Python
  • TensorFlow / Keras
  • NumPy & Pandas
  • Matplotlib
  • scikit-learn

πŸš€ How CNN fits into NLP

         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
         β”‚     Text Data (NLP)   β”‚
         β”‚ (sentences, words...) β”‚
         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                      β”‚
                      β–Ό
         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
         β”‚     Preprocessing     β”‚
         β”‚ (tokenization,        β”‚
         β”‚  padding, embedding)  β”‚
         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                      β”‚
                      β–Ό
         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
         β”‚   CNN Model (Conv1D)  β”‚
         β”‚  - Convolution        β”‚
         β”‚  - Pooling            β”‚
         β”‚  - Dense Layers       β”‚
         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                      β”‚
                      β–Ό
         β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
         β”‚   Predicted Emotion   β”‚
         β”‚ (joy, anger, etc.)    β”‚
         β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

πŸ“Š Exploratory Data Analysis (EDA)

  • Analyzes distribution of emotion labels (class balance)
  • Inspects sentence lengths
  • Visualizes frequent words (word clouds)

πŸ—οΈ Model Architecture

  • Embedding Layer: Converts tokenized words to dense vectors
  • Conv1D Layer: Captures local n-gram patterns in text
  • GlobalMaxPooling1D: Reduces sequence to fixed-length
  • Dense Layers: Final classification

πŸ“ˆ Training & Evaluation

  • Model trained on the training set, validated on the validation set, and tested on the test set.
  • Performance evaluated using metrics: accuracy, precision, recall, F1-score
  • Training history plotted for visualization

πŸ“‹ Results

  • The trained CNN model achieves strong accuracy on emotion classification tasks.
  • Metrics and visualizations help interpret model performance and common confusions between emotions.

About

This project applies Convolutional Neural Networks (CNNs) to a Natural Language Processing (NLP) task: classifying emotions from text data.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published