File size: 5,897 Bytes
aa2a5c8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
---
language:
- vi
tags:
- hate-speech-detection
- vietnamese-nlp
- text-classification
- offensive-language-detection
license: mit
datasets:
- vihsd
base_model: vinai/bartpho-syllable-base
---

# BARTpho

BARTpho fine-tuned cho bài toán phân loại Hate Speech tiếng Việt

## Model Details

### Model Type
BARTpho (Bidirectional and Auto-Regressive Transformer cho tiếng Việt)

### Base Model
This model is fine-tuned from [vinai/bartpho-syllable-base](https://huggingface.co/vinai/bartpho-syllable-base)

### Training Info
- **Task**: Hate Speech Classification
- **Language**: Vietnamese
- **Labels**: 
  - `0`: CLEAN (Normal content)
  - `1`: OFFENSIVE (Mildly offensive content)
  - `2`: HATE (Hate speech)

## 📊 Model Performance

| Metric | Score |
|--------|-------|
| Accuracy | 0.8985 |
| F1 Macro | 0.6791 |
| F1 Weighted | 0.8886 |

## Model Description

This model has been fine-tuned on the ViHSD (Vietnamese Hate Speech Dataset) to classify Vietnamese text into three categories: CLEAN, OFFENSIVE, and HATE.

### Architecture
BARTpho (Bidirectional and Auto-Regressive Transformer cho tiếng Việt)

The model combines the powerful pretrained representations with task-specific fine-tuning for effective hate speech detection in Vietnamese social media content.

## How to Use

### 1. Using Transformers Pipeline

```python
from transformers import pipeline

# Initialize the hate speech classifier
classifier = pipeline(
    "text-classification",
    model="visolex/hate-speech-bartpho",
    tokenizer="visolex/hate-speech-bartpho",
    return_all_scores=True
)

# Classify text
results = classifier("Văn bản tiếng Việt cần kiểm tra")
print(results)
```

### 2. Using AutoModel

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

# Load model and tokenizer
model_name = "visolex/hate-speech-bartpho"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name)

# Prepare text
text = "Văn bản tiếng Việt cần kiểm tra"
inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True, max_length=256)

# Get predictions
with torch.no_grad():
    outputs = model(**inputs)
    logits = outputs.logits
    
    # Get probabilities
    probabilities = torch.nn.functional.softmax(logits, dim=-1)
    
    # Get predicted label
    predicted_label = torch.argmax(probabilities, dim=-1).item()
    confidence = probabilities[0][predicted_label].item()

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

print(f"Predicted: {label_mapping[predicted_label]} (Confidence: {confidence:.2%})")
```

### 3. Batch Processing

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

model_name = "visolex/hate-speech-bartpho"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name)

# List of texts to classify
texts = [
    "Bài viết rất hay và bổ ích",
    "Đồ ngu người ta nói đúng mà",
    "Cút đi đồ chó"
]

# Tokenize and predict
inputs = tokenizer(texts, return_tensors="pt", padding=True, truncation=True, max_length=256)

with torch.no_grad():
    outputs = model(**inputs)
    predictions = torch.argmax(outputs.logits, dim=-1)

for text, pred in zip(texts, predictions):
    label = ["CLEAN", "OFFENSIVE", "HATE"][pred.item()]
    print(f"{text[:50]} -> {label}")
```

## 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**: Optimized via early stopping

### Preprocessing
- Text normalization for Vietnamese
- Special character handling
- Emoji and slang processing

## Evaluation Results

Model evaluation metrics on the ViHSD test set: See Model Performance section above for details.

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

## Use Cases

- **Social Media Moderation**: Automatic detection of hate speech in Vietnamese social media platforms
- **Content Filtering**: Filtering offensive content in Vietnamese text
- **Research**: Studying hate speech patterns in Vietnamese online communities

## Limitations and Considerations

⚠️ **Important Limitations**:
- Model trained primarily on social media data, may not generalize to formal text
- Performance may vary with slang, code-switching, or regional dialects
- Model reflects biases present in training data
- Should be used as part of a larger moderation system, not sole decision-maker

## Citation

If you use this model in your research, please cite:

```bibtex
@software{vihsd_bartpho,
  title = {BARTpho for Vietnamese Hate Speech Detection},
  author = {ViSoLex Team},
  year = {2024},
  url = {https://huggingface.co/visolex/hate-speech-bartpho},
  base_model = {vinai/bartpho-syllable-base}
}
```

## 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 trained by vinai
- Dataset: ViHSD (Vietnamese Hate Speech Detection Dataset)
- Framework: [Hugging Face Transformers](https://huggingface.co/transformers)