Text Classification
Transformers
PyTorch
ONNX
Safetensors
Arabic
bert
hate-speech
gender-based-violence
arabic
trinary-classification
pilot
Eval Results (legacy)
text-embeddings-inference
Instructions to use thejosango/nuha-ajp-trinary-onnx with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use thejosango/nuha-ajp-trinary-onnx with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="thejosango/nuha-ajp-trinary-onnx")# Load model directly from transformers import AutoTokenizer, AutoModelForSequenceClassification tokenizer = AutoTokenizer.from_pretrained("thejosango/nuha-ajp-trinary-onnx") model = AutoModelForSequenceClassification.from_pretrained("thejosango/nuha-ajp-trinary-onnx", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Commit ·
ca3f524
0
Parent(s):
Upload model
Browse filesCo-authored-by: SFconvertbot <SFconvertbot@users.noreply.huggingface.co>
Co-authored-by: yazansh <yazansh@users.noreply.huggingface.co>
- .gitattributes +36 -0
- README.md +122 -0
- config.json +37 -0
- model.onnx +3 -0
- model.safetensors +3 -0
- pytorch_model.bin +3 -0
- special_tokens_map.json +7 -0
- tokenizer.json +0 -0
- tokenizer_config.json +28 -0
- vocab.txt +0 -0
.gitattributes
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
| 36 |
+
model.onnx filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
- onnx
|
| 14 |
+
- pilot
|
| 15 |
+
datasets:
|
| 16 |
+
- thejosango/nuha-ajp-dataset
|
| 17 |
+
metrics:
|
| 18 |
+
- f1
|
| 19 |
+
- precision
|
| 20 |
+
- recall
|
| 21 |
+
model-index:
|
| 22 |
+
- name: nuha-ajp-trinary-onnx
|
| 23 |
+
results:
|
| 24 |
+
- task:
|
| 25 |
+
type: text-classification
|
| 26 |
+
name: Text Classification
|
| 27 |
+
dataset:
|
| 28 |
+
name: Jordanian NUHA Dataset
|
| 29 |
+
type: thejosango/nuha-ajp-dataset
|
| 30 |
+
config: methodology
|
| 31 |
+
split: validation
|
| 32 |
+
metrics:
|
| 33 |
+
- type: f1
|
| 34 |
+
value: 0.5363
|
| 35 |
+
name: F1
|
| 36 |
+
- type: precision
|
| 37 |
+
value: 0.6660
|
| 38 |
+
name: Precision
|
| 39 |
+
- type: recall
|
| 40 |
+
value: 0.5188
|
| 41 |
+
name: Recall
|
| 42 |
+
---
|
| 43 |
+
|
| 44 |
+
# nuha-ajp-trinary-onnx
|
| 45 |
+
|
| 46 |
+
## Model Summary
|
| 47 |
+
|
| 48 |
+
`nuha-ajp-trinary-onnx` is a **lightweight, ONNX-optimised** 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 — with a reduced 4-layer architecture for efficient CPU inference, and is exported to ONNX. It shares the same classification task and labels as [`nuha-ajp-trinary`](https://huggingface.co/thejosango/nuha-ajp-trinary) but is optimised for production deployment. This is the model powering the NUHA analysis platform.
|
| 49 |
+
|
| 50 |
+
| Label | Meaning |
|
| 51 |
+
|---|---|
|
| 52 |
+
| `Not Online Violence` | Comments that are not hate speech |
|
| 53 |
+
| `Offensive Language` | Hate speech characterised by irony or sarcasm |
|
| 54 |
+
| `Gender Based Violence` | Direct hate speech targeting gender — the primary focus of NUHA |
|
| 55 |
+
|
| 56 |
+
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).
|
| 57 |
+
|
| 58 |
+
For the full-depth (12-layer) version of this classifier, see [`nuha-ajp-trinary`](https://huggingface.co/thejosango/nuha-ajp-trinary).
|
| 59 |
+
|
| 60 |
+
## Uses
|
| 61 |
+
|
| 62 |
+
### Direct Use
|
| 63 |
+
|
| 64 |
+
```python
|
| 65 |
+
from optimum.onnxruntime import ORTModelForSequenceClassification
|
| 66 |
+
from transformers import AutoTokenizer, pipeline
|
| 67 |
+
|
| 68 |
+
model = ORTModelForSequenceClassification.from_pretrained("thejosango/nuha-ajp-trinary-onnx")
|
| 69 |
+
tokenizer = AutoTokenizer.from_pretrained("thejosango/nuha-ajp-trinary-onnx")
|
| 70 |
+
classifier = pipeline("text-classification", model=model, tokenizer=tokenizer)
|
| 71 |
+
|
| 72 |
+
result = classifier("اخرسي يا غبية")
|
| 73 |
+
print(result)
|
| 74 |
+
# [{'label': 'Gender Based Violence', 'score': ...}]
|
| 75 |
+
```
|
| 76 |
+
|
| 77 |
+
For batch inference:
|
| 78 |
+
|
| 79 |
+
```python
|
| 80 |
+
comments = ["يعطيكم العافية", "أنتِ ساحرة", "اخرسي يا غبية"]
|
| 81 |
+
results = classifier(comments)
|
| 82 |
+
for comment, result in zip(comments, results):
|
| 83 |
+
print(f"{result['label']} ({result['score']:.2f}): {comment}")
|
| 84 |
+
```
|
| 85 |
+
|
| 86 |
+
### Using the PyTorch Version
|
| 87 |
+
|
| 88 |
+
If you need the full PyTorch model (for fine-tuning or non-ONNX inference), use [`nuha-ajp-trinary`](https://huggingface.co/thejosango/nuha-ajp-trinary) directly.
|
| 89 |
+
|
| 90 |
+
### Out-of-Scope Use
|
| 91 |
+
|
| 92 |
+
- **Other Arabic dialects**: The model was trained primarily on Jordanian Arabic. Performance on Egyptian, Gulf, or Modern Standard Arabic is not validated.
|
| 93 |
+
- **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.
|
| 94 |
+
- **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.
|
| 95 |
+
|
| 96 |
+
## Preprocessing
|
| 97 |
+
|
| 98 |
+
At inference time, apply the following normalisation to input text before passing it to the model:
|
| 99 |
+
|
| 100 |
+
1. URLs replaced with `[رابط]` token
|
| 101 |
+
2. @mentions replaced with `[مستخدم]` token
|
| 102 |
+
3. Email addresses replaced with `[بريد]` token
|
| 103 |
+
4. Numbers removed
|
| 104 |
+
5. Punctuation removed
|
| 105 |
+
6. Arabic diacritics (harakat) removed
|
| 106 |
+
7. Whitespace normalised
|
| 107 |
+
|
| 108 |
+
## Evaluation Results
|
| 109 |
+
|
| 110 |
+
Evaluated on the validation split of [`thejosango/nuha-ajp-dataset`](https://huggingface.co/datasets/thejosango/nuha-ajp-dataset) (methodology configuration):
|
| 111 |
+
|
| 112 |
+
| Metric | Value |
|
| 113 |
+
|---|---|
|
| 114 |
+
| F1 (macro) | 0.5363 |
|
| 115 |
+
| Precision | 0.6660 |
|
| 116 |
+
| Recall | 0.5188 |
|
| 117 |
+
|
| 118 |
+
See [`nuha-ajp-trinary`](https://huggingface.co/thejosango/nuha-ajp-trinary) for full training details and evaluation discussion.
|
| 119 |
+
|
| 120 |
+
---
|
| 121 |
+
|
| 122 |
+
*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": 4,
|
| 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 |
+
}
|
model.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:369fb710b83acca4ad3e7e08dfb30dcf9e044841ceddc31594d1610048ae58a6
|
| 3 |
+
size 314065731
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b669f5b481089b8482caea885a857d77a438c1c5f772e4c983819fccf35aa2f2
|
| 3 |
+
size 313979148
|
pytorch_model.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d0f3499293186d4718646d31ed44bd78d64681b13ee29c83d23a380b284660da
|
| 3 |
+
size 313995148
|
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 |
+
}
|
vocab.txt
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|