🛡️ Toxic Comment Detection (PhoBERT fine-tuned)

Mô hình này được fine-tune từ vinai/phobert-base-v2 để phân loại bình luận tiếng Việt thành hai nhóm:

  • 0 = Non-Toxic (Bình thường)
  • 1 = Toxic (Độc hại)

Mục tiêu: phát hiện các bình luận tiêu cực, công kích, xúc phạm trong môi trường mạng xã hội.


📊 Dataset & Training

  • Dữ liệu huấn luyện: tổng hợp từ nhiều nguồn (Facebook comments, tập dữ liệu nhãn "toxic" và "non-toxic").
  • Tiền xử lý:
    • Loại bỏ comment trùng lặp
    • Chuẩn hóa chữ thường
    • Oversampling để cân bằng số lượng
    • Data augmentation cho nhãn toxic (viết hoa, bỏ dấu, teen code…)
  • Loss function: Focal Loss (trọng số cao hơn cho nhãn Toxic)
  • Optimizer: AdamW
  • Scheduler: Cosine
  • Epochs: 10
  • Early stopping: patience = 2

📈 Kết quả

Kết quả trên tập kiểm tra:

  • Accuracy: 0.90
  • Precision: 0.88
  • Recall: 0.86
  • F1-score: 0.87

📌 Báo cáo chi tiết

              precision    recall  f1-score   support

  Non-Toxic       0.91      0.92      0.91      1500
      Toxic       0.88      0.86      0.87      1400

    accuracy                           0.90      2900
   macro avg       0.90      0.89      0.89      2900
weighted avg       0.90      0.90      0.90      2900

🔎 Ma trận nhầm lẫn

Dự đoán Non-Toxic Dự đoán Toxic
Thực tế Non-Toxic 1378 122
Thực tế Toxic 196 1204

🚀 Sử dụng

1. Dùng trực tiếp với transformers.pipeline

from transformers import pipeline

classifier = pipeline(
    "text-classification",
    model="vijjj1/toxic-comment-phobert",
    tokenizer="vijjj1/toxic-comment-phobert"
)

comments = [
    "mày là đồ ngu, biến đi!",
    "hôm nay thật là một ngày tuyệt vời."
]

results = classifier(comments)
for c, r in zip(comments, results):
    print(f"{c}{r}")

✅ Output:

mày là đồ ngu, biến đi! → {'label': 'LABEL_1', 'score': 0.97}
hôm nay thật là một ngày tuyệt vời. → {'label': 'LABEL_0', 'score': 0.95}

2. Tự load model

import torch
from transformers import AutoTokenizer, AutoModelForSequenceClassification

model_id = "vijjj1/toxic-comment-phobert"

tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForSequenceClassification.from_pretrained(model_id)

inputs = tokenizer("bạn thật sự quá tệ", return_tensors="pt")
with torch.no_grad():
    outputs = model(**inputs)
    probs = torch.softmax(outputs.logits, dim=-1).numpy()[0]

print("Prob Non-Toxic:", probs[0])
print("Prob Toxic:", probs[1])

📌 Ứng dụng

  • Phát hiện bình luận độc hại trên mạng xã hội
  • Tiền xử lý dữ liệu bình luận để lọc spam/toxic
  • Hỗ trợ hệ thống moderation (quản trị cộng đồng)

⚖️ Giấy phép

Model này được phát hành dưới giấy phép MIT.
Người dùng chịu trách nhiệm cho mọi ứng dụng thực tế, đặc biệt trong môi trường nhạy cảm.


✨ Tác giả


Downloads last month
76
Safetensors
Model size
0.1B params
Tensor type
F32
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Spaces using vijjj1/toxic-comment-phobert 3