Upload README.md with huggingface_hub
Browse files
README.md
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language: vi
|
| 3 |
+
license: mit
|
| 4 |
+
base_model: NlpHUST/electra-base-vn
|
| 5 |
+
tags:
|
| 6 |
+
- vietnamese
|
| 7 |
+
- content-moderation
|
| 8 |
+
- text-classification
|
| 9 |
+
- kids-safety
|
| 10 |
+
datasets:
|
| 11 |
+
- ViHSD
|
| 12 |
+
metrics:
|
| 13 |
+
- accuracy
|
| 14 |
+
- f1
|
| 15 |
+
pipeline_tag: text-classification
|
| 16 |
+
---
|
| 17 |
+
|
| 18 |
+
# 🛡️ Vietnamese Comment Filter for Kids Platform
|
| 19 |
+
|
| 20 |
+
Model lọc bình luận tiếng Việt được thiết kế đặc biệt cho nền tảng đọc báo dành cho trẻ em.
|
| 21 |
+
|
| 22 |
+
## 📋 Thông tin Model
|
| 23 |
+
|
| 24 |
+
- **Kiến trúc**: ELECTRA-base-vn + BiGRU + Attention
|
| 25 |
+
- **Task**: Binary Classification (CLEAN vs TOXIC)
|
| 26 |
+
- **Hybrid System**: ELECTRA + Logistic Regression specialists
|
| 27 |
+
- **Dataset**: ViHSD (Vietnamese Hate Speech Detection)
|
| 28 |
+
|
| 29 |
+
## 🎯 Mục đích
|
| 30 |
+
|
| 31 |
+
Model này được phát triển để:
|
| 32 |
+
- Tự động kiểm duyệt bình luận trên nền tảng đọc báo cho trẻ em
|
| 33 |
+
- Phát hiện nội dung không phù hợp (toxic, hate speech, NSFW)
|
| 34 |
+
- Bảo vệ trẻ em khỏi nội dung có hại
|
| 35 |
+
|
| 36 |
+
## 🏗️ Kiến trúc 3 Tầng
|
| 37 |
+
|
| 38 |
+
### Stage 1: NSFW Rule-based Filter
|
| 39 |
+
Phát hiện nhanh các từ ngữ tục tĩu, dâm ô bằng rule-based matching.
|
| 40 |
+
|
| 41 |
+
### Stage 2: ELECTRA Binary Gatekeeper
|
| 42 |
+
Phân loại CLEAN vs TOXIC bằng deep learning model.
|
| 43 |
+
|
| 44 |
+
### Stage 3: Twin-Logistic Specialist
|
| 45 |
+
- **Navigator**: Phân biệt OFFENSIVE vs HATE
|
| 46 |
+
- **Power Gauge**: Tính xác suất toxic chính xác
|
| 47 |
+
|
| 48 |
+
## 📊 Hiệu suất
|
| 49 |
+
|
| 50 |
+
- **Accuracy**: 87.4%
|
| 51 |
+
- **F1-Score (Macro)**: 0.846
|
| 52 |
+
- **Inference Time**: ~15-30ms/comment
|
| 53 |
+
|
| 54 |
+
## 💡 Cách sử dụng
|
| 55 |
+
|
| 56 |
+
### Option 1: Sử dụng qua API (Đơn giản nhất - Recommended)
|
| 57 |
+
|
| 58 |
+
```bash
|
| 59 |
+
# Chạy FastAPI server
|
| 60 |
+
python api_server.py
|
| 61 |
+
|
| 62 |
+
# Test bằng curl
|
| 63 |
+
curl -X POST "http://localhost:8000/filter" \
|
| 64 |
+
-H "Content-Type: application/json" \
|
| 65 |
+
-d '{"text": "Sản phẩm tốt", "strict_mode": true}'
|
| 66 |
+
```
|
| 67 |
+
|
| 68 |
+
### Option 2: Load trực tiếp trong Python
|
| 69 |
+
|
| 70 |
+
```python
|
| 71 |
+
from transformers import AutoTokenizer, AutoModel
|
| 72 |
+
import torch
|
| 73 |
+
|
| 74 |
+
# Load model
|
| 75 |
+
model = AutoModel.from_pretrained("your-username/vn-comment-filter-kids")
|
| 76 |
+
tokenizer = AutoTokenizer.from_pretrained("your-username/vn-comment-filter-kids")
|
| 77 |
+
|
| 78 |
+
# Inference
|
| 79 |
+
text = "Comment cần kiểm tra"
|
| 80 |
+
inputs = tokenizer(text, return_tensors="pt", max_length=256, padding=True, truncation=True)
|
| 81 |
+
|
| 82 |
+
with torch.no_grad():
|
| 83 |
+
outputs = model(**inputs)
|
| 84 |
+
prediction = torch.argmax(outputs.logits, dim=-1).item()
|
| 85 |
+
|
| 86 |
+
print("CLEAN" if prediction == 0 else "TOXIC")
|
| 87 |
+
```
|
| 88 |
+
|
| 89 |
+
## ⚙️ Configuration
|
| 90 |
+
|
| 91 |
+
Model hỗ trợ 2 modes:
|
| 92 |
+
- **Normal Mode**: Threshold = 0.60 (balanced)
|
| 93 |
+
- **Strict Mode**: Threshold = 0.45 (safer for kids, more false positives)
|
| 94 |
+
|
| 95 |
+
## 📦 Files trong Repository
|
| 96 |
+
|
| 97 |
+
```
|
| 98 |
+
.
|
| 99 |
+
├── model.safetensors # Model weights
|
| 100 |
+
├── config.json # Model config
|
| 101 |
+
├── tokenizer files # Tokenizer artifacts
|
| 102 |
+
├── preprocessing_config.json # Text preprocessing rules
|
| 103 |
+
├── specialist_navigator.pkl # Logistic model cho OFF vs HATE
|
| 104 |
+
├── specialist_power.pkl # Logistic model cho toxicity prob
|
| 105 |
+
├── requirements.txt # Python dependencies
|
| 106 |
+
└── README.md # Documentation này
|
| 107 |
+
```
|
| 108 |
+
|
| 109 |
+
## ⚠️ Limitations
|
| 110 |
+
|
| 111 |
+
- Model được train trên ViHSD dataset (social media comments)
|
| 112 |
+
- Có thể có false positives với ngữ cảnh đặc biệt
|
| 113 |
+
- Không phù hợp cho các domain khác ngoài content moderation
|
| 114 |
+
|
| 115 |
+
## 📄 License
|
| 116 |
+
|
| 117 |
+
MIT License - Free for educational and commercial use
|
| 118 |
+
|
| 119 |
+
## 🙏 Credits
|
| 120 |
+
|
| 121 |
+
- Base model: [NlpHUST/electra-base-vn](https://huggingface.co/NlpHUST/electra-base-vn)
|
| 122 |
+
- Dataset: ViHSD (Vietnamese Hate Speech Detection)
|
| 123 |
+
- Framework: Hugging Face Transformers, PyTorch
|
| 124 |
+
|
| 125 |
+
## 📧 Contact
|
| 126 |
+
|
| 127 |
+
For questions or issues, please open an issue on the repository.
|