This project implements a deep learning model using TensorFlow to classify emotions expressed in tweets.
It is based on a guided Coursera project and leverages the dair-ai/emotion dataset available on Hugging Face.
The model is trained to recognize six emotion categories in tweets:
- Joy
- Anger
- Sadness
- Love
- Fear
- Surprise
The project includes text preprocessing, embedding, LSTM model training, and performance evaluation.
- 🔍 Emotion classification from tweet text
- 🧠 LSTM-based deep learning model
- 💬 Tokenization, padding, and word embeddings
- 📊 Confusion matrix and classification report
├── Tweet_Emotion_Recognition.ipynb # Main Jupyter notebook
├── Tweet_Emotion_Recognition.pdf # PDF export of the notebook
├── requirements.txt # Python dependencies
└── README.md # Project documentation
| Category | Tools & Libraries |
|---|---|
| Deep Learning | TensorFlow, Keras |
| NLP | Hugging Face Datasets |
| Visualization | Matplotlib |
| Data Handling | NumPy |
| Development | Jupyter Notebook |
- Python 3.8+
- TensorFlow
- NumPy
- Matplotlib
- Scikit-learn
- Hugging Face Datasets
- Jupyter
Install required packages using:
pip install tensorflow numpy matplotlib scikit-learn datasets jupyter-
Clone the repository:
git clone https://github.com/your-username/tweet-emotion-recognition.git cd tweet-emotion-recognition -
(Optional) Create and activate a virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Open and run the notebook:
jupyter notebook Tweet_Emotion_Recognition.ipynb
The model is a Sequential neural network composed of:
- An Embedding layer (using pre-trained GloVe vectors)
- A Bidirectional LSTM layer with 64 units (returning sequences)
- A second Bidirectional LSTM layer with 32 units
- A Dense layer with ReLU activation
- A Softmax output layer for emotion classification
The model was trained and evaluated on the dair-ai/emotion dataset and achieved:
- Validation Accuracy: ~89.5%
- Test Accuracy: 88.5%
- F1 Score: 88.5%
Results were visualized using a confusion matrix and classification report.
This project is for educational purposes and is based on a guided Coursera project: Coursera: Tweet Emotion Recognition with TensorFlow
Khaled Jamal
LinkedIn