File size: 4,992 Bytes
f4fe75d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
---
language: az
license: cc-by-4.0
library_name: transformers
tags:
- text-classification
- toxicity
- azerbaijani
- multi-label-classification
pipeline_tag: text-classification
datasets:
- LocalDoc/toxic_dataset_classification_azerbaijani
base_model:
- microsoft/mdeberta-v3-base
---

# Azerbaijani Toxicity Classifier

This is a multi-label text classification model fine-tuned to detect various types of toxicity in **Azerbaijani** text.

The model is based on `mDeBERTa-v3` and can identify the following categories:
- `toxicity` (Overall Toxicity)
- `severe_toxicity`
- `obscene`
- `threat`
- `insult`
- `identity_attack`
- `sexual_explicit`

## Model Description

This model is designed for content moderation and analysis of online communication in the Azerbaijani language. It takes a string of text as input and returns a probability score for each of the seven toxicity categories. This allows for nuanced moderation, distinguishing between general insults, threats, or sexually explicit content.

## How to Use

You can use this model directly with the `transformers` library.

First, make sure you have the necessary libraries installed:
```bash
pip install transformers torch
```

```python
import torch
from transformers import AutoTokenizer, AutoModelForSequenceClassification

def classify_toxicity():
    text_to_classify = "Sən nə yaramaz adamsan"
    
    model_id = "LocalDoc/azerbaijani_toxicity_classifier"
    
    # The order of labels must match the model's output
    label_names = [
        'identity_attack',
        'insult',
        'obscene',
        'severe_toxicity',
        'sexual_explicit',
        'threat',
        'toxicity'
    ]
    
    print(f"Loading model: {model_id}...")
    try:
        tokenizer = AutoTokenizer.from_pretrained(model_id)
        model = AutoModelForSequenceClassification.from_pretrained(model_id)
    except Exception as e:
        print(f"Error loading model. Make sure the repository '{model_id}' is public and contains the model files.")
        print(f"Details: {e}")
        return

    device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
    model.to(device)
    model.eval()
    print(f"Model loaded successfully on {device}.")
-
    
    inputs = tokenizer(
        text_to_classify,
        truncation=True,
        padding=True,
        return_tensors='pt'
    ).to(device)

    
    with torch.no_grad():
        outputs = model(**inputs)
        # Apply sigmoid to get probabilities for each category
        probabilities = torch.sigmoid(outputs.logits).cpu().numpy()[0]


    threshold = 0.5
    overall_toxicity_score = probabilities[-1] # The last label is 'toxicity'
    is_toxic = overall_toxicity_score > threshold

    print("\n" + "="*50)
    print("TOXICITY ANALYSIS RESULTS")
    print("="*50)
    print(f"Text: {text_to_classify}")

    status = "TOXIC" if is_toxic else "NOT TOXIC"
    print(f"\nOverall Status: {status} (Confidence: {overall_toxicity_score:.3f})")

    print("\nCategory Scores:")
    for i, category in enumerate(label_names):
        score = probabilities[i]
        formatted_name = category.replace('_', ' ').capitalize()
        print(f"  - {formatted_name:<20}: {score:.4f}")
        
    print("="*50)


if __name__ == "__main__":
    classify_toxicity()

```

```bash
==================================================
TOXICITY ANALYSIS RESULTS
==================================================
Text: Sən nə yaramaz adamsan

Overall Status: TOXIC (Confidence: 0.987)

Category Scores:
  - Identity attack     : 0.0004
  - Insult              : 0.9878
  - Obscene             : 0.0056
  - Severe toxicity     : 0.0002
  - Sexual explicit     : 0.0002
  - Threat              : 0.0006
  - Toxicity            : 0.9875
==================================================
```

## Intended Use & Limitations

This model is intended to be used as a tool for content moderation to help flag potentially harmful content for human review.

**Limitations:**
*   The model may struggle with sarcasm, irony, or other forms of nuanced language.
*   Its performance is dependent on the data it was trained on and may exhibit biases present in that data.
*   It should not be used to make fully automated, final decisions about content or users without a human-in-the-loop.

## Training

The model was fine-tuned on a private dataset of Azerbaijani text labeled for the seven toxicity categories mentioned above. It was trained as a multi-label classification task, where each text can belong to one, multiple, or no categories.

## License

This model is licensed under the **Creative Commons Attribution 4.0 International (CC BY 4.0)** license. You are free to share and adapt the material for any purpose, even commercially, as long as you give appropriate credit. For more details, see the [license terms](https://creativecommons.org/licenses/by/4.0/).


## Contact

For more information, questions, or issues, please contact LocalDoc at [[email protected]].