This project focuses on classifying emotions from text using the DistilBERT model, implemented in both PyTorch and TensorFlow. The dataset used is the "GoEmotions" dataset, which contains a variety of emotional labels.
-
Data Loading and Preprocessing:
- Loads the "GoEmotions" dataset using the Hugging Face
datasetslibrary. - Filters the data to remove multi-label entries.
- Maps labels to a string format for better visualization and understanding.
- Loads the "GoEmotions" dataset using the Hugging Face
-
Data Visualization:
- Visualizes class distribution using bar charts to observe any data imbalances.
-
Model Training:
- Implements DistilBERT for sequence classification in both PyTorch and TensorFlow frameworks.
- Trains the model on the preprocessed dataset, using accuracy as the evaluation metric.
- Includes callbacks to save the model to the Hugging Face Hub and to monitor metrics during training.
-
Evaluation:
- Evaluates the trained models on the validation set and displays a Confusion Matrix to visualize model performance across different emotions.
-
Emotion Prediction:
- The model can classify user input into predefined emotion categories using a text classification pipeline.
- A command-line interface allows users to interact with the model, input sentences, and receive emotion predictions.
You can use these models for emotion classification in your own projects.
To use the PyTorch model for emotion classification, you can use the following code snippet:
from transformers import pipeline
pipe = pipeline("text-classification", model="tuhanasinan/go-emotions-distilbert-pytorch")To use the TensorFlow model for emotion classification, you can use the following code snippet:
from transformers import pipeline
pipe = pipeline("text-classification", model="tuhanasinan/go_emotions-distilbert-tensorflow")Here are the links to the dataset and pre-trained and fine-tuned models used in this project:
- Dataset: GoEmotions Dataset
- Distilbert Model:DistilBERT
- PyTorch Model: go-emotions-distilbert-pytorch
- TensorFlow Model: go-emotions-distilbert-tensorflow