Upload README.md with huggingface_hub
Browse files
README.md
CHANGED
|
@@ -1,68 +1,211 @@
|
|
| 1 |
---
|
| 2 |
-
language:
|
|
|
|
| 3 |
tags:
|
| 4 |
- hate-speech-detection
|
| 5 |
-
- vietnamese
|
| 6 |
-
-
|
| 7 |
-
|
|
|
|
| 8 |
datasets:
|
| 9 |
-
-
|
| 10 |
-
|
| 11 |
-
- accuracy
|
| 12 |
-
- f1
|
| 13 |
-
model-index:
|
| 14 |
-
- name: bartpho-hsd
|
| 15 |
-
results:
|
| 16 |
-
- task:
|
| 17 |
-
type: text-classification
|
| 18 |
-
name: Hate Speech Detection
|
| 19 |
-
dataset:
|
| 20 |
-
name: VN-HSD
|
| 21 |
-
type: custom
|
| 22 |
-
metrics:
|
| 23 |
-
- name: Accuracy
|
| 24 |
-
type: accuracy
|
| 25 |
-
value: <INSERT_ACCURACY>
|
| 26 |
-
- name: F1 Score
|
| 27 |
-
type: f1
|
| 28 |
-
value: <INSERT_F1_SCORE>
|
| 29 |
-
base_model:
|
| 30 |
-
- vinai/bartpho-base
|
| 31 |
-
pipeline_tag: text-classification
|
| 32 |
---
|
| 33 |
|
| 34 |
-
#
|
| 35 |
|
| 36 |
-
|
| 37 |
|
| 38 |
## Model Details
|
| 39 |
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
* **Fine‑tuning**: HuggingFace Transformers
|
| 43 |
|
| 44 |
-
###
|
|
|
|
| 45 |
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
|
|
|
|
|
|
|
|
|
| 50 |
|
| 51 |
-
##
|
| 52 |
|
| 53 |
-
|
| 54 |
-
|
|
|
|
|
|
|
|
|
|
| 55 |
|
| 56 |
-
##
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
```python
|
| 59 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
-
|
| 62 |
-
model = AutoModelForSequenceClassification.from_pretrained("visolex/bartpho-hsd")
|
| 63 |
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
print(f"Dự đoán: {['CLEAN','OFFENSIVE','HATE'][pred]}")
|
| 68 |
-
```
|
|
|
|
| 1 |
---
|
| 2 |
+
language:
|
| 3 |
+
- vi
|
| 4 |
tags:
|
| 5 |
- hate-speech-detection
|
| 6 |
+
- vietnamese-nlp
|
| 7 |
+
- text-classification
|
| 8 |
+
- offensive-language-detection
|
| 9 |
+
license: mit
|
| 10 |
datasets:
|
| 11 |
+
- vihsd
|
| 12 |
+
base_model: vinai/bartpho-syllable-base
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
---
|
| 14 |
|
| 15 |
+
# BARTpho
|
| 16 |
|
| 17 |
+
BARTpho fine-tuned cho bài toán phân loại Hate Speech tiếng Việt
|
| 18 |
|
| 19 |
## Model Details
|
| 20 |
|
| 21 |
+
### Model Type
|
| 22 |
+
BARTpho (Bidirectional and Auto-Regressive Transformer cho tiếng Việt)
|
|
|
|
| 23 |
|
| 24 |
+
### Base Model
|
| 25 |
+
This model is fine-tuned from [vinai/bartpho-syllable-base](https://huggingface.co/vinai/bartpho-syllable-base)
|
| 26 |
|
| 27 |
+
### Training Info
|
| 28 |
+
- **Task**: Hate Speech Classification
|
| 29 |
+
- **Language**: Vietnamese
|
| 30 |
+
- **Labels**:
|
| 31 |
+
- `0`: CLEAN (Normal content)
|
| 32 |
+
- `1`: OFFENSIVE (Mildly offensive content)
|
| 33 |
+
- `2`: HATE (Hate speech)
|
| 34 |
|
| 35 |
+
## 📊 Model Performance
|
| 36 |
|
| 37 |
+
| Metric | Score |
|
| 38 |
+
|--------|-------|
|
| 39 |
+
| Accuracy | 0.8985 |
|
| 40 |
+
| F1 Macro | 0.6791 |
|
| 41 |
+
| F1 Weighted | 0.8886 |
|
| 42 |
|
| 43 |
+
## Model Description
|
| 44 |
+
|
| 45 |
+
This model has been fine-tuned on the ViHSD (Vietnamese Hate Speech Dataset) to classify Vietnamese text into three categories: CLEAN, OFFENSIVE, and HATE.
|
| 46 |
+
|
| 47 |
+
### Architecture
|
| 48 |
+
BARTpho (Bidirectional and Auto-Regressive Transformer cho tiếng Việt)
|
| 49 |
+
|
| 50 |
+
The model combines the powerful pretrained representations with task-specific fine-tuning for effective hate speech detection in Vietnamese social media content.
|
| 51 |
+
|
| 52 |
+
## How to Use
|
| 53 |
+
|
| 54 |
+
### 1. Using Transformers Pipeline
|
| 55 |
+
|
| 56 |
+
```python
|
| 57 |
+
from transformers import pipeline
|
| 58 |
+
|
| 59 |
+
# Initialize the hate speech classifier
|
| 60 |
+
classifier = pipeline(
|
| 61 |
+
"text-classification",
|
| 62 |
+
model="visolex/hate-speech-bartpho",
|
| 63 |
+
tokenizer="visolex/hate-speech-bartpho",
|
| 64 |
+
return_all_scores=True
|
| 65 |
+
)
|
| 66 |
+
|
| 67 |
+
# Classify text
|
| 68 |
+
results = classifier("Văn bản tiếng Việt cần kiểm tra")
|
| 69 |
+
print(results)
|
| 70 |
+
```
|
| 71 |
+
|
| 72 |
+
### 2. Using AutoModel
|
| 73 |
|
| 74 |
```python
|
| 75 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 76 |
+
import torch
|
| 77 |
+
|
| 78 |
+
# Load model and tokenizer
|
| 79 |
+
model_name = "visolex/hate-speech-bartpho"
|
| 80 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 81 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
| 82 |
+
|
| 83 |
+
# Prepare text
|
| 84 |
+
text = "Văn bản tiếng Việt cần kiểm tra"
|
| 85 |
+
inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True, max_length=256)
|
| 86 |
+
|
| 87 |
+
# Get predictions
|
| 88 |
+
with torch.no_grad():
|
| 89 |
+
outputs = model(**inputs)
|
| 90 |
+
logits = outputs.logits
|
| 91 |
+
|
| 92 |
+
# Get probabilities
|
| 93 |
+
probabilities = torch.nn.functional.softmax(logits, dim=-1)
|
| 94 |
+
|
| 95 |
+
# Get predicted label
|
| 96 |
+
predicted_label = torch.argmax(probabilities, dim=-1).item()
|
| 97 |
+
confidence = probabilities[0][predicted_label].item()
|
| 98 |
+
|
| 99 |
+
# Label mapping
|
| 100 |
+
label_mapping = {
|
| 101 |
+
0: "CLEAN",
|
| 102 |
+
1: "OFFENSIVE",
|
| 103 |
+
2: "HATE"
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
print(f"Predicted: {label_mapping[predicted_label]} (Confidence: {confidence:.2%})")
|
| 107 |
+
```
|
| 108 |
+
|
| 109 |
+
### 3. Batch Processing
|
| 110 |
+
|
| 111 |
+
```python
|
| 112 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 113 |
+
import torch
|
| 114 |
+
|
| 115 |
+
model_name = "visolex/hate-speech-bartpho"
|
| 116 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 117 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
| 118 |
+
|
| 119 |
+
# List of texts to classify
|
| 120 |
+
texts = [
|
| 121 |
+
"Bài viết rất hay và bổ ích",
|
| 122 |
+
"Đồ ngu người ta nói đúng mà",
|
| 123 |
+
"Cút đi đồ chó"
|
| 124 |
+
]
|
| 125 |
+
|
| 126 |
+
# Tokenize and predict
|
| 127 |
+
inputs = tokenizer(texts, return_tensors="pt", padding=True, truncation=True, max_length=256)
|
| 128 |
+
|
| 129 |
+
with torch.no_grad():
|
| 130 |
+
outputs = model(**inputs)
|
| 131 |
+
predictions = torch.argmax(outputs.logits, dim=-1)
|
| 132 |
+
|
| 133 |
+
for text, pred in zip(texts, predictions):
|
| 134 |
+
label = ["CLEAN", "OFFENSIVE", "HATE"][pred.item()]
|
| 135 |
+
print(f"{text[:50]} -> {label}")
|
| 136 |
+
```
|
| 137 |
+
|
| 138 |
+
## Training Details
|
| 139 |
+
|
| 140 |
+
### Training Data
|
| 141 |
+
- **Dataset**: ViHSD (Vietnamese Hate Speech Detection Dataset)
|
| 142 |
+
- **Total samples**: ~10,000 Vietnamese comments from social media
|
| 143 |
+
- **Training split**: ~70%
|
| 144 |
+
- **Validation split**: ~15%
|
| 145 |
+
- **Test split**: ~15%
|
| 146 |
+
|
| 147 |
+
### Training Configuration
|
| 148 |
+
- **Framework**: PyTorch + HuggingFace Transformers
|
| 149 |
+
- **Optimizer**: AdamW
|
| 150 |
+
- **Learning Rate**: 2e-5
|
| 151 |
+
- **Batch Size**: 32
|
| 152 |
+
- **Max Length**: 256 tokens
|
| 153 |
+
- **Epochs**: Optimized via early stopping
|
| 154 |
+
|
| 155 |
+
### Preprocessing
|
| 156 |
+
- Text normalization for Vietnamese
|
| 157 |
+
- Special character handling
|
| 158 |
+
- Emoji and slang processing
|
| 159 |
+
|
| 160 |
+
## Evaluation Results
|
| 161 |
+
|
| 162 |
+
Model evaluation metrics on the ViHSD test set: See Model Performance section above for details.
|
| 163 |
+
|
| 164 |
+
### Label Distribution
|
| 165 |
+
- **CLEAN (0)**: Normal content without offensive language
|
| 166 |
+
- **OFFENSIVE (1)**: Mildly offensive or inappropriate content
|
| 167 |
+
- **HATE (2)**: Hate speech, extremist language, severe threats
|
| 168 |
+
|
| 169 |
+
## Use Cases
|
| 170 |
+
|
| 171 |
+
- **Social Media Moderation**: Automatic detection of hate speech in Vietnamese social media platforms
|
| 172 |
+
- **Content Filtering**: Filtering offensive content in Vietnamese text
|
| 173 |
+
- **Research**: Studying hate speech patterns in Vietnamese online communities
|
| 174 |
+
|
| 175 |
+
## Limitations and Considerations
|
| 176 |
+
|
| 177 |
+
⚠️ **Important Limitations**:
|
| 178 |
+
- Model trained primarily on social media data, may not generalize to formal text
|
| 179 |
+
- Performance may vary with slang, code-switching, or regional dialects
|
| 180 |
+
- Model reflects biases present in training data
|
| 181 |
+
- Should be used as part of a larger moderation system, not sole decision-maker
|
| 182 |
+
|
| 183 |
+
## Citation
|
| 184 |
+
|
| 185 |
+
If you use this model in your research, please cite:
|
| 186 |
+
|
| 187 |
+
```bibtex
|
| 188 |
+
@software{vihsd_bartpho,
|
| 189 |
+
title = {BARTpho for Vietnamese Hate Speech Detection},
|
| 190 |
+
author = {ViSoLex Team},
|
| 191 |
+
year = {2024},
|
| 192 |
+
url = {https://huggingface.co/visolex/hate-speech-bartpho},
|
| 193 |
+
base_model = {vinai/bartpho-syllable-base}
|
| 194 |
+
}
|
| 195 |
+
```
|
| 196 |
+
|
| 197 |
+
## Contact & Support
|
| 198 |
+
|
| 199 |
+
- **GitHub**: [ViSoLex Hate Speech Detection](https://github.com/visolex/hate-speech-detection)
|
| 200 |
+
- **Issues**: [Report Issues](https://github.com/visolex/hate-speech-detection/issues)
|
| 201 |
+
- **Questions**: Open a discussion on the model's Hugging Face page
|
| 202 |
+
|
| 203 |
+
## License
|
| 204 |
+
|
| 205 |
+
This model is distributed under the MIT License.
|
| 206 |
|
| 207 |
+
## Acknowledgments
|
|
|
|
| 208 |
|
| 209 |
+
- Base model trained by vinai
|
| 210 |
+
- Dataset: ViHSD (Vietnamese Hate Speech Detection Dataset)
|
| 211 |
+
- Framework: [Hugging Face Transformers](https://huggingface.co/transformers)
|
|
|
|
|
|