🚀 微調版俄文文本毒性分類模型
本項目基於 cointegrated/rubert-tiny 模型微調,用於對俄語短文本(如社交網絡評論)的毒性和不當性進行分類。
標籤信息
屬性 |
詳情 |
語言 |
俄語 |
標籤 |
俄語、分類、毒性、多標籤 |
快速測試
你可以通過以下示例文本快速測試模型:
"Иди ты нафиг!"
🚀 快速開始
這是 cointegrated/rubert-tiny 模型的微調版本,用於對俄語短非正式文本(如社交網絡中的評論)的毒性和不當性進行分類。
問題被表述為多標籤分類,包含以下類別:
non-toxic
:根據 OK ML Cup 競賽的定義,文本不包含侮辱、髒話和威脅。
insult
:侮辱
obscenity
:髒話
threat
:威脅
dangerous
:根據 Babakov 等人 的定義,文本不合適,即可能損害發言者的聲譽。
如果文本同時為 non-toxic
且非 dangerous
,則可認為該文本是安全的。
💻 使用示例
基礎用法
以下函數用於估計文本具有毒性或危險性的概率:
import torch
from transformers import AutoTokenizer, AutoModelForSequenceClassification
model_checkpoint = 'cointegrated/rubert-tiny-toxicity'
tokenizer = AutoTokenizer.from_pretrained(model_checkpoint)
model = AutoModelForSequenceClassification.from_pretrained(model_checkpoint)
if torch.cuda.is_available():
model.cuda()
def text2toxicity(text, aggregate=True):
""" Calculate toxicity of a text (if aggregate=True) or a vector of toxicity aspects (if aggregate=False)"""
with torch.no_grad():
inputs = tokenizer(text, return_tensors='pt', truncation=True, padding=True).to(model.device)
proba = torch.sigmoid(model(**inputs).logits).cpu().numpy()
if isinstance(text, str):
proba = proba[0]
if aggregate:
return 1 - proba.T[0] * (1 - proba.T[-1])
return proba
print(text2toxicity('я люблю нигеров', True))
print(text2toxicity('я люблю нигеров', False))
print(text2toxicity(['я люблю нигеров', 'я люблю африканцев'], True))
print(text2toxicity(['я люблю нигеров', 'я люблю африканцев'], False))
🔧 技術細節
該模型在 OK ML Cup 和 Babakov 等人 的聯合數據集上進行訓練,使用 Adam
優化器,學習率為 1e-5
,批量大小為 64
,訓練了 15
個週期,具體訓練過程可參考 Colab 筆記本。
如果文本的不當性得分高於 0.8,則認為該文本不合適;如果得分低於 0.2,則認為該文本合適。開發集上每個標籤的 ROC AUC 如下:
non-toxic : 0.9937
insult : 0.9912
obscenity : 0.9881
threat : 0.9910
dangerous : 0.8295