LikoKiko commited on
Commit
ff868bf
·
0 Parent(s):

Initial commit

Browse files
.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
+ *.png filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,107 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.29** ( you can change it )
34
+
35
+ ![Validation F1 per Epoch](valf1perepoch.png)
36
+ ![Final Test Metrics](testmetrics.png)
37
+ ![Best Threshold](bestthreshold.png)
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.29 # best threshold from training
47
+ KMaxLen = 256 # 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: 256 tokens
70
+ - Training (this run):
71
+ - Batch size: 32
72
+ - Epochs: 10
73
+ - Learning rate: 0.000015
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 (this run)
78
+
79
+ - Test Accuracy: 0.9740
80
+ - Test Precision: 0.9726
81
+ - Test Recall: 0.9708
82
+ - Test F1: 0.9717
83
+ - Best threshold: 0.29
84
+
85
+ ## Reproduce (training code)
86
+
87
+ This model was trained with a script that:
88
+ - Loads `onlplab/alephbert-base` with `num_labels=1`
89
+ - Tokenizes with `max_length=256` and pads to the max length
90
+ - Trains with AdamW, linear warmup, and mixed precision
91
+ - Tries cutoffs from `0.05` to `0.95` on the validation set and picks the best F1
92
+ - Saves the best checkpoint by validation F1, then reports test metrics
93
+
94
+ ## License
95
+
96
+ CC-BY-SA-4.0
97
+
98
+ ## How to cite
99
+
100
+ ```bibtex
101
+ @misc{opencensor-hebrew,
102
+ title = {OpenCensor-Hebrew: Hebrew Profanity Detection Model},
103
+ author = {LikoKIko},
104
+ year = {2025},
105
+ url = {https://huggingface.co/LikoKIko/OpenCensor-Hebrew}
106
+ }
107
+ ```
bestthreshold.png ADDED

Git LFS Details

  • SHA256: 88dd499b308a8943e0e614f5f87966e07f3eb341a1f8651d2c8b5ad0feda09d9
  • Pointer size: 130 Bytes
  • Size of remote file: 21.8 kB
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:417aa196c649d1b5677e08d7fffa15e05b621330e55f97a63123df94e036bc8a
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

  • SHA256: aee4b9ee2c451475d4b9f203d91a8902642e82a8972d0f89568af6b07810db88
  • Pointer size: 130 Bytes
  • Size of remote file: 50.8 kB
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

  • SHA256: b6d3bb050ec8b670650712fb0bcf6738a34431d01c9cb1415464c7fca3c62ea9
  • Pointer size: 131 Bytes
  • Size of remote file: 105 kB
vocab.txt ADDED
The diff for this file is too large to render. See raw diff