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.
- 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
- Source: Kaggle - Emotions Dataset for NLP
- Format: CSV files with two columns:
text
: input sentence/phraseemotion
: target label (emotion category)
- Python
- TensorFlow / Keras
- NumPy & Pandas
- Matplotlib
- scikit-learn
βββββββββββββββββββββββββ
β Text Data (NLP) β
β (sentences, words...) β
ββββββββββββββ¬βββββββββββ
β
βΌ
βββββββββββββββββββββββββ
β Preprocessing β
β (tokenization, β
β padding, embedding) β
ββββββββββββββ¬βββββββββββ
β
βΌ
βββββββββββββββββββββββββ
β CNN Model (Conv1D) β
β - Convolution β
β - Pooling β
β - Dense Layers β
ββββββββββββββ¬βββββββββββ
β
βΌ
βββββββββββββββββββββββββ
β Predicted Emotion β
β (joy, anger, etc.) β
βββββββββββββββββββββββββ
- Analyzes distribution of emotion labels (class balance)
- Inspects sentence lengths
- Visualizes frequent words (word clouds)
- 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
- 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
- The trained CNN model achieves strong accuracy on emotion classification tasks.
- Metrics and visualizations help interpret model performance and common confusions between emotions.