LikoKiko
commited on
Commit
·
09dfad0
1
Parent(s):
939886c
Added H1 files and updated README (Full Release)
Browse files- .gitattributes +1 -0
- README.md +106 -0
- bestthreshold.png +3 -0
- config.json +32 -0
- model.safetensors +3 -0
- special_tokens_map.json +7 -0
- testmetrics.png +3 -0
- tokenizer.json +0 -0
- tokenizer_config.json +58 -0
- valf1perepoch.png +3 -0
- vocab.txt +0 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,4 @@ saved_model/**/* 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
|
|
|
|
|
|
| 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 |
+
*.png filter=lfs diff=lfs merge=lfs -text
|
README.md
CHANGED
|
@@ -1,3 +1,109 @@
|
|
| 1 |
---
|
|
|
|
|
|
|
| 2 |
license: cc-by-sa-4.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
language:
|
| 3 |
+
- he
|
| 4 |
license: cc-by-sa-4.0
|
| 5 |
+
tags:
|
| 6 |
+
- text-classification
|
| 7 |
+
- profanity-detection
|
| 8 |
+
- hebrew
|
| 9 |
+
- bert
|
| 10 |
+
- alephbert
|
| 11 |
+
library_name: transformers
|
| 12 |
+
base_model: onlplab/alephbert-base
|
| 13 |
+
datasets:
|
| 14 |
+
- custom
|
| 15 |
+
metrics:
|
| 16 |
+
- accuracy
|
| 17 |
+
- precision
|
| 18 |
+
- recall
|
| 19 |
+
- f1
|
| 20 |
---
|
| 21 |
+
|
| 22 |
+
# OpenCensor-Hebrew
|
| 23 |
+
|
| 24 |
+
This is a fine tuned **AlephBERT** model that finds bad words ( profanity ) in Hebrew text.
|
| 25 |
+
|
| 26 |
+
You give the model a Hebrew sentence.
|
| 27 |
+
It returns:
|
| 28 |
+
- a score between **0 and 1**
|
| 29 |
+
- a yes/no flag (based on a cutoff you choose)
|
| 30 |
+
|
| 31 |
+
Meaning of the score:
|
| 32 |
+
- **0 = clean**, **1 = has profanity**
|
| 33 |
+
- Recommended cutoff from tests: **0.49** ( you can change it )
|
| 34 |
+
|
| 35 |
+

|
| 36 |
+

|
| 37 |
+

|
| 38 |
+
|
| 39 |
+
## How to use
|
| 40 |
+
|
| 41 |
+
```python
|
| 42 |
+
import torch
|
| 43 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 44 |
+
|
| 45 |
+
KModel = "LikoKIko/OpenCensor-Hebrew"
|
| 46 |
+
KCutoff = 0.49 # best threshold from training
|
| 47 |
+
KMaxLen = 512 # number of tokens (not characters)
|
| 48 |
+
|
| 49 |
+
tokenizer = AutoTokenizer.from_pretrained(KModel)
|
| 50 |
+
model = AutoModelForSequenceClassification.from_pretrained(KModel, num_labels=1).eval()
|
| 51 |
+
|
| 52 |
+
text = "some hebrew text here"
|
| 53 |
+
inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True, max_length=KMaxLen)
|
| 54 |
+
|
| 55 |
+
with torch.inference_mode():
|
| 56 |
+
score = torch.sigmoid(model(**inputs).logits).item()
|
| 57 |
+
KHasProfanity = int(score >= KCutoff)
|
| 58 |
+
|
| 59 |
+
print({"score": round(score, 4), "KHasProfanity": KHasProfanity})
|
| 60 |
+
````
|
| 61 |
+
|
| 62 |
+
Note: If the text is very long, it is cut at `KMaxLen` tokens.
|
| 63 |
+
|
| 64 |
+
## About this model
|
| 65 |
+
|
| 66 |
+
- Base: `onlplab/alephbert-base`
|
| 67 |
+
- Task: binary classification (clean / profanity)
|
| 68 |
+
- Language: Hebrew
|
| 69 |
+
- Max length: 512 tokens
|
| 70 |
+
- Training:
|
| 71 |
+
- Batch size: 16
|
| 72 |
+
- Epochs: 10
|
| 73 |
+
- Learning rate: 0.00002
|
| 74 |
+
- Loss: binary cross-entropy with logits (`BCEWithLogitsLoss`). We use `pos_weight` so the model pays more attention to the rare class. This helps when the dataset is imbalanced.
|
| 75 |
+
- Scheduler: linear warmup (10%)
|
| 76 |
+
|
| 77 |
+
### Results
|
| 78 |
+
|
| 79 |
+
- Test Accuracy: 0.9826
|
| 80 |
+
- Test Precision: 0.9812
|
| 81 |
+
- Test Recall: 0.9835
|
| 82 |
+
- Test F1: 0.9823
|
| 83 |
+
- Best threshold: 0.49
|
| 84 |
+
|
| 85 |
+
## Reproduce (training code)
|
| 86 |
+
|
| 87 |
+
This model was trained with a script that:
|
| 88 |
+
|
| 89 |
+
- Loads `onlplab/alephbert-base` with `num_labels=1`
|
| 90 |
+
- Tokenizes with `max_length=512` and pads to the max length
|
| 91 |
+
- Trains with AdamW, linear warmup, and mixed precision
|
| 92 |
+
- Tries cutoffs from `0.1` to `0.9` on the validation set and picks the best F1
|
| 93 |
+
- Saves the best checkpoint by validation F1, then reports test metrics
|
| 94 |
+
|
| 95 |
+
## License
|
| 96 |
+
|
| 97 |
+
CC-BY-SA-4.0
|
| 98 |
+
|
| 99 |
+
## How to cite
|
| 100 |
+
```
|
| 101 |
+
```bibtex
|
| 102 |
+
@misc{opencensor-hebrew,
|
| 103 |
+
title = {OpenCensor-Hebrew: Hebrew Profanity Detection Model},
|
| 104 |
+
author = {LikoKIko},
|
| 105 |
+
year = {2025},
|
| 106 |
+
url = {[https://huggingface.co/LikoKIko/OpenCensor-Hebrew](https://huggingface.co/LikoKIko/OpenCensor-Hebrew)}
|
| 107 |
+
}
|
| 108 |
+
```
|
| 109 |
+
```
|
bestthreshold.png
ADDED
|
Git LFS Details
|
config.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_name_or_path": "onlplab/alephbert-base",
|
| 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": "LABEL_0"
|
| 14 |
+
},
|
| 15 |
+
"initializer_range": 0.02,
|
| 16 |
+
"intermediate_size": 3072,
|
| 17 |
+
"label2id": {
|
| 18 |
+
"LABEL_0": 0
|
| 19 |
+
},
|
| 20 |
+
"layer_norm_eps": 1e-12,
|
| 21 |
+
"max_position_embeddings": 512,
|
| 22 |
+
"model_type": "bert",
|
| 23 |
+
"num_attention_heads": 12,
|
| 24 |
+
"num_hidden_layers": 12,
|
| 25 |
+
"pad_token_id": 0,
|
| 26 |
+
"position_embedding_type": "absolute",
|
| 27 |
+
"torch_dtype": "float32",
|
| 28 |
+
"transformers_version": "4.39.1",
|
| 29 |
+
"type_vocab_size": 1,
|
| 30 |
+
"use_cache": true,
|
| 31 |
+
"vocab_size": 52000
|
| 32 |
+
}
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b7c15726bd22425a757957bd75f6a67cc889cbe7f0fe39465d07131f27bcdd41
|
| 3 |
+
size 503932924
|
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 |
+
}
|
testmetrics.png
ADDED
|
Git LFS Details
|
tokenizer.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"added_tokens_decoder": {
|
| 3 |
+
"0": {
|
| 4 |
+
"content": "[PAD]",
|
| 5 |
+
"lstrip": false,
|
| 6 |
+
"normalized": false,
|
| 7 |
+
"rstrip": false,
|
| 8 |
+
"single_word": false,
|
| 9 |
+
"special": true
|
| 10 |
+
},
|
| 11 |
+
"1": {
|
| 12 |
+
"content": "[UNK]",
|
| 13 |
+
"lstrip": false,
|
| 14 |
+
"normalized": false,
|
| 15 |
+
"rstrip": false,
|
| 16 |
+
"single_word": false,
|
| 17 |
+
"special": true
|
| 18 |
+
},
|
| 19 |
+
"2": {
|
| 20 |
+
"content": "[CLS]",
|
| 21 |
+
"lstrip": false,
|
| 22 |
+
"normalized": false,
|
| 23 |
+
"rstrip": false,
|
| 24 |
+
"single_word": false,
|
| 25 |
+
"special": true
|
| 26 |
+
},
|
| 27 |
+
"3": {
|
| 28 |
+
"content": "[SEP]",
|
| 29 |
+
"lstrip": false,
|
| 30 |
+
"normalized": false,
|
| 31 |
+
"rstrip": false,
|
| 32 |
+
"single_word": false,
|
| 33 |
+
"special": true
|
| 34 |
+
},
|
| 35 |
+
"4": {
|
| 36 |
+
"content": "[MASK]",
|
| 37 |
+
"lstrip": false,
|
| 38 |
+
"normalized": false,
|
| 39 |
+
"rstrip": false,
|
| 40 |
+
"single_word": false,
|
| 41 |
+
"special": true
|
| 42 |
+
}
|
| 43 |
+
},
|
| 44 |
+
"clean_up_tokenization_spaces": true,
|
| 45 |
+
"cls_token": "[CLS]",
|
| 46 |
+
"do_basic_tokenize": true,
|
| 47 |
+
"do_lower_case": true,
|
| 48 |
+
"mask_token": "[MASK]",
|
| 49 |
+
"max_len": 512,
|
| 50 |
+
"model_max_length": 512,
|
| 51 |
+
"never_split": null,
|
| 52 |
+
"pad_token": "[PAD]",
|
| 53 |
+
"sep_token": "[SEP]",
|
| 54 |
+
"strip_accents": null,
|
| 55 |
+
"tokenize_chinese_chars": true,
|
| 56 |
+
"tokenizer_class": "BertTokenizer",
|
| 57 |
+
"unk_token": "[UNK]"
|
| 58 |
+
}
|
valf1perepoch.png
ADDED
|
Git LFS Details
|
vocab.txt
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|