CoolFace
Apppublic

xyz6269/arabic-hate-speech-detection

sourceHugging Faceupdated 3mo agoView on Hugging Face
0likes
App README

Arabic Multimodal Hate Speech Detection

A multimodal hate speech detection system for memes, combining Arabic text understanding with visual reasoning. The system fuses a fine-tuned MARBERTv2 text encoder with a CLIP ViT-B/32 vision encoder via cross-modal projection, and routes borderline cases to an LLM judge for final moderation decisions.


How It Works

Pipeline Overview

Meme Image
    │
    ├──► EasyOCR (text extraction)
    │         │
    │         ▼
    │    NLLB-200 Translation (EN → AR)
    │         │
    │         ▼
    │    MARBERTv2 (text encoder) ──► text features (512d)
    │                                        │
    └──► CLIP ViT-B/32 (vision encoder) ──► visual features (512d)
                                                    │
                                             Concatenation (1024d)
                                                    │
                                            Binary Classifier
                                                    │
                                          Confidence Score (0–1)
                                                    │
                              ┌─────────────────────┴──────────────────────┐
                         conf >= 0.53                              0.4 <= conf < 0.53
                              │                                            │
                        REMOVE / ALLOW                            LLM Judge (Groq)
                        (fusion model)                           REMOVE / WARN / ALLOW

Components

Text Encoder — MARBERTv2 A BERT-based model pre-trained on Arabic dialectal and Modern Standard Arabic. Handles the Arabic text extracted and translated from meme images. Token embeddings are mean-pooled with attention masking and projected to 512 dimensions.

Vision Encoder — CLIP ViT-B/32 OpenAI's CLIP vision transformer, frozen during training. Extracts visual semantics from the meme image and projects them to 512 dimensions via CLIP's visual projection head.

Fusion Text and visual features are concatenated into a 1024-dimensional vector and passed through a 3-layer MLP classifier with GELU activations and dropout (0.5), producing a single hate speech probability score.

Agentic Decision Layer The agent applies a confidence-based routing policy:

  • —conf >= 0.53 → REMOVE (fusion model is confident)
  • —conf < 0.4 → ALLOW (fusion model is confident)
  • —0.4 <= conf < 0.53 → escalate to VLM Judge (Groq, llama-4-scout-17b-16e-instruct)

The LLM judge receives the extracted text and model confidence, then returns one of: REMOVE, WARN, or ALLOW, with a one-sentence explanation.

Fallback policy: if the Groq API is unavailable, the system defaults to REMOVE to err on the side of safety.


Performance

MetricScore
Test Accuracy0.7333
AUROC0.7830
Macro F10.71
Not-Hate F10.79
Hate F10.62
Decision Threshold0.53

Evaluated on the Facebook Hateful Memes dataset (900 test samples).


Running Locally

Requirements

  • —Python 3.10+
  • —CUDA-capable GPU recommended (CPU inference is slow)
  • —A Groq API key (free tier available at console.groq.com)

Installation

bash
git clone https://huggingface.co/spaces/xyz6269/arabic-hate-speech-detection
cd arabic-hate-speech-detection
pip install -r requirements.txt

Environment Variables

bash
export GROQ_API_KEY="your_groq_api_key_here"
Note: The Groq API key is required for the LLM judge step. On HuggingFace Spaces, requests to Groq may be blocked — run locally for full agentic pipeline functionality. The Space demo will fall back to REMOVE for borderline cases if Groq is unavailable.

Model Weights

The model weights are hosted on HuggingFace Hub and downloaded automatically at startup from xyz6269/arabic-hateful-memes-model. No manual download needed.

Launch

bash
python app.py

The Gradio interface will be available at http://127.0.0.1:7860.


Requirements

gradio
spaces
torch
torchvision
transformers
huggingface_hub
easyocr
groq
Pillow
  • —please ignore the requirements.txt file in the repo as that one is different for a reason being that it's what running the model on huggingfaces requires ---

Dataset

Training data sourced from:

Combined dataset: ~9000 training samples after filtering and balancing.


Citation

If you use this system in your research, please cite the accompanying paper (forthcoming, SoftwareX, Elsevier).


License

MIT