AnnNaserNabil commited on
Commit
2501840
·
verified ·
1 Parent(s): 2c34278

Upload 10 files

Browse files
.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
+ tokenizer.json filter=lfs diff=lfs merge=lfs -text
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**: FacebookAI/xlm-roberta-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**: 32
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:ccee955253bd0bc56ab980049a6e1f7676b3a7d00e5d0a507b6ed0e2abcf2602
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,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "XLMRobertaModel"
4
+ ],
5
+ "attention_probs_dropout_prob": 0.1,
6
+ "bos_token_id": 0,
7
+ "classifier_dropout": null,
8
+ "eos_token_id": 2,
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-05,
15
+ "max_position_embeddings": 514,
16
+ "model_type": "xlm-roberta",
17
+ "num_attention_heads": 12,
18
+ "num_hidden_layers": 12,
19
+ "output_hidden_states": true,
20
+ "output_past": true,
21
+ "pad_token_id": 1,
22
+ "position_embedding_type": "absolute",
23
+ "torch_dtype": "float32",
24
+ "transformers_version": "4.53.3",
25
+ "type_vocab_size": 1,
26
+ "use_cache": true,
27
+ "vocab_size": 250002
28
+ }
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:cb73c2a2db553e18038726794a9881ff09daad7d3b555dea7be64098f51f88c2
3
+ size 1112197096
sentencepiece.bpe.model ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:cfc8146abe2a0488e9e2a0c56de7952f7c11ab059eca145a0a727afce0db2865
3
+ size 5069051
special_tokens_map.json ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": "<s>",
3
+ "cls_token": "<s>",
4
+ "eos_token": "</s>",
5
+ "mask_token": {
6
+ "content": "<mask>",
7
+ "lstrip": true,
8
+ "normalized": false,
9
+ "rstrip": false,
10
+ "single_word": false
11
+ },
12
+ "pad_token": "<pad>",
13
+ "sep_token": "</s>",
14
+ "unk_token": "<unk>"
15
+ }
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3a56def25aa40facc030ea8b0b87f3688e4b3c39eb8b45d5702b3a1300fe2a20
3
+ size 17082734
tokenizer_config.json ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "added_tokens_decoder": {
3
+ "0": {
4
+ "content": "<s>",
5
+ "lstrip": false,
6
+ "normalized": false,
7
+ "rstrip": false,
8
+ "single_word": false,
9
+ "special": true
10
+ },
11
+ "1": {
12
+ "content": "<pad>",
13
+ "lstrip": false,
14
+ "normalized": false,
15
+ "rstrip": false,
16
+ "single_word": false,
17
+ "special": true
18
+ },
19
+ "2": {
20
+ "content": "</s>",
21
+ "lstrip": false,
22
+ "normalized": false,
23
+ "rstrip": false,
24
+ "single_word": false,
25
+ "special": true
26
+ },
27
+ "3": {
28
+ "content": "<unk>",
29
+ "lstrip": false,
30
+ "normalized": false,
31
+ "rstrip": false,
32
+ "single_word": false,
33
+ "special": true
34
+ },
35
+ "250001": {
36
+ "content": "<mask>",
37
+ "lstrip": true,
38
+ "normalized": false,
39
+ "rstrip": false,
40
+ "single_word": false,
41
+ "special": true
42
+ }
43
+ },
44
+ "bos_token": "<s>",
45
+ "clean_up_tokenization_spaces": false,
46
+ "cls_token": "<s>",
47
+ "eos_token": "</s>",
48
+ "extra_special_tokens": {},
49
+ "mask_token": "<mask>",
50
+ "model_max_length": 512,
51
+ "pad_token": "<pad>",
52
+ "sep_token": "</s>",
53
+ "tokenizer_class": "XLMRobertaTokenizer",
54
+ "unk_token": "<unk>"
55
+ }