🚀 土耳其语有毒语言检测模型
该模型是基于 dbmdz/bert-base-turkish-cased
微调而来,用于对土耳其语文本进行二元有毒性分类。它使用经过清理和预处理的 Overfit-GM/turkish-toxic-language
数据集进行训练。
✨ 主要特性
- 多标签支持:支持多种评估指标,如准确率、F1值、精确率和召回率。
- 数据处理:对训练数据进行了清理和预处理,包括去除URL、提及、特殊字符、俚语等。
- 训练策略:采用Hugging Face的
Trainer
API进行训练,应用了欠采样来平衡类别分布。
📦 安装指南
暂未提供相关安装步骤。
💻 使用示例
基础用法
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch
tokenizer = AutoTokenizer.from_pretrained("fc63/turkish_toxic_language_detection_model")
model = AutoModelForSequenceClassification.from_pretrained("fc63/turkish_toxic_language_detection_model")
def predict_toxicity(text):
inputs = tokenizer(text, return_tensors="pt", truncation=True, padding="max_length", max_length=128)
outputs = model(**inputs)
predicted = torch.argmax(outputs.logits, dim=1).item()
return "Toxic" if predicted == 1 else "Non-Toxic"
📚 详细文档
性能表现
指标 |
非有毒 |
有毒 |
宏平均 |
精确率 |
0.96 |
0.95 |
0.96 |
召回率 |
0.95 |
0.96 |
0.96 |
F1分数 |
0.96 |
0.96 |
0.96 |
准确率 |
|
|
0.96 |
测试样本 |
5400 |
5414 |
10814 |
混淆矩阵
|
预测: 非有毒 |
预测: 有毒 |
真实: 非有毒 |
5154 |
246 |
真实: 有毒 |
200 |
5214 |
预处理细节 (cleaned_corrected_text)
该模型在 cleaned_corrected_text
列上进行训练,该列是从 corrected_text
经过基本的基于正则表达式的清理步骤和手动俚语过滤得到的。具体如下:
清理函数
def clean_corrected_text(text):
text = text.lower()
text = re.sub(r"http\S+|www\S+|https\S+", '', text, flags=re.MULTILINE)
text = re.sub(r"@\w+", '', text)
text = re.sub(r"[^\w\s.,!?-]", '', text)
text = re.sub(r"\s+", ' ', text).strip()
return text
手动俚语过滤
slang_words = ["kanka", "lan", "knk", "bro", "la", "birader", "kanki"]
def remove_slang(text):
for word in slang_words:
text = text.replace(word, "")
return text.strip()
应用步骤总结
步骤 |
描述 |
小写转换 |
所有文本转换为小写 |
URL移除 |
移除包含http、www、https的链接 |
提及移除 |
移除 @username 样式的提及 |
特殊字符移除 |
移除表情符号和符号(如üòä、*、%、$、^等) |
空格归一化 |
将多个空格合并为一个 |
俚语移除 |
移除常见的非正式词汇,如 "kanka"、"lan" 等 |
结论:cleaned_corrected_text
是一个经过轻度清理、未进行语言学处理的文本列。模型直接在该列上进行训练。
训练细节
- 训练器:Hugging Face
Trainer
API
- 轮数:3
- 批次大小:16
- 学习率:2e-5
- 评估策略:基于轮次
- 欠采样:应用于平衡类别分布
数据集
使用的数据集:Overfit-GM/turkish-toxic-language
预处理和平衡后的最终数据集大小:54068 个样本
🔧 技术细节
模型基于 dbmdz/bert-base-turkish-cased
进行微调,用于土耳其语文本的二元有毒性分类。通过对 Overfit-GM/turkish-toxic-language
数据集进行清理和预处理,去除了URL、提及、特殊字符和俚语等噪声信息,提高了模型的性能。训练过程中使用了Hugging Face的 Trainer
API,设置了合适的轮数、批次大小和学习率,并应用了欠采样来平衡类别分布。
📄 许可证
本项目采用 MIT 许可证。