Data Warehouse & Data Mining

Explainable Bangla Toxic Comment Detection using BanglaBERT with SHAP and LIME

A fine-tuned BanglaBERT detects toxic Bengali comments (86% accuracy, 87% F1, 0.91 ROC-AUC) and explains every prediction with SHAP and LIME.

Data-mining research (IEEE-format paper) that fine-tunes BanglaBERT on Bengali toxicity data using 5-fold stratified cross-validation and adds an explainability layer — SHAP and LIME reveal which words drove each toxic / non-toxic decision, tackling the black-box problem in low-resource Bangla NLP.

86%
accuracy
87%
F1-score
0.91
ROC-AUC
5-fold
stratified CV

[ 01 ]

Research Overview

Toxic and hateful comments are rampant on Bengali social media, and the mental-health toll on adolescents is real. Most existing detection systems optimize accuracy alone and offer no explanation for their verdicts.

This study fine-tunes BanglaBERT for toxic-comment classification and wraps it in an explainability mechanism — LIME and SHAP — so moderators can see exactly which tokens triggered a flag.

[ 02 ]

Problem Statement

  • Bengali toxicity detection is underserved: the language is low-resource, and informal writing, acronyms, and context-dependent insults defeat keyword rules and classical ML.
  • Transformer models detect toxicity well but act as black boxes, which undermines trust in automated moderation.
  • Applying both SHAP and LIME to a transformer-based Bangla toxicity framework had rarely been explored.

[ 03 ]

Objective

  • Fine-tune BanglaBERT for binary toxic / non-toxic Bengali comment classification.
  • Evaluate with 5-fold stratified cross-validation for reliable estimates.
  • Add SHAP and LIME to surface the words driving each prediction.
  • Contribute a transparent, trustworthy framework to low-resource Bangla NLP.

[ 04 ]

Methodology

  • Data: multiple Bengali toxicity corpora compiled into a labeled benchmark for fine-tuning and evaluation.
  • Model: BanglaBERT, the Bengali member of the BERT family, fine-tuned for sequence classification.
  • Training: 5-fold stratified cross-validation with averaged accuracy, F1, and ROC-AUC reported.
  • Explainability: LIME and SHAP both applied to individual predictions to identify important toxic words and validate model behaviour.

[ 05 ]

Models Used

BanglaBERT

Fine-tuned transformer with a sequence-classification head for toxic / non-toxic prediction.

SHAP + LIME

Post-hoc local explainers that attribute each prediction to the words that drove it.

[ 06 ]

Dataset

  • Multiple Bengali toxicity datasets combined — a BanglaMedia corpus, a Bengali comments dataset, a contextual toxicity dataset, plus auxiliary and synthetic augmentation sets.

[ 07 ]

Implementation

  • Fine-tuning loop over five stratified folds with the BanglaBERT transformer, aggregating per-fold metrics.
  • Post-hoc analysis on held-out toxic and non-toxic examples using SHAP (additive attribution) and LIME (local surrogate) to highlight decisive tokens.

[ 08 ]

Key Features

  • 5-fold stratified cross-validation for reliable generalization estimates.
  • Dual explainability — both SHAP and LIME on the same framework.
  • Word-level attribution that names the toxic terms behind each flag.
  • Focus on low-resource Bangla NLP rather than high-resource English.

[ 09 ]

Results

  • Averaged over the five folds, the fine-tuned BanglaBERT reaches 86% accuracy, 87% F1-score, and 0.91 ROC-AUC.
  • SHAP and LIME attributions align with toxic keywords, showing the model reasons over the expected linguistic signals rather than spurious cues.

[ 10 ]

Outcome

  • A validated, explainable toxicity detector that can underpin intelligent online moderation for Bengali content.
  • A reproducible template for pairing transformer classifiers with SHAP + LIME in low-resource languages.

[ 11 ]

Tools & Technologies

PythonHugging Face TransformersBanglaBERTSHAPLIMEPyTorchscikit-learn

[ 12 ]

Challenges

  • Bengali linguistic nuance — context-dependent insults, slang, and transliterated forms.
  • Limited high-quality labeled Bengali toxicity data; augmentation was needed.
  • Explainability tools are compute-heavy over transformer embeddings.

[ 13 ]

Future Improvements

  • Extend to multi-class severity (sarcasm, misogyny, religious hate) and cross-lingual transfer.
  • Scale the labeled corpus and test other Bangla transformer variants (m-BERT, XLM-R, MuRIL).
  • Ship the explainable scorer as a live moderation API.

[ 14 ]

Related work

Back to research