PhoBERT Toxic Comment Detection (Vietnamese)

Model phân loại bình luận độc hại tiếng Việt, fine-tuned từ vinai/phobert-base-v2.

Nhãn phân loại

Nhãn Mô tả
CLEAN Bình luận bình thường, không có nội dung xấu
OFFENSIVE Bình luận xúc phạm, thô tục
HATE Bình luận thù ghét, kích động

Cách sử dụng

Yêu cầu

pip install transformers torch underthesea

Inference nhanh

import torch
from transformers import AutoTokenizer, AutoModelForSequenceClassification

model_name = "your-username/phobert-toxic-detection"  # thay bằng repo của bạn

tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name)
model.eval()

label_names = ["CLEAN", "OFFENSIVE", "HATE"]

def predict(text: str) -> dict:
    inputs = tokenizer(
        text,
        return_tensors="pt",
        max_length=64,
        truncation=True,
        padding=True,
    )
    with torch.no_grad():
        logits = model(**inputs).logits
    probs = torch.softmax(logits, dim=-1).squeeze()
    pred_idx = probs.argmax().item()
    return {
        "label": label_names[pred_idx],
        "score": round(probs[pred_idx].item(), 4),
        "all_scores": {
            label_names[i]: round(probs[i].item(), 4)
            for i in range(len(label_names))
        },
    }

# Ví dụ
print(predict("Bạn làm rất tốt!"))
# {"label": "CLEAN", "score": 0.98, ...}

print(predict("Mày ngu vcl"))
# {"label": "OFFENSIVE", "score": 0.91, ...}

Dùng pipeline của Transformers

from transformers import pipeline

classifier = pipeline(
    "text-classification",
    model="your-username/phobert-toxic-detection",
    top_k=None,  # trả về score của cả 3 nhãn
)

result = classifier("Bình luận cần kiểm tra")
print(result)

Thông tin mô hình

Thuộc tính Giá trị
Base model vinai/phobert-base-v2
Ngôn ngữ Tiếng Việt
Số nhãn 3 (CLEAN, OFFENSIVE, HATE)
Max sequence length 64 tokens
Tokenizer PhoBERT BPE

Tiền xử lý

Model được huấn luyện với pipeline tiền xử lý bao gồm:

  • Teencode normalization — chuyển đổi từ lóng / viết tắt tiếng Việt (vd: kkhông, mmày)
  • Sensitive word dictionary — danh sách từ nhạy cảm và từ chính trị
  • Underthesea tokenizer — tách từ tiếng Việt trước khi đưa vào PhoBERT

Lưu ý: Kết quả tốt nhất đạt được khi áp dụng đúng pipeline tiền xử lý trên. Nếu bỏ qua bước này, độ chính xác có thể giảm với các văn bản có nhiều teencode.

Giới hạn

  • Model được huấn luyện trên dữ liệu tiếng Việt; không áp dụng tốt cho ngôn ngữ khác.
  • Văn bản dài hơn 64 token sẽ bị cắt bớt.
  • Có thể nhạy cảm với cách viết sáng tạo (intentional misspelling) nhằm tránh bộ lọc.
  • Không nên dùng làm hệ thống kiểm duyệt duy nhất mà không có sự giám sát của con người.

Trích dẫn

Nếu bạn sử dụng model này trong nghiên cứu, hãy trích dẫn PhoBERT gốc:

@inproceedings{phobert,
  title     = {{PhoBERT: Pre-trained language models for Vietnamese}},
  author    = {Dat Quoc Nguyen and Anh Tuan Nguyen},
  booktitle = {Findings of EMNLP},
  year      = {2020}
}
Downloads last month

-

Downloads are not tracked for this model. How to track
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support