File size: 5,284 Bytes
3c6e625
cb777d5
 
4c790e4
cc3ed62
3c6e625
cb777d5
 
 
 
 
 
 
3c6e625
cb777d5
e0def9f
 
 
 
3c6e625
 
e0def9f
 
 
cb777d5
e0def9f
cb777d5
 
e0def9f
 
 
cb777d5
 
 
 
 
 
 
 
 
3c6e625
 
 
 
cb777d5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3c6e625
cb777d5
 
3c6e625
cb777d5
 
 
 
 
3c6e625
cb777d5
 
 
 
3c6e625
cb777d5
3c6e625
cb777d5
 
 
 
 
 
3c6e625
cb777d5
3c6e625
cb777d5
 
 
3c6e625
cb777d5
3c6e625
cb777d5
 
 
 
3c6e625
cb777d5
3c6e625
cb777d5
3c6e625
cb777d5
 
 
 
3c6e625
cb777d5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3c6e625
cb777d5
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
---
language:
- ar
license: apache-2.0
base_model: thejosango/nuha-mlm
tags:
- bert
- text-classification
- hate-speech
- gender-based-violence
- arabic
- binary-classification
- pilot
datasets:
- thejosango/nuha-dataset
metrics:
- f1
- precision
- recall
model-index:
- name: nuha-binary
  results:
  - task:
      type: text-classification
      name: Text Classification
    dataset:
      name: Jordanian NUHA Dataset
      type: thejosango/nuha-dataset
      config: binary
      split: validation
    metrics:
    - type: f1
      value: 0.6879
      name: F1
    - type: precision
      value: 0.6464
      name: Precision
    - type: recall
      value: 0.7351
      name: Recall
---

# nuha-binary

## Model Summary

`nuha-binary` is a binary Arabic text classifier that detects hate speech in Jordanian social media comments. It fine-tunes [`nuha-mlm`](https://huggingface.co/thejosango/nuha-mlm) — a domain-adapted Arabic BERT — and outputs one of two labels:

| Label | Meaning |
|---|---|
| `non-hate-speech` | Not Online Violence |
| `hate-speech` | Offensive Language or Online Gender Based Violence |

This model was developed as part of a **pilot proof-of-concept** for the NUHA project by the [Jordan Open Source Association (JOSA)](https://josa.ngo). Performance metrics reflect the complexity of hate speech detection in colloquial Arabic and the exploratory nature of this initial effort.

For a more granular three-class classifier, see [`nuha-multiclass`](https://huggingface.co/thejosango/nuha-multiclass).

## Uses

### Direct Use

Classifying Arabic social media comments as hate speech or non-hate speech, particularly for Jordanian Arabic content from Facebook and X (Twitter).

```python
from transformers import pipeline

classifier = pipeline(
    "text-classification",
    model="thejosango/nuha-binary",
    tokenizer="thejosango/nuha-binary",
)

result = classifier("أنتِ امرأة رائعة")
print(result)
# [{'label': 'non-hate-speech', 'score': ...}]
```

For batch inference:

```python
comments = ["أنتِ امرأة رائعة", "اخرسي يا غبية"]
results = classifier(comments)
for comment, result in zip(comments, results):
    print(f"{result['label']} ({result['score']:.2f}): {comment}")
```

### Out-of-Scope Use

- **Other Arabic dialects**: The model was trained primarily on Jordanian Arabic. Performance on Egyptian, Gulf, or Modern Standard Arabic is not validated.
- **General hate speech**: The model is specifically calibrated for online gender-based violence in a Jordanian context. It may not generalise to other forms of hate speech or other demographic targets.
- **High-stakes automated decisions**: Given the moderate performance (F1 ≈ 0.69) and pilot nature of this work, the model should not be used as a sole decision-maker in content moderation systems without human review.

## Bias, Risks, and Limitations

- **Pilot annotation quality**: Training labels were produced in an exploratory annotation effort with variable inter-annotator agreement. The model inherits noise from that process.
- **Class imbalance**: The training data contains approximately 59% non-hate-speech and 41% hate-speech examples. Weighted loss was used during training to partially compensate.
- **Colloquial Arabic only**: The aggressive text cleaning (Arabic-only filtering) means the model has never seen URLs, numbers, punctuation, or Latin-script text. Inputs containing these will have them silently ignored by the preprocessing.
- **Moderate performance**: An F1 of 0.69 on the validation set reflects genuine difficulty of the task and the limitations of the pilot training data. Precision (0.65) is lower than recall (0.74), meaning the model tends toward false positives.

## Training Details

### Training Data

Fine-tuned on the `binary` configuration of [`thejosango/nuha-dataset`](https://huggingface.co/datasets/thejosango/nuha-dataset), which maps:
- **Not Online Violence**`non-hate-speech`
- **Offensive Language**`hate-speech`
- **Gender Based Violence**`hate-speech`

### Preprocessing

At training and inference time, the following normalisation is applied to input text (in addition to the dataset-level Arabic-only filtering):

1. URLs replaced with `[رابط]` token
2. @mentions replaced with `[مستخدم]` token
3. Email addresses replaced with `[بريد]` token
4. Numbers removed
5. Punctuation removed
6. Arabic diacritics (harakat) removed
7. Whitespace normalised

### Hyperparameters

| Parameter | Value |
|---|---|
| Base model | thejosango/nuha-mlm |
| Hidden layers | 4 (reduced from base's 12) |
| Classifier dropout | 0.50 |
| Learning rate | 5e-5 |
| LR schedule | Linear |
| Batch size | 64 |
| Epochs | 5 |
| Weight decay | 1e-3 |
| Label smoothing | 0.1 |
| Weighted loss | Yes (balanced class weights) |
| Data augmentation | Yes (contextual word substitution, ratio 0.75) |
| Framework | Transformers 4.32.1, PyTorch 2.0.1 |

### Evaluation Results

Evaluated on the validation split of `thejosango/nuha-dataset` (binary configuration):

| Metric | Value |
|---|---|
| F1 | 0.6879 |
| Precision | 0.6464 |
| Recall | 0.7351 |
| Loss | 0.5743 |

---

*This model was developed as part of an initial pilot study. Results should be interpreted accordingly.*