AnnNaserNabil commited on
Commit
fb10267
·
verified ·
1 Parent(s): 0f02f07

Upload 10 files

Browse files
README.md CHANGED
@@ -1,3 +1,97 @@
1
- ---
2
- license: mit
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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**: md-nishat-008/Mixed-Distil-BERT
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**: 16
27
+ - **Learning Rate**: 1e-05
28
+ - **Epochs**: 10
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:e5fd4d1a658194d203ce2a06dc79777d53f6f4dcf35d909bcb987857cbe6bc43
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,24 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "activation": "gelu",
3
+ "architectures": [
4
+ "DistilBertModel"
5
+ ],
6
+ "attention_dropout": 0.1,
7
+ "dim": 768,
8
+ "dropout": 0.1,
9
+ "hidden_dim": 3072,
10
+ "initializer_range": 0.02,
11
+ "max_position_embeddings": 512,
12
+ "model_type": "distilbert",
13
+ "n_heads": 12,
14
+ "n_layers": 6,
15
+ "output_hidden_states": true,
16
+ "pad_token_id": 0,
17
+ "qa_dropout": 0.1,
18
+ "seq_classif_dropout": 0.2,
19
+ "sinusoidal_pos_embds": false,
20
+ "tie_weights_": true,
21
+ "torch_dtype": "float32",
22
+ "transformers_version": "4.53.3",
23
+ "vocab_size": 30522
24
+ }
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:2a617546ae639c094a9af5596f01afa78dec6a80b727adf1df7ce96279c65ad1
3
+ size 265462608
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": 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": "DistilBertTokenizer",
57
+ "unk_token": "[UNK]"
58
+ }
vocab.txt ADDED
The diff for this file is too large to render. See raw diff