Metadata-Version: 2.4
Name: arabic-toxic
Version: 0.2.3
Summary: Arabic multi-label toxic content classifier
Author-email: Faisal Alshargi <alshargi@hotmail.de>
License-Expression: MIT
Project-URL: Homepage, https://github.com/alshargi/arabic-toxic
Project-URL: Repository, https://github.com/alshargi/arabic-toxic
Project-URL: Issues, https://github.com/alshargi/arabic-toxic/issues
Keywords: arabic,toxicity,harassment,nlp,text-classification,content-moderation
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Operating System :: OS Independent
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
Classifier: Topic :: Text Processing :: Linguistic
Requires-Python: >=3.10
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: joblib>=1.2
Requires-Dist: numpy>=1.23
Requires-Dist: scikit-learn<1.8.0,>=1.4.0
Dynamic: license-file


# 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

```bash
pip install arabic-toxic
```

---

## Quick Start

### Single Text Classification

```python
from arabic_toxic import classify

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

print(result)
```

### Output

```python
{
    "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.

```python
from arabic_toxic import classify

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

print(result["is_toxic"])
```

### Output

```python
False
```

### Full Example

```python
from arabic_toxic import classify

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

### Output

```python
{
    "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.

```python
from arabic_toxic import classify

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

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

for result in results:
    print(result)
```

### Output

```python
{
    "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

```python
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](https://github.com/alshargi)

PyPI: [https://pypi.org/project/arabic-toxic/](https://pypi.org/project/arabic-toxic/)
