File size: 4,350 Bytes
27688b9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
---
license: mit
base_model: unknown
tags:
- vietnamese
- hate-speech-detection
- text-classification
- offensive-language-detection
datasets:
- visolex/vihsd
metrics:
- accuracy
- macro-f1
- weighted-f1
model-index:
- name: bilstm-hsd
  results:
  - task:
      type: text-classification
      name: Hate Speech Detection
    dataset:
      name: ViHSD
      type: hate-speech-detection
    metrics:
    - type: accuracy
      value: 0.8388
    - type: macro-f1
      value: 0.3041
    - type: weighted-f1
      value: 0.7652
    - type: macro-precision
      value: 0.2796
    - type: macro-recall
      value: 0.3333
---

# BILSTM: Hate Speech Detection for Vietnamese Text

This model is a fine-tuned version of [unknown](https://huggingface.co/unknown) 
on the **ViHSD (Vietnamese Hate Speech Detection Dataset)** for classifying Vietnamese text into three categories: CLEAN, OFFENSIVE, and HATE.

## Model Details

* **Base Model**: unknown
* **Description**: bilstm fine-tuned for Vietnamese Hate Speech Detection
* **Architecture**: Unknown
* **Dataset**: ViHSD (Vietnamese Hate Speech Detection Dataset)
* **Fine-tuning Framework**: HuggingFace Transformers + PyTorch
* **Task**: Hate Speech Classification (3 classes)

### Hyperparameters

* **Batch size**: `32`
* **Learning rate**: `2e-5`
* **Epochs**: `100`
* **Max sequence length**: `256`
* **Weight decay**: `0.01`
* **Warmup steps**: `500`
* **Early stopping patience**: `5`
* **Optimizer**: AdamW
* **Learning rate scheduler**: Cosine with warmup

## Dataset

Model was trained on **ViHSD (Vietnamese Hate Speech Detection Dataset)** containing ~10,000 Vietnamese comments from social media.

### Label Descriptions:

* **CLEAN (0)**: Normal content without offensive language
* **OFFENSIVE (1)**: Mildly offensive or inappropriate content  
* **HATE (2)**: Hate speech, extremist language, severe threats

## Evaluation Results

The model was evaluated on test set with the following metrics:

* **Accuracy**: `0.8388`
* **Macro-F1**: `0.3041`
* **Weighted-F1**: `0.7652`
* **Macro-Precision**: `0.2796`
* **Macro-Recall**: `0.3333`

### Basic Usage

```python
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch

# Load model and tokenizer
model_name = "visolex/bilstm-hsd"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(
    model_name
)

# Classify text
text = "Văn bản tiếng Việt cần phân loại"
inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True)

with torch.no_grad():
    outputs = model(**inputs)
    predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
    predicted_label = torch.argmax(predictions, dim=-1).item()

# Label mapping
label_names = {
    0: "CLEAN",
    1: "OFFENSIVE",
    2: "HATE"
}

print(f"Predicted label: {label_names[predicted_label]}")
print(f"Confidence scores: {predictions[0].tolist()}")
```


**⚠️ Note for Vocab-based Models**: This model (`bilstm`) uses custom vocabulary-based tokenization and does not include a Hugging Face tokenizer. You will need to implement custom tokenization or load a tokenizer from a compatible base model. The model expects word-level tokenized input.


## Training Details

### Training Data
- **Dataset**: ViHSD (Vietnamese Hate Speech Detection Dataset)
- **Total samples**: ~10,000 Vietnamese comments from social media
- **Training split**: ~70%
- **Validation split**: ~15%
- **Test split**: ~15%

### Training Configuration
- **Framework**: PyTorch + HuggingFace Transformers
- **Optimizer**: AdamW
- **Learning Rate**: 2e-5
- **Batch Size**: 32
- **Max Length**: 256 tokens
- **Epochs**: 100 (with early stopping patience: 5)
- **Weight Decay**: 0.01
- **Warmup Steps**: 500


## Contact & Support

- **GitHub**: [ViSoLex Hate Speech Detection](https://github.com/visolex/hate-speech-detection)
- **Issues**: [Report Issues](https://github.com/visolex/hate-speech-detection/issues)
- **Questions**: Open a discussion on the model's Hugging Face page

## License

This model is distributed under the MIT License.

## Acknowledgments

- Base model: [unknown](https://huggingface.co/unknown)
- Dataset: ViHSD (Vietnamese Hate Speech Detection Dataset)
- Framework: [Hugging Face Transformers](https://huggingface.co/transformers)
- ViSoLex Toolkit

---