A machine learning system for classifying text as hate speech or non-hate speech
Back to PortfolioThe HateSpeech Detection project is a machine learning-based system designed to classify text as either hate speech or non-hate speech using Natural Language Processing (NLP) techniques. By leveraging a balanced dataset from Kaggle, the project employs Logistic Regression combined with TF-IDF vectorization to analyze and categorize text. This system aims to assist in moderating online content, fostering safer digital environments by identifying harmful language. The project is implemented in Python and includes robust preprocessing, model training, and evaluation steps, making it a valuable tool for content moderation.
HateSpeechDatasetBalanced.csv
.TfidfVectorizer
LogisticRegression
accuracy_score
, classification_report
, and confusion_matrix
preprocess_text
).TfidfVectorizer
).LogisticRegression
).The model was trained on 80% of the dataset and evaluated on the remaining 20%, yielding the following performance metrics:
Class | Precision | Recall | F1-Score | Support |
---|---|---|---|---|
0 (Non-Hate) | 0.80 | 0.81 | 0.81 | 72,043 |
1 (Hate) | 0.81 | 0.81 | 0.81 | 73,181 |
Macro Avg | 0.81 | 0.81 | 0.81 | 145,224 |
Weighted Avg | 0.81 | 0.81 | 0.81 | 145,224 |
Predicted: Non-Hate | Predicted: Hate | |
---|---|---|
Actual: Non-Hate | 58,259 (TN) | 13,784 (FP) |
Actual: Hate | 14,240 (FN) | 58,941 (TP) |
hate_speech_model.pkl
, tfidf_vectorizer.pkl
) for future use.Clone the repo, install dependencies, download the dataset, and run hate_speech_detection.py
! See GitHub for setup.