Update README.md
Browse files
README.md
CHANGED
@@ -1,3 +1,157 @@
|
|
1 |
-
---
|
2 |
-
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
language: az
|
3 |
+
license: cc-by-4.0
|
4 |
+
library_name: transformers
|
5 |
+
tags:
|
6 |
+
- text-classification
|
7 |
+
- toxicity
|
8 |
+
- azerbaijani
|
9 |
+
- multi-label-classification
|
10 |
+
pipeline_tag: text-classification
|
11 |
+
datasets:
|
12 |
+
- LocalDoc/toxic_dataset_classification_azerbaijani
|
13 |
+
base_model:
|
14 |
+
- microsoft/mdeberta-v3-base
|
15 |
+
---
|
16 |
+
|
17 |
+
# Azerbaijani Toxicity Classifier
|
18 |
+
|
19 |
+
This is a multi-label text classification model fine-tuned to detect various types of toxicity in **Azerbaijani** text.
|
20 |
+
|
21 |
+
The model is based on `mDeBERTa-v3` and can identify the following categories:
|
22 |
+
- `toxicity` (Overall Toxicity)
|
23 |
+
- `severe_toxicity`
|
24 |
+
- `obscene`
|
25 |
+
- `threat`
|
26 |
+
- `insult`
|
27 |
+
- `identity_attack`
|
28 |
+
- `sexual_explicit`
|
29 |
+
|
30 |
+
## Model Description
|
31 |
+
|
32 |
+
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.
|
33 |
+
|
34 |
+
## How to Use
|
35 |
+
|
36 |
+
You can use this model directly with the `transformers` library.
|
37 |
+
|
38 |
+
First, make sure you have the necessary libraries installed:
|
39 |
+
```bash
|
40 |
+
pip install transformers torch
|
41 |
+
```
|
42 |
+
|
43 |
+
```python
|
44 |
+
import torch
|
45 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
46 |
+
|
47 |
+
def classify_toxicity():
|
48 |
+
text_to_classify = "Sən nə yaramaz adamsan"
|
49 |
+
|
50 |
+
model_id = "LocalDoc/azerbaijani_toxicity_classifier"
|
51 |
+
|
52 |
+
# The order of labels must match the model's output
|
53 |
+
label_names = [
|
54 |
+
'identity_attack',
|
55 |
+
'insult',
|
56 |
+
'obscene',
|
57 |
+
'severe_toxicity',
|
58 |
+
'sexual_explicit',
|
59 |
+
'threat',
|
60 |
+
'toxicity'
|
61 |
+
]
|
62 |
+
|
63 |
+
print(f"Loading model: {model_id}...")
|
64 |
+
try:
|
65 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
66 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_id)
|
67 |
+
except Exception as e:
|
68 |
+
print(f"Error loading model. Make sure the repository '{model_id}' is public and contains the model files.")
|
69 |
+
print(f"Details: {e}")
|
70 |
+
return
|
71 |
+
|
72 |
+
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
|
73 |
+
model.to(device)
|
74 |
+
model.eval()
|
75 |
+
print(f"Model loaded successfully on {device}.")
|
76 |
+
-
|
77 |
+
|
78 |
+
inputs = tokenizer(
|
79 |
+
text_to_classify,
|
80 |
+
truncation=True,
|
81 |
+
padding=True,
|
82 |
+
return_tensors='pt'
|
83 |
+
).to(device)
|
84 |
+
|
85 |
+
|
86 |
+
with torch.no_grad():
|
87 |
+
outputs = model(**inputs)
|
88 |
+
# Apply sigmoid to get probabilities for each category
|
89 |
+
probabilities = torch.sigmoid(outputs.logits).cpu().numpy()[0]
|
90 |
+
|
91 |
+
|
92 |
+
threshold = 0.5
|
93 |
+
overall_toxicity_score = probabilities[-1] # The last label is 'toxicity'
|
94 |
+
is_toxic = overall_toxicity_score > threshold
|
95 |
+
|
96 |
+
print("\n" + "="*50)
|
97 |
+
print("TOXICITY ANALYSIS RESULTS")
|
98 |
+
print("="*50)
|
99 |
+
print(f"Text: {text_to_classify}")
|
100 |
+
|
101 |
+
status = "TOXIC" if is_toxic else "NOT TOXIC"
|
102 |
+
print(f"\nOverall Status: {status} (Confidence: {overall_toxicity_score:.3f})")
|
103 |
+
|
104 |
+
print("\nCategory Scores:")
|
105 |
+
for i, category in enumerate(label_names):
|
106 |
+
score = probabilities[i]
|
107 |
+
formatted_name = category.replace('_', ' ').capitalize()
|
108 |
+
print(f" - {formatted_name:<20}: {score:.4f}")
|
109 |
+
|
110 |
+
print("="*50)
|
111 |
+
|
112 |
+
|
113 |
+
if __name__ == "__main__":
|
114 |
+
classify_toxicity()
|
115 |
+
|
116 |
+
```
|
117 |
+
|
118 |
+
```bash
|
119 |
+
==================================================
|
120 |
+
TOXICITY ANALYSIS RESULTS
|
121 |
+
==================================================
|
122 |
+
Text: Sən nə yaramaz adamsan
|
123 |
+
|
124 |
+
Overall Status: TOXIC (Confidence: 0.987)
|
125 |
+
|
126 |
+
Category Scores:
|
127 |
+
- Identity attack : 0.0004
|
128 |
+
- Insult : 0.9878
|
129 |
+
- Obscene : 0.0056
|
130 |
+
- Severe toxicity : 0.0002
|
131 |
+
- Sexual explicit : 0.0002
|
132 |
+
- Threat : 0.0006
|
133 |
+
- Toxicity : 0.9875
|
134 |
+
==================================================
|
135 |
+
```
|
136 |
+
|
137 |
+
## Intended Use & Limitations
|
138 |
+
|
139 |
+
This model is intended to be used as a tool for content moderation to help flag potentially harmful content for human review.
|
140 |
+
|
141 |
+
**Limitations:**
|
142 |
+
* The model may struggle with sarcasm, irony, or other forms of nuanced language.
|
143 |
+
* Its performance is dependent on the data it was trained on and may exhibit biases present in that data.
|
144 |
+
* It should not be used to make fully automated, final decisions about content or users without a human-in-the-loop.
|
145 |
+
|
146 |
+
## Training
|
147 |
+
|
148 |
+
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.
|
149 |
+
|
150 |
+
## License
|
151 |
+
|
152 |
+
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/).
|
153 |
+
|
154 |
+
|
155 |
+
## Contact
|
156 |
+
|
157 |
+
For more information, questions, or issues, please contact LocalDoc at [[email protected]].
|