Skip to content
GTHome
All projects

ML Engineer (Solo) · 2024

Open SourceSource-available

Hate Speech Classifier

A machine learning project detecting hate speech and offensive language using a Kenyan dataset, trained with scikit-learn and NLTK.

Pythonscikit-learnNLTKPandasMatplotlib

Source-available

Hate Speech Classifier

Pythonscikit-learnNLTK

Problem

Online platforms in Kenya need automated tools to detect hate speech and offensive language in local-language contexts, where most off-the-shelf models underperform.

Approach

Trained and evaluated text classification models on a Kenyan-focused hate speech dataset using scikit-learn, with NLTK for preprocessing and Pandas/Matplotlib for analysis.

Tech highlights

Python with scikit-learn for model training, NLTK for tokenization and cleaning, Pandas for dataset handling, and Matplotlib for visualizing class distributions and model performance.

Results

Compared four classifiers on 9,614 held-out tweets (of 48,076). Multinomial Naive Bayes scored the highest accuracy, 75.9% (75.9% again after tuning alpha to 0.01), but a macro F1 of only 0.35. Linear SVM, at 69.5% accuracy, had the best macro F1 (0.49). The honest conclusion: accuracy flatters a model that mostly predicts the majority class, so the next step is rebalancing the classes, not more tuning.

Challenges

Handling code-switched Swahili–English text and local slang that standard English tokenizers mangle, and correcting for a heavily imbalanced dataset where neutral and offensive examples vastly outnumbered genuine hate speech, which skewed naive accuracy and forced a focus on precision and recall.

More like this