Skip to main content

Arabic multi-label toxic content classifier

Project description

arabic-toxic

Arabic Multi-Label Toxic Content Classifier

A fast and lightweight Arabic NLP package for toxic content detection, content moderation, social media analysis, and Arabic text safety classification.

The package supports multi-label classification and can detect several categories of toxic and harmful content in Arabic text.


Installation

pip install arabic-toxic

Quick Start

Single Text Classification

from arabic_toxic import classify

result = classify("يلعن امك يا ابن الحمار")

print(result)

Output

{
    "text": "يلعن امك يا ابن الحمار",
    "labels": ["Cussing", "Hatred"],
    "top_label": "Cussing",
    "is_toxic": True,
    "scores": {
        "Cussing": 99.999,
        "Hatred": 94.404,
        "Sexual": 2.938,
        "Racial": 0.762,
        "Appearance": 0.033,
        "Violence": 0.027,
        "NOT": 0.001
    }
}

Toxic / Non-Toxic Detection

from arabic_toxic import classify

print(classify("أنت إنسان محترم"))
print(classify("شكراً لك على المساعدة"))

Output

{
    "text": "أنت إنسان محترم",
    "labels": ["NOT"],
    "top_label": "NOT",
    "is_toxic": False
}

{
    "text": "شكراً لك على المساعدة",
    "labels": ["NOT"],
    "top_label": "NOT",
    "is_toxic": False
}

Batch Classification

from arabic_toxic import classify_many

texts = [
    "أنت إنسان محترم",
    "يلعن امك يا ابن الحمار",
    "الشكل والتفكير حمار",
    "ليبرالية شوية صعاليك"
]

results = classify_many(texts)

for r in results:
    print(r)

Probability Scores

from arabic_toxic import predict_proba

scores = predict_proba("يلعن امك يا ابن الحمار")

print(scores)

Supported Labels

Label Description
Appearance Appearance-based insults
Cussing Profanity and offensive language
Hatred Hate and hostility
NOT Non-toxic content
Racial Ethnic or racial attacks
Sexual Sexual harassment or abuse
Violence Violent threats or content

Model Architecture

The model uses:

  • Arabic text normalization
  • TF-IDF word n-grams
  • TF-IDF character n-grams
  • Multi-label classification
  • One-vs-Rest strategy
  • SGD Logistic Classifier

Designed for:

  • Content Moderation
  • Social Media Monitoring
  • Arabic NLP Research
  • Online Community Safety
  • AI Safety Applications

Evaluation Results

Test-set performance:

Metric Score
Macro F1 0.9109
Micro F1 0.9205
Subset Accuracy 0.8433
Hamming Loss 0.0307

Notes

This package is intended for Arabic content moderation, research, and production prototyping.

Performance may vary depending on dialect, domain, and writing style. Always validate the model on your own data before using it in production decision systems.


Author

Dr. Faisal Alshargi

AI Researcher • NLP Engineer • Data Scientist

GitHub: https://github.com/alshargi

PyPI: https://pypi.org/project/arabic-toxic/

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

arabic_toxic-0.2.2.tar.gz (3.4 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

arabic_toxic-0.2.2-py3-none-any.whl (3.4 MB view details)

Uploaded Python 3

File details

Details for the file arabic_toxic-0.2.2.tar.gz.

File metadata

  • Download URL: arabic_toxic-0.2.2.tar.gz
  • Upload date:
  • Size: 3.4 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for arabic_toxic-0.2.2.tar.gz
Algorithm Hash digest
SHA256 029f79e982095f1a1d248188cded7eea1d0d4b4ca1f4d125c1da8536b9c3ce67
MD5 f53c9c97d963112fe9b17bf99ac86888
BLAKE2b-256 871ec10d4fc6f47cbbefc8d2819998f336058c1eb0ee2bf78e8cee56c5fdb4fc

See more details on using hashes here.

File details

Details for the file arabic_toxic-0.2.2-py3-none-any.whl.

File metadata

  • Download URL: arabic_toxic-0.2.2-py3-none-any.whl
  • Upload date:
  • Size: 3.4 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for arabic_toxic-0.2.2-py3-none-any.whl
Algorithm Hash digest
SHA256 2301626f999329eeb7d2a3a63b0683dc5feae2be6248a547ac9481a2b114632b
MD5 5eddce5a5d9023666677714194f110a5
BLAKE2b-256 af2bb4997d327e7ae23a7401d9db017ba90241d786c0b75541dbee397866cac9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page