tamim65 commited on
Commit
82892b8
·
verified ·
1 Parent(s): 29ac9ac

Upload Production V3 multi-label model

Browse files
README.md ADDED
@@ -0,0 +1,119 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: bn
3
+ tags:
4
+ - hate-speech-detection
5
+ - bangla
6
+ - multilabel-classification
7
+ - banglabert
8
+ license: mit
9
+ datasets:
10
+ - custom
11
+ metrics:
12
+ - f1
13
+ - precision
14
+ - recall
15
+ ---
16
+
17
+ # BanglaBERT Hate Speech Detection - Production V3
18
+
19
+ Production V3 multi-label hate speech detection model for Bangla text.
20
+
21
+ ## Model Architecture
22
+
23
+ - **Base Model**: BanglaBERT (sagorsarker/bangla-bert-base)
24
+ - **Architecture**: Advanced Dual-Head with Label-Aware Attention
25
+ - **Task**: Multi-label classification
26
+ - **Labels**: 7 categories (vulgar, hate, religious, threat, troll, insult, safe)
27
+
28
+ ## Features
29
+
30
+ - **Label-Aware Attention**: Each label has specialized attention mechanism
31
+ - **Multi-Scale Feature Extraction**: 3 convolutional scales (kernel 3, 5, 7)
32
+ - **Label Co-occurrence Module**: Captures inter-label relationships
33
+ - **Per-Label Threshold Optimization**: Individual thresholds for each label
34
+ - **Safe Label Exclusivity**: Intelligent conflict resolution
35
+
36
+ ## Usage
37
+
38
+ ```python
39
+ import torch
40
+ from transformers import AutoTokenizer
41
+ import pickle
42
+
43
+ # Load model and tokenizer
44
+ model_path = "tamim65/banglabert-hate-speech-prod-v3"
45
+ tokenizer = AutoTokenizer.from_pretrained(model_path)
46
+
47
+ # Load full model (custom architecture)
48
+ model = torch.load(f"{model_path}/full_model.pt", map_location='cpu')
49
+ model.eval()
50
+
51
+ # Load metadata and thresholds
52
+ with open(f"{model_path}/metadata.pkl", 'rb') as f:
53
+ metadata = pickle.load(f)
54
+ with open(f"{model_path}/optimal_thresholds.pkl", 'rb') as f:
55
+ optimal_thresholds = pickle.load(f)
56
+
57
+ # Predict
58
+ def predict(text):
59
+ inputs = tokenizer(text, return_tensors='pt', padding=True, truncation=True, max_length=128)
60
+ with torch.no_grad():
61
+ outputs = model(**inputs)
62
+ probs = torch.sigmoid(outputs).cpu().numpy()[0]
63
+
64
+ # Apply thresholds
65
+ predictions = {}
66
+ for i, label in enumerate(metadata['label_names']):
67
+ predictions[label] = {
68
+ 'probability': float(probs[i]),
69
+ 'predicted': bool(probs[i] >= optimal_thresholds[i])
70
+ }
71
+
72
+ return predictions
73
+
74
+ # Example
75
+ text = "আপনার মন্তব্য খুব সুন্দর"
76
+ result = predict(text)
77
+ print(result)
78
+ ```
79
+
80
+ ## Performance
81
+
82
+ - Optimized thresholds for each label
83
+ - Handles multi-label scenarios effectively
84
+ - Safe label exclusivity prevents false positives
85
+
86
+ ## Training Details
87
+
88
+ - **Optimizer**: AdamW
89
+ - **Learning Rate**: 2e-5
90
+ - **Batch Size**: 16
91
+ - **Epochs**: 10
92
+ - **Loss**: Binary Cross Entropy with Logits
93
+
94
+ ## Files
95
+
96
+ - `full_model.pt`: Complete model with custom architecture
97
+ - `model.safetensors`: Model weights (safetensors format)
98
+ - `config.json`: Model configuration
99
+ - `tokenizer.json`, `vocab.txt`: Tokenizer files
100
+ - `metadata.pkl`: Label names and metadata
101
+ - `optimal_thresholds.pkl`: Per-label threshold values
102
+
103
+ ## Citation
104
+
105
+ If you use this model, please cite:
106
+
107
+ ```bibtex
108
+ @misc{banglabert-hate-speech-v3,
109
+ author = {Tamim},
110
+ title = {BanglaBERT Hate Speech Detection - Production V3},
111
+ year = {2025},
112
+ publisher = {HuggingFace},
113
+ howpublished = {\url{https://huggingface.co/tamim65/banglabert-hate-speech-prod-v3}}
114
+ }
115
+ ```
116
+
117
+ ## License
118
+
119
+ MIT License
config.json ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "ElectraModel"
4
+ ],
5
+ "attention_probs_dropout_prob": 0.1,
6
+ "classifier_dropout": null,
7
+ "dtype": "float32",
8
+ "embedding_size": 768,
9
+ "hidden_act": "gelu",
10
+ "hidden_dropout_prob": 0.1,
11
+ "hidden_size": 768,
12
+ "initializer_range": 0.02,
13
+ "intermediate_size": 3072,
14
+ "layer_norm_eps": 1e-12,
15
+ "max_position_embeddings": 512,
16
+ "model_type": "electra",
17
+ "num_attention_heads": 12,
18
+ "num_hidden_layers": 12,
19
+ "pad_token_id": 0,
20
+ "position_embedding_type": "absolute",
21
+ "summary_activation": "gelu",
22
+ "summary_last_dropout": 0.1,
23
+ "summary_type": "first",
24
+ "summary_use_proj": true,
25
+ "transformers_version": "4.57.1",
26
+ "type_vocab_size": 2,
27
+ "use_cache": true,
28
+ "vocab_size": 32000
29
+ }
full_model.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e166367b4e318aef22a0628e84febf3fbf87d2505620ad37876409a757a0e7cf
3
+ size 525235522
metadata.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d63f8eda404c3573109b541a39496819e6fd6e3be7d39658ba5421585cecebc9
3
+ size 419
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d8930a1d5e7a5b64f87137d6afc648b14dcfb78f52e7f4aa07e1ac22c62f72d5
3
+ size 440129200
optimal_thresholds.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:67187ed8845182843cfeca0c4e3e8fa8fd14f2d91b6719584dc9973af0d8afbb
3
+ size 296
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,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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": false,
48
+ "extra_special_tokens": {},
49
+ "full_tokenizer_file": null,
50
+ "mask_token": "[MASK]",
51
+ "model_max_length": 1000000000000000019884624838656,
52
+ "never_split": null,
53
+ "pad_token": "[PAD]",
54
+ "sep_token": "[SEP]",
55
+ "strip_accents": null,
56
+ "tokenize_chinese_chars": false,
57
+ "tokenizer_class": "ElectraTokenizer",
58
+ "unk_token": "[UNK]"
59
+ }
vocab.txt ADDED
The diff for this file is too large to render. See raw diff