AnnNaserNabil commited on
Commit
ef10414
·
verified ·
1 Parent(s): b6a34e0

Upload 10 files

Browse files
README.md ADDED
@@ -0,0 +1,97 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: bn
3
+ tags:
4
+ - hate-speech-detection
5
+ - bangla
6
+ - bert
7
+ - binary-classification
8
+ license: mit
9
+ ---
10
+
11
+ # Bangla Hate Speech Detection Model
12
+
13
+ This model is fine-tuned for binary hate speech detection in Bangla text.
14
+
15
+ ## Model Description
16
+
17
+ - **Base Model**: sagorsarker/bangla-bert-base
18
+ - **Task**: Binary Classification (Hate Speech vs Non-Hate Speech)
19
+ - **Language**: Bangla (Bengali)
20
+ - **Training Method**: Baseline training only (original behavior)
21
+
22
+ ## Training Details
23
+
24
+ ### Training Hyperparameters
25
+
26
+ - **Batch Size**: 64
27
+ - **Learning Rate**: 3e-05
28
+ - **Epochs**: 30
29
+ - **Max Sequence Length**: 128
30
+ - **Dropout**: 0.1
31
+ - **Weight Decay**: 0.01
32
+ - **Warmup Ratio**: 0.1
33
+
34
+ ### Training Data
35
+
36
+ - **K-Fold Cross-Validation**: 5 folds
37
+ - **Stratification**: binary
38
+
39
+ ## Performance
40
+
41
+ *Add your metrics here after training*
42
+
43
+ ## Usage
44
+
45
+ ```python
46
+ from transformers import AutoModel, AutoTokenizer
47
+ import torch
48
+ import torch.nn as nn
49
+ import json
50
+
51
+ # Load model components
52
+ encoder = AutoModel.from_pretrained("path/to/model")
53
+
54
+ with open("path/to/model/classifier_config.json", 'r') as f:
55
+ c_config = json.load(f)
56
+
57
+ classifier = nn.Sequential(
58
+ nn.Linear(c_config['hidden_size'], 256),
59
+ nn.ReLU(),
60
+ nn.Dropout(0.1),
61
+ nn.Linear(256, c_config['num_labels'])
62
+ )
63
+ classifier.load_state_dict(torch.load("path/to/model/classifier.pt"))
64
+
65
+ tokenizer = AutoTokenizer.from_pretrained("path/to/model")
66
+
67
+ # Predict
68
+ def predict(text):
69
+ inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=128)
70
+ with torch.no_grad():
71
+ outputs = encoder(**inputs)
72
+ cls_embedding = outputs.last_hidden_state[:, 0, :]
73
+ logits = classifier(cls_embedding)
74
+ prob = torch.sigmoid(logits).item()
75
+ return prob
76
+
77
+ text = "আপনার বাংলা টেক্সট এখানে"
78
+ prob = predict(text)
79
+ print(f"Hate Speech Probability: {prob:.4f}")
80
+ ```
81
+
82
+ ## Citation
83
+
84
+ If you use this model, please cite:
85
+
86
+ ```bibtex
87
+ @misc{bangla-hate-speech-model,
88
+ author = {Nabil},
89
+ title = {Bangla Hate Speech Detection Model},
90
+ year = {2026},
91
+ publisher = {HuggingFace},
92
+ }
93
+ ```
94
+
95
+ ## License
96
+
97
+ MIT License
classifier.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:de96f2aa32ddf22e241c24b451182d6dfcc0562316af65a75fbc48d7db950180
3
+ size 790568
classifier_config.json ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ {
2
+ "type": "sequential",
3
+ "layers": "Sequential(\n (0): Linear(in_features=768, out_features=256, bias=True)\n (1): ReLU()\n (2): Dropout(p=0.1, inplace=False)\n (3): Linear(in_features=256, out_features=1, bias=True)\n)",
4
+ "num_labels": 1,
5
+ "hidden_size": 768
6
+ }
config.json ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "BertModel"
4
+ ],
5
+ "attention_probs_dropout_prob": 0.1,
6
+ "classifier_dropout": null,
7
+ "hidden_act": "gelu",
8
+ "hidden_dropout_prob": 0.1,
9
+ "hidden_size": 768,
10
+ "initializer_range": 0.02,
11
+ "intermediate_size": 3072,
12
+ "layer_norm_eps": 1e-12,
13
+ "max_position_embeddings": 512,
14
+ "model_type": "bert",
15
+ "num_attention_heads": 12,
16
+ "num_hidden_layers": 12,
17
+ "output_hidden_states": true,
18
+ "pad_token_id": 0,
19
+ "position_embedding_type": "absolute",
20
+ "torch_dtype": "float32",
21
+ "transformers_version": "4.53.3",
22
+ "type_vocab_size": 2,
23
+ "use_cache": true,
24
+ "vocab_size": 102025
25
+ }
how_to_load.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # How to load this model:
2
+
3
+ from transformers import AutoModel, AutoTokenizer
4
+ import torch
5
+ import torch.nn as nn
6
+ import json
7
+
8
+ # Load encoder
9
+ encoder = AutoModel.from_pretrained("./outputs/final_baseline_best")
10
+
11
+ # Load classifier config
12
+ with open("./outputs/final_baseline_best/classifier_config.json", 'r') as f:
13
+ c_config = json.load(f)
14
+
15
+ num_labels = c_config.get('num_labels', 1)
16
+ hidden_size = c_config.get('hidden_size', 768)
17
+
18
+ # Reconstruct classifier
19
+ classifier = nn.Sequential(
20
+ nn.Linear(hidden_size, 256),
21
+ nn.ReLU(),
22
+ nn.Dropout(0.1),
23
+ nn.Linear(256, num_labels)
24
+ )
25
+ classifier.load_state_dict(torch.load("./outputs/final_baseline_best/classifier.pt"))
26
+
27
+ # Load tokenizer
28
+ tokenizer = AutoTokenizer.from_pretrained("./outputs/final_baseline_best")
29
+
30
+ # Inference function
31
+ def predict(text):
32
+ inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=128)
33
+ with torch.no_grad():
34
+ outputs = encoder(**inputs)
35
+ cls_embedding = outputs.last_hidden_state[:, 0, :]
36
+ logits = classifier(cls_embedding)
37
+ probs = torch.sigmoid(logits)
38
+ return probs.item()
39
+
40
+ # Example
41
+ text = "আপনার বাংলা টেক্সট এখানে"
42
+ prob = predict(text)
43
+ print(f"Hate Speech Probability: {prob:.4f}")
44
+ print(f"Prediction: {'Hate Speech' if prob > 0.5 else 'Non-Hate Speech'}")
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9800f124cda999ddcb04ae94278259ef18bf2e8780438c8eff03fe98babe2a55
3
+ size 657608552
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,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
+ "100": {
12
+ "content": "[UNK]",
13
+ "lstrip": false,
14
+ "normalized": false,
15
+ "rstrip": false,
16
+ "single_word": false,
17
+ "special": true
18
+ },
19
+ "101": {
20
+ "content": "[CLS]",
21
+ "lstrip": false,
22
+ "normalized": false,
23
+ "rstrip": false,
24
+ "single_word": false,
25
+ "special": true
26
+ },
27
+ "102": {
28
+ "content": "[SEP]",
29
+ "lstrip": false,
30
+ "normalized": false,
31
+ "rstrip": false,
32
+ "single_word": false,
33
+ "special": true
34
+ },
35
+ "103": {
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
+ "extra_special_tokens": {},
49
+ "mask_token": "[MASK]",
50
+ "model_max_length": 1000000000000000019884624838656,
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
+ }
vocab.txt ADDED
The diff for this file is too large to render. See raw diff