Vietnamese Hate Speech Detection — PhoBERT (Combined Augmentation)
AnoraLee/vietnamese-hsd-phobert-combined is a fine-tuned vinai/phobert-base model for 3-class Vietnamese Hate Speech Detection (CLEAN, OFFENSIVE, HATE) on social media text.
This checkpoint is trained on the combined augmented dataset (merging original training data with Back-Translation, EDA, and LLM synthetic augmentations from Gemma & Qwen, deduplicated and conflict-filtered). Among all PhoBERT experiments in the benchmark, phobert_combined achieves the highest HATE F1 (58.0%), improving by +4.2% over phobert_baseline.
- Live Demo (HSD Studio): vietnamese-hsd-augmentation.vercel.app
- Backend API (HF Space): BonTori/vietnamese_tdtu_hsd_detectToxic
Label Mapping
| ID | Label | Description |
|---|---|---|
0 | CLEAN | Normal, non-toxic Vietnamese text |
1 | OFFENSIVE | Profanity, vulgarity, or rude language without targeted hate |
2 | HATE | Hate speech, harassment, dehumanization, or targeted attacks |
Evaluation Results
Evaluated on the frozen tdtu_test set (6,576 samples; validation set: 2,650 samples):
| Model | Strategy | Accuracy | Macro F1 | Weighted F1 | HATE F1 |
|---|---|---|---|---|---|
phobert_baseline | Original unaugmented | 84.4% | 60.2% | 84.7% | 53.8% |
phobert_bt | + Back-translation (vi → en → vi) | 83.0% | 44.5% | 79.8% | 42.7% |
phobert_eda | + Easy Data Augmentation | 78.4% | 58.3% | 81.3% | 56.5% |
phobert_llm | + LLM synthesis (Gemma, Qwen) | 83.5% | 60.9% | 84.5% | 56.1% |
phobert_combined | Combined augmentation (BT + EDA + LLM) | 78.0% | 57.3% | 80.7% | 58.0% |
- Test Loss:
0.5513 - Key Takeaway: Because the corpus is heavily imbalanced toward
CLEANcomments, combining multiple augmentation strategies intentionally trades off a small drop in overall accuracy to maximize sensitivity and F1 on the minorityHATEclass (+4.2% HATE F1 overphobert_baseline).
Usage
Important: PhoBERT requires Vietnamese word segmentation (compound words joined with
_, e.g.,cảm_ơn,xã_hội) before tokenization, and uses the slow tokenizer (use_fast=False). Useundertheseaorpy_vncorenlpto segment input text first.
With underthesea + transformers pipeline
from underthesea import word_tokenize
from transformers import AutoTokenizer, pipeline
model_id = "AnoraLee/vietnamese-hsd-phobert-combined"
tokenizer = AutoTokenizer.from_pretrained(model_id, use_fast=False)
classifier = pipeline(
"text-classification",
model=model_id,
tokenizer=tokenizer,
max_length=128,
truncation=True,
)
raw_texts = [
"Bài viết chia sẻ rất hữu ích, cảm ơn tác giả!",
"Thứ rác rưởi, cút khỏi mạng xã hội đi.",
]
segmented_texts = [word_tokenize(t, format="text") for t in raw_texts]
print(classifier(segmented_texts))
With PyTorch
import torch
from underthesea import word_tokenize
from transformers import AutoTokenizer, AutoModelForSequenceClassification
model_id = "AnoraLee/vietnamese-hsd-phobert-combined"
tokenizer = AutoTokenizer.from_pretrained(model_id, use_fast=False)
model = AutoModelForSequenceClassification.from_pretrained(model_id)
model.eval()
raw_text = "Nói chuyện kiểu gì mà vô duyên thế không biết."
segmented_text = word_tokenize(raw_text, format="text")
inputs = tokenizer(segmented_text, return_tensors="pt", truncation=True, max_length=128)
with torch.no_grad():
logits = model(**inputs).logits
probs = torch.softmax(logits, dim=-1).squeeze()
pred_id = torch.argmax(probs).item()
print(f"Label: {model.config.id2label[pred_id]} ({probs[pred_id]:.4f})")
Training Details
- Base Model:
vinai/phobert-base - Training Split:
combined_bt_eda_llm(140,914 samples from ViHSD, VOZ, YouTube, Back-Translation, EDA, and LLM synthesis; word-segmented) - Max Sequence Length:
128 - Optimizer / Hyperparameters:
learning_rate:2e-5per_device_train_batch_size:16weight_decay:0.01fp16:Trueseed:42EarlyStoppingCallback(patience=2)withload_best_model_at_end=True(metric_for_best_model="macro_f1"), stopping at Epoch 3 and restoring the best checkpoint.
Limitations & Bias
- Trained on Vietnamese social media comments (ViHSD, VOZ forums, YouTube). Performance may degrade if input text is not word-segmented (
_) or comes from formal domains outside social media. - Augmented training prioritizes sensitivity toward
HATEspeech, which can slightly increase false positives on borderlineCLEAN/ sarcastic sentences.
Authors & License
Developed by researchers at the Faculty of Information Technology, Ton Duc Thang University (TDTU).
Distributed under the Apache License 2.0.