Toxic Comment Detection

Detection of Toxic Comments and Minimization of Unintended Model Bias — B.Sc. Thesis (Grade: 10.0/10.0)

Python TensorFlow NLP Ensemble B.Sc. Thesis Top 6% Kaggle
Toxic Comment Detection — Academic Poster Overview

Objective

Research goal and dataset overview

Investigated and predicted toxicity in online comments using Deep Learning, with a primary focus on mitigating unintended machine learning bias against specific demographic and identity subgroups (race, gender, religion, etc.).

Utilized Kaggle's "Jigsaw Unintended Bias in Toxicity Classification" dataset, containing approximately 1.8 million annotated public comments — a highly imbalanced dataset with 92% non-toxic and 8% toxic samples.

Data & Preprocessing

Maximizing vocabulary coverage through extensive text cleaning

1.8M
Annotated public comments
15.82% → 56.92%
Embedding vocabulary coverage improvement
99.7%
Total words covered after preprocessing
300D
Pre-trained embeddings: FastText & GloVe

Performed extensive text cleaning and preprocessing to maximize vocabulary coverage. Leveraged pre-trained word embeddings utilizing FastText (300D) and GloVe (300D) to accurately capture semantic meaning across the corpus.


Methodology & Architectures

Designed, trained, and evaluated 16 distinct Neural Network architectures

Recurrent Neural Networks

Bidirectional architectures capturing long-range sequential dependencies in text.

6 LSTM · 6 GRU architectures
Varying layers & neuron counts
Bidirectional context in both directions

Convolutional Neural Networks

TextCNN capturing local n-gram features through parallel convolutions.

5 parallel convolution layers
Varying filter sizes for multi-scale features
Efficient local text pattern extraction

Transformers

State-of-the-art sequence-to-sequence models with self-attention.

BERT · RoBERTa · GPT-2
Fine-tuned for toxicity classification
Complex contextual understanding via self-attention

Ensemble Learning

Weighted average combination of top-performing models.

RoBERTa (0.4) + BiLSTM (0.2)
GPT-2 (0.2) + BiGRU (0.2)
Correcting individual model errors

Bias Mitigation & Evaluation

Ensuring the model does not unfairly penalize frequently targeted identities

Addressed the highly imbalanced dataset (92% non-toxic, 8% toxic) by utilizing specialized evaluation metrics designed to measure unintended model bias against specific demographic and identity subgroups.

🎯

Subgroup AUC

Measures model performance specifically on comments mentioning identity subgroups (e.g., race, gender, religion), ensuring the model does not underperform on protected groups.

BPSN AUC

Background Positive, Subgroup Negative — evaluates whether the model incorrectly flags non-toxic comments mentioning identity terms as toxic, penalizing false positives on subgroup mentions.

BNSP AUC

Background Negative, Subgroup Positive — evaluates whether the model misses toxic comments directed at identity groups, penalizing false negatives on targeted harassment.


Results

Ensemble model performance and competition standing

0.94233

Private AUC Score — Ensemble Model

Top 6%
Worldwide ranking
165 / 2,646
Competition placement
10.0 / 10.0
Thesis grade

The final Ensemble Model — combining RoBERTa (0.4 weight), BiLSTM (0.2 weight), GPT-2 (0.2 weight), and BiGRU (0.2 weight) — achieved the highest performance, leveraging a weighted average technique to correct individual model errors and boost overall accuracy.


Tech Stack

Languages, frameworks, and environment

Languages

Python

Frameworks & Libraries

TensorFlowKerasScikit-Learn Hugging Face TransformersNumPyPandas

Environment

Google Colab (TPUv2)

Key Academic References

Papers used in architecture design

[1] Devlin, J., et al. (2018). BERT: Pre-training of deep bidirectional transformers for language understanding.
[2] Liu, Y., et al. (2019). RoBERTa: A robustly optimized BERT pretraining approach.
[3] Radford, A., et al. (2019). Language models are unsupervised multitask learners. (GPT-2)
[4] Vaswani, A., et al. (2017). Attention is all you need.
[5] Kim, Y. (2014). Convolutional neural networks for sentence classification.