SafwanLjd yazansh commited on
Commit
fdd2ade
·
0 Parent(s):

Upload model

Browse files

Co-authored-by: yazansh <yazansh@users.noreply.huggingface.co>

.gitattributes ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,165 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - ar
4
+ license: apache-2.0
5
+ base_model: thejosango/nuha-ajp-mlm
6
+ tags:
7
+ - bert
8
+ - text-classification
9
+ - hate-speech
10
+ - gender-based-violence
11
+ - arabic
12
+ - trinary-classification
13
+ - pilot
14
+ datasets:
15
+ - thejosango/nuha-ajp-dataset
16
+ metrics:
17
+ - f1
18
+ - precision
19
+ - recall
20
+ model-index:
21
+ - name: nuha-ajp-trinary
22
+ results:
23
+ - task:
24
+ type: text-classification
25
+ name: Text Classification
26
+ dataset:
27
+ name: Jordanian NUHA Dataset
28
+ type: thejosango/nuha-ajp-dataset
29
+ config: methodology
30
+ split: validation
31
+ metrics:
32
+ - type: f1
33
+ value: 0.5363
34
+ name: F1
35
+ - type: precision
36
+ value: 0.6660
37
+ name: Precision
38
+ - type: recall
39
+ value: 0.5188
40
+ name: Recall
41
+ ---
42
+
43
+ # nuha-ajp-trinary-onnx
44
+
45
+ ## Model Summary
46
+
47
+ `nuha-ajp-trinary` is an Arabic text classifier that categorises Jordanian social media comments into three classes based on the NUHA methodology for online gender-based violence (OGBV). It fine-tunes [`nuha-ajp-mlm`](https://huggingface.co/thejosango/nuha-ajp-mlm) — a domain-adapted Arabic BERT — and outputs one of:
48
+
49
+ | Label | Meaning |
50
+ |---|---|
51
+ | `Not Online Violence` | Comments that are not hate speech |
52
+ | `Offensive Language` | Hate speech characterised by irony or sarcasm |
53
+ | `Gender Based Violence` | Direct hate speech targeting gender — the primary focus of NUHA |
54
+
55
+ 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). It is the production model behind the NUHA analysis platform.
56
+
57
+ A **lightweight, ONNX-optimised** 4-layer classifier trained on the same task is available at [`thejosango/nuha-ajp-trinary-onnx`](https://huggingface.co/thejosango/nuha-ajp-trinary-onnx).
58
+
59
+ For a simpler binary classifier (hate speech / non-hate speech), see [`nuha-ajp-binary`](https://huggingface.co/thejosango/nuha-ajp-binary).
60
+
61
+ ## Uses
62
+
63
+ ### Direct Use
64
+
65
+ Classifying Arabic social media comments for online gender-based violence, particularly for Jordanian Arabic content from Facebook and X (Twitter).
66
+
67
+ ```python
68
+ from transformers import pipeline
69
+
70
+ classifier = pipeline(
71
+ "text-classification",
72
+ model="thejosango/nuha-ajp-trinary",
73
+ tokenizer="thejosango/nuha-ajp-trinary",
74
+ )
75
+
76
+ result = classifier("اخرسي يا غبية")
77
+ print(result)
78
+ # [{'label': 'Gender Based Violence', 'score': ...}]
79
+ ```
80
+
81
+ For batch inference:
82
+
83
+ ```python
84
+ comments = ["يعطيكم العافية", "أنتِ ساحرة", "اخرسي يا غبية"]
85
+ results = classifier(comments)
86
+ for comment, result in zip(comments, results):
87
+ print(f"{result['label']} ({result['score']:.2f}): {comment}")
88
+ ```
89
+
90
+ ### Using the ONNX Version
91
+
92
+ For faster CPU inference, use the ONNX export:
93
+
94
+ ```python
95
+ from optimum.onnxruntime import ORTModelForSequenceClassification
96
+ from transformers import AutoTokenizer, pipeline
97
+
98
+ model = ORTModelForSequenceClassification.from_pretrained("thejosango/nuha-ajp-trinary-onnx")
99
+ tokenizer = AutoTokenizer.from_pretrained("thejosango/nuha-ajp-trinary-onnx")
100
+ classifier = pipeline("text-classification", model=model, tokenizer=tokenizer)
101
+ ```
102
+
103
+ ### Out-of-Scope Use
104
+
105
+ - **Other Arabic dialects**: The model was trained primarily on Jordanian Arabic. Performance on Egyptian, Gulf, or Modern Standard Arabic is not validated.
106
+ - **Other hate speech targets**: NUHA is calibrated for online gender-based violence. It is not designed to detect hate speech targeting race, religion, or other demographics.
107
+ - **High-stakes automated decisions**: Given the moderate performance (F1 ≈ 0.54) and pilot nature of this work, the model should not be used as the sole decision-maker in content moderation systems without human review.
108
+
109
+ ## Bias, Risks, and Limitations
110
+
111
+ - **Pilot annotation quality**: Training labels were produced in an exploratory annotation effort with variable inter-annotator agreement. The model inherits noise from that process, which is reflected in the moderate F1 score.
112
+ - **Three-class difficulty**: Distinguishing `Offensive Language` from `Gender Based Violence` is a genuinely difficult subtask. The `Offensive Language` class is small (≈2% of training data) and the model may struggle with it.
113
+ - **Colloquial Arabic only**: The aggressive text cleaning (Arabic-only filtering) means the model has never seen URLs, numbers, punctuation, or Latin-script text.
114
+ - **Imbalanced classes**: The training data is dominated by `Not Online Violence` (≈59%), with `Offensive Language` being very sparse (≈2%). Data augmentation was applied but class imbalance remains a factor.
115
+
116
+ ## Training Details
117
+
118
+ ### Training Data
119
+
120
+ Fine-tuned on the `methodology` configuration of [`thejosango/nuha-ajp-dataset`](https://huggingface.co/datasets/thejosango/nuha-ajp-dataset), which applies the three-class NUHA categorisation scheme to the original annotations.
121
+
122
+ ### Preprocessing
123
+
124
+ At training and inference time, the following normalisation is applied to input text (in addition to the dataset-level Arabic-only filtering):
125
+
126
+ 1. URLs replaced with `[رابط]` token
127
+ 2. @mentions replaced with `[مستخدم]` token
128
+ 3. Email addresses replaced with `[بريد]` token
129
+ 4. Numbers removed
130
+ 5. Punctuation removed
131
+ 6. Arabic diacritics (harakat) removed
132
+ 7. Whitespace normalised
133
+
134
+ ### Hyperparameters
135
+
136
+ | Parameter | Value |
137
+ |---|---|
138
+ | Base model | thejosango/nuha-ajp-mlm |
139
+ | Hidden layers | 12 (full depth) |
140
+ | Learning rate | 5e-5 |
141
+ | LR schedule | Constant |
142
+ | Batch size | 64 |
143
+ | Epochs | 5 |
144
+ | Weight decay | 0.0 |
145
+ | Label smoothing | 0.1 |
146
+ | Weighted loss | No |
147
+ | Data augmentation | Yes (contextual word substitution, ratio 0.75) |
148
+ | Framework | Transformers 4.32.1, PyTorch 2.0.1 |
149
+
150
+ ### Evaluation Results
151
+
152
+ Evaluated on the validation split of `thejosango/nuha-ajp-dataset` (methodology configuration):
153
+
154
+ | Metric | Value |
155
+ |---|---|
156
+ | F1 (macro) | 0.5363 |
157
+ | Precision | 0.6660 |
158
+ | Recall | 0.5188 |
159
+ | Loss | 0.7126 |
160
+
161
+ The lower recall relative to precision suggests the model is conservative — it tends to under-predict `Gender Based Violence` rather than over-predict it. This reflects both the difficulty of the three-class task and the limited size of the pilot training corpus.
162
+
163
+ ---
164
+
165
+ *This model was developed as part of an initial pilot study. Performance metrics reflect the complexity of the task and the proof-of-concept nature of this system.*
config.json ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_name_or_path": "thejosango/nuha-mlm",
3
+ "architectures": [
4
+ "BertForSequenceClassification"
5
+ ],
6
+ "attention_probs_dropout_prob": 0.1,
7
+ "classifier_dropout": null,
8
+ "gradient_checkpointing": false,
9
+ "hidden_act": "gelu",
10
+ "hidden_dropout_prob": 0.1,
11
+ "hidden_size": 768,
12
+ "id2label": {
13
+ "0": "Not Online Violence",
14
+ "1": "Offensive Language",
15
+ "2": "Gender Based Violence"
16
+ },
17
+ "initializer_range": 0.02,
18
+ "intermediate_size": 3072,
19
+ "label2id": {
20
+ "Gender Based Violence": 2,
21
+ "Not Online Violence": 0,
22
+ "Offensive Language": 1
23
+ },
24
+ "layer_norm_eps": 1e-12,
25
+ "max_position_embeddings": 512,
26
+ "model_type": "bert",
27
+ "num_attention_heads": 12,
28
+ "num_hidden_layers": 12,
29
+ "pad_token_id": 0,
30
+ "position_embedding_type": "absolute",
31
+ "problem_type": "single_label_classification",
32
+ "torch_dtype": "float32",
33
+ "transformers_version": "4.32.1",
34
+ "type_vocab_size": 2,
35
+ "use_cache": true,
36
+ "vocab_size": 64000
37
+ }
config.toml ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [experiment]
2
+ name = "multiclass-15"
3
+ type = "multiclass"
4
+
5
+
6
+ [dataset]
7
+ path = "thejosango/nuha-dataset"
8
+ dataset_revision = "main"
9
+ augment_ratio = 0.75
10
+ undersampling_strategy = false
11
+
12
+
13
+ [model]
14
+ pretrained_model_name_or_path = "thejosango/nuha-mlm"
15
+ revision = "ce20f497544665775129f9ff5b3cd2a3e350dce8"
16
+ #num_hidden_layers = 6
17
+
18
+ [training]
19
+ num_train_epochs = 5
20
+ warmup_steps = 0
21
+ lr_scheduler_type = "constant"
22
+ learning_rate = 5e-5
23
+ per_device_train_batch_size = 64
24
+ per_device_eval_batch_size = 64
25
+ gradient_accumulation_steps = 1
26
+ weight_decay = 0.00
27
+ label_smoothing_factor = 0.1
28
+ weighted_loss = false
29
+ early_stopping_patience = 5
30
+ early_stopping_threshold = 0.005
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:796fd97fe5001c0e539646bc40dccdec9867ca6a64be77757db496e0849844ef
3
+ size 540850993
special_tokens_map.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "cls_token": "[CLS]",
3
+ "mask_token": "[MASK]",
4
+ "pad_token": "[PAD]",
5
+ "sep_token": "[SEP]",
6
+ "unk_token": "[UNK]"
7
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "clean_up_tokenization_spaces": true,
3
+ "cls_token": "[CLS]",
4
+ "do_basic_tokenize": true,
5
+ "do_lower_case": false,
6
+ "mask_token": "[MASK]",
7
+ "max_len": 512,
8
+ "max_length": 512,
9
+ "model_max_length": 512,
10
+ "never_split": [
11
+ "[بريد]",
12
+ "[مستخدم]",
13
+ "[رابط]"
14
+ ],
15
+ "pad_to_multiple_of": null,
16
+ "pad_token": "[PAD]",
17
+ "pad_token_type_id": 0,
18
+ "padding_side": "right",
19
+ "sep_token": "[SEP]",
20
+ "stride": 0,
21
+ "strip_accents": null,
22
+ "tokenize_chinese_chars": true,
23
+ "tokenizer_class": "BertTokenizer",
24
+ "truncation_side": "right",
25
+ "truncation_strategy": "longest_first",
26
+ "unk_token": "[UNK]",
27
+ "use_fast": true
28
+ }
training_args.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3c9afc151079f723aaf55e1c31f15e9fa248d61133309b574902aef6a2150344
3
+ size 4091
vocab.txt ADDED
The diff for this file is too large to render. See raw diff