Skip to main content

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

The classify() function returns an is_toxic field that directly tells whether the input text is toxic.

from arabic_toxic import classify

result = classify("أنت إنسان محترم")

print(result["is_toxic"])

Output

False

Full Example

from arabic_toxic import classify

print(classify("أنت إنسان محترم"))
print(classify("يلعن امك يا ابن الحمار"))

Output

{
    "text": "أنت إنسان محترم",
    "labels": ["NOT"],
    "top_label": "NOT",
    "is_toxic": False,
    "scores": {
        "Hatred": 23.802,
        "Appearance": 23.436,
        "Racial": 13.917,
        "NOT": 11.666,
        "Cussing": 10.767,
        "Sexual": 3.805,
        "Violence": 1.656
    }
}

{
    "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
    }
}

Classifying a List of Texts

The current version can classify a list of texts by applying classify() to each item.

from arabic_toxic import classify

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

results = [classify(text) for text in texts]

for result in results:
    print(result)

Output

{
    "text": "أنت إنسان محترم",
    "labels": ["NOT"],
    "top_label": "NOT",
    "is_toxic": False,
    "scores": {
        "Hatred": 23.802,
        "Appearance": 23.436,
        "Racial": 13.917,
        "NOT": 11.666,
        "Cussing": 10.767,
        "Sexual": 3.805,
        "Violence": 1.656
    }
}

{
    "text": "شكراً لك على المساعدة",
    "labels": ["NOT"],
    "top_label": "NOT",
    "is_toxic": False,
    "scores": {
        "NOT": 94.747,
        "Hatred": 4.771,
        "Violence": 3.802,
        "Sexual": 3.508,
        "Cussing": 2.306,
        "Appearance": 2.286,
        "Racial": 2.183
    }
}

{
    "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
    }
}

{
    "text": "الشكل والتفكير حمار",
    "labels": ["Hatred"],
    "top_label": "Hatred",
    "is_toxic": True,
    "scores": {
        "Hatred": 98.338,
        "Racial": 12.536,
        "Appearance": 12.058,
        "NOT": 8.266,
        "Cussing": 2.405,
        "Sexual": 1.201,
        "Violence": 0.909
    }
}

{
    "text": "ليبرالية شوية صعاليك",
    "labels": ["Hatred", "Racial"],
    "top_label": "Racial",
    "is_toxic": True,
    "scores": {
        "Racial": 70.922,
        "Hatred": 65.004,
        "Cussing": 22.948,
        "Appearance": 5.112,
        "NOT": 4.478,
        "Sexual": 2.064,
        "Violence": 1.858
    }
}

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/

Metadata

Release files for arabic-toxic 0.2.3

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for arabic-toxic 0.2.3
File Size Uploaded Provenance
arabic_toxic-0.2.3.tar.gz 3.4 MB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for arabic-toxic 0.2.3
File Interpreter ABI Platform
arabic_toxic-0.2.3-py3-none-any.whl Python 3 none any Details

Total release size: 6.8 MB

Release files / arabic_toxic-0.2.3.tar.gz

Download URL arabic_toxic-0.2.3.tar.gz
Size 3.4 MB
Tags Source
SHA-256 checksum
How to use checksums
82fb066b922829b4d81935aacef3ec4b0e0c2514e9e78eb67bc5f41b91102d5d
BLAKE2b-256 checksum
How to use checksums
11ce3154ea946d5074364646dcc6e82e44a2c324bb7a7e6b663af2d91f01dccb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.20

Release files / arabic_toxic-0.2.3-py3-none-any.whl

Download URL arabic_toxic-0.2.3-py3-none-any.whl
Size 3.4 MB
Tags Python 3
SHA-256 checksum
How to use checksums
373987b3e41fc8d1e7b1eb3399687e1e97d7262a56e4a05f2371ce6ed7ee28c5
BLAKE2b-256 checksum
How to use checksums
4374d1176ec41608a37b0f9df88a75729a460ff3ef23366559b38e70f96522a8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.10.20

Security for arabic-toxic 0.2.3

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page