Hate Speech Detection

A Logistic Regression text classifier for hate-speech detection, using SMOTE to address class imbalance.

Abstract illustration of imbalanced class bars being balanced, next to a logistic curve.
My role
Data Science Intern
Type
Internship
Timeline
Apr — May 2024
Status
Internship project

Stack

  • Python
  • scikit-learn
  • Logistic Regression
  • SMOTE
  • NLP preprocessing

Reported results

  • 92%

    Reported classification accuracy

    Dataset-dependent. Per-class precision and recall matter more for the minority class.

On this page
  1. Overview
  2. The problem
  3. Pipeline
  4. Approach
  5. Results
  6. Limitations

Overview

The second NLP project from my Personifwy internship: a supervised classifier for detecting hate speech in text.

The central challenge was class imbalance, which I addressed with SMOTE before training. The model reached a reported 92% classification accuracy.

The problem

Hate-speech detection is a text-classification task with two complications: the language is highly contextual, and hateful examples are usually a minority of the data. A model trained naïvely on imbalanced data can look accurate while rarely identifying the class that matters most.

Pipeline

Balancing the classes before training was the key step.

5 layers · select a layer for details

  1. Input Labelled text

    Text samples labelled for hate speech, with the hateful class in the minority.

  2. Preprocess NLP preprocessing

    Cleaning and normalizing text before feature extraction.

    • Python
  3. Balance SMOTE oversampling

    Synthetic minority-class examples reduce the imbalance the model sees during training.

    • SMOTE
  4. Model Logistic Regression

    An interpretable linear classifier.

    • scikit-learn
    • Logistic Regression
  5. Output Predicted class

    Evaluated with classification accuracy.

Approach

Preprocessing

Text was cleaned and normalized with standard NLP preprocessing before being converted into numeric features.

Handling class imbalance with SMOTE

SMOTE (Synthetic Minority Over-sampling Technique) creates synthetic examples of the minority class by interpolating between existing examples in feature space. Balancing the classes gives the classifier more minority-class examples to learn from, instead of letting the majority class dominate training.

Logistic Regression

Logistic Regression is a linear model that estimates the probability that a piece of text belongs to a class. It is fast, well understood, and its coefficients are interpretable — useful for inspecting which terms drive a prediction.

Results

The model achieved a reported 92% classification accuracy.

Limitations

  • Accuracy can mislead on imbalanced data. Per-class precision, recall, and F1 score say much more about how well the minority class is detected.
  • Oversampling needs care. SMOTE should be applied only to training data (within each cross-validation fold) so that evaluation reflects real, unseen examples — something I'd make explicit in any follow-up write-up.
  • Context is hard. Sarcasm, reclaimed terms, and coded language are difficult for bag-of-words style models. This project is a study in text classification, not a content-moderation system, and its performance depends on the dataset and its labelling guidelines.
Abstract illustration of text messages turning into a TF-IDF matrix and an SVM decision boundary. Internship project

Machine learning Internship

SMS Spam Classification

An SVM text classifier that separates spam from legitimate SMS messages using TF-IDF features, tuned with GridSearchCV.

  • Python
  • scikit-learn
  • SVM
  • TF-IDF
  • and 2 more
Abstract illustration of a clinical dashboard with intake form, schedule, and SOAP-note panels. Contains no real data. In production

Healthcare software Professional

EMR & Patient Intake Platform

A production Electronic Medical Record platform covering patient intake, clinical documentation, scheduling, billing, and practice administration.

  • Python
  • Django
  • Django REST Framework
  • JavaScript
  • and 7 more
Login I Lanexis PVT LTD - customer.lanexis.com Completed and deployed

Business platform Client project

Lanexis Customer Portal

A B2B customer portal I planned, designed, built, and deployed end to end Django backend, React Native/Expo app, Google Sheets integration, and AWS infrastructure.

  • Django
  • Django REST Framework
  • React Native
  • Expo
  • and 7 more

→Get in touch

Working on something similar?

I’m happy to talk through the problem, the trade-offs, and how I’d approach it.