库名称:transformers
标签:
- 文本分类
- 内容审核
- 评论审核
- 文本审核
许可证:openrail
语言:
- 英语
基础模型:
- distilbert/distilbert-base-uncased
🛡️ 评论审核模型



基于DistilBERT架构构建的强大多标签内容审核系统,旨在高精度检测和分类用户生成评论中的潜在有害内容。该模型在文本审核性能方面表现卓越,是目前基于所提供数据集的最佳模型。此外,其体积小巧,非常适合在边缘设备上部署。目前,它是Hugging Face上唯一能在保持较小体积的同时实现如此高性能的模型。
🎯 主要特点
- 多标签分类
- 实时内容分析
- 准确率95.4%
- 9种内容类别
- 通过API或本地实现轻松集成
- 轻量级部署
- 适用于边缘设备和移动应用
- 低延迟推理
- 资源高效且保持高准确率
- 可在消费级硬件上运行
📊 内容类别
模型识别以下类型的潜在有害内容:
类别 |
标签 |
定义 |
性相关 |
S |
旨在引起性兴奋的内容,如性活动描述或推广性服务(不包括性教育和健康内容)。 |
仇恨 |
H |
基于种族、性别、民族、宗教、国籍、性取向、残疾状况或种姓表达、煽动或宣扬仇恨的内容。 |
暴力 |
V |
宣扬或美化暴力或庆祝他人痛苦或羞辱的内容。 |
骚扰 |
HR |
可能用于现实生活中折磨或骚扰个人,或增加骚扰发生可能性的内容。 |
自残 |
SH |
宣扬、鼓励或描述自残行为的内容,如自杀、自伤和饮食失调。 |
未成年人性内容 |
S3 |
包含18岁以下个体的性相关内容。 |
仇恨/威胁 |
H2 |
包含针对目标群体的暴力或严重伤害的仇恨内容。 |
暴力/图形 |
V2 |
以极端细节描绘死亡、暴力或严重身体伤害的暴力内容。 |
安全内容 |
OK |
不违反任何准则的适当内容。 |
📈 性能指标
准确率:95.4%
平均ROC AUC:0.912
宏F1分数:0.407
微F1分数:0.802
查看详细性能指标
🖥️ 训练详情
模型在NVIDIA RTX 3080 GPU的家庭环境中训练,证明有效的审核模型可在消费级硬件上开发。这使得个体开发者和小型组织也能参与模型开发。
关键训练规格:
- 硬件:NVIDIA RTX 3080
- 基础模型:DistilBERT
- 模型大小:6700万参数(优化部署效率)
- 训练环境:本地工作站
- 训练类型:微调
尽管体积较小(6700万参数),该模型仍实现了令人印象深刻的性能指标,适合在各种设备和环境中部署。其效率与性能的平衡表明,无需大量计算资源即可实现有效的内容审核。
🚀 快速开始
Python实现(本地)
from transformers import AutoModelForSequenceClassification, AutoTokenizer
model = AutoModelForSequenceClassification.from_pretrained("Vrandan/Comment-Moderation")
tokenizer = AutoTokenizer.from_pretrained("Vrandan/Comment-Moderation")
def analyze_text(text):
inputs = tokenizer(text, return_tensors="pt")
outputs = model(**inputs)
probabilities = outputs.logits.softmax(dim=-1).squeeze()
labels = [model.config.id2label[i] for i in range(len(probabilities))]
predictions = sorted(zip(labels, probabilities), key=lambda x: x[1], reverse=True)
return predictions
text = "您的文本"
results = analyze_text(text)
for label, prob in results:
print(f"{label}: {prob:.4f}")
示例输出:
标签: OK - 概率: 0.9840
标签: H - 概率: 0.0043
标签: SH - 概率: 0.0039
标签: V - 概率: 0.0019
标签: S - 概率: 0.0018
标签: HR - 概率: 0.0015
标签: V2 - 概率: 0.0011
标签: S3 - 概率: 0.0010
标签: H2 - 概率: 0.0006
Python实现(无服务器)
import requests
API_URL = "https://api-inference.huggingface.co/models/Vrandan/Comment-Moderation"
headers = {"Authorization": "Bearer hf_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"}
def query(payload):
response = requests.post(API_URL, headers=headers, json=payload)
return response.json()
output = query({
"inputs": "您的文本",
})
JavaScript实现(Node.js)
require('dotenv').config();
const { HfInference } = require('@huggingface/inference');
const readline = require('readline');
const hf = new HfInference(process.env.HUGGING_FACE_ACCESS_TOKEN);
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
async function analyzeText(text) {
try {
const result = await hf.textClassification({
model: 'Vrandan/Comment-Moderation',
inputs: text
});
console.log('\n结果:');
result.forEach(pred => {
console.log(`标签: ${pred.label} - 概率: ${pred.score.toFixed(4)}`);
});
} catch (error) {
console.error('分析文本时出错:', error.message);
}
}
async function main() {
while (true) {
try {
const text = await new Promise(resolve => {
rl.question('\n输入要分析的文本(或输入"quit"退出): ', resolve);
});
if (text.toLowerCase() === 'quit') break;
if (text.trim()) await analyzeText(text);
} catch (error) {
console.error('错误:', error.message);
}
}
rl.close();
}
main().catch(console.error);
JavaScript实现(无服务器)
async function query(data) {
const response = await fetch(
"https://api-inference.huggingface.co/models/Vrandan/Comment-Moderation",
{
headers: {
Authorization: "Bearer hf_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx",
"Content-Type": "application/json",
},
method: "POST",
body: JSON.stringify(data),
}
);
const result = await response.json();
return result;
}
query({"inputs": "您的文本"}).then((response) => {
console.log(JSON.stringify(response));
});
📊 详细模型性能
模型已通过标准分类指标全面评估:
- 损失: 0.641
- 准确率: 0.954 (95.4%)
- 宏F1分数: 0.407
- 微F1分数: 0.802
- 加权F1分数: 0.763
- 宏精确率: 0.653
- 微精确率: 0.875
- 加权精确率: 0.838
- 宏召回率: 0.349
- 微召回率: 0.740
- 加权召回率: 0.740
- 平均ROC AUC: 0.912
⚠️ 重要注意事项
道德使用
限制
- 可能遗漏上下文细微差别
- 可能出现误报
- 文化背景差异
📚 数据集信息
该模型基于OpenAI发布的论文《"A Holistic Approach to Undesired Content Detection"》中描述的数据集训练。
数据集来源
引用
如在研究中使用此模型或数据集,请引用:
@article{openai2022moderation,
title={A Holistic Approach to Undesired Content Detection},
author={Todor Markov and Chong Zhang and Sandhini Agarwal and Tyna Eloundou and Teddy Lee and Steven Adler and Angela Jiang and Lilian Weng},
journal={arXiv preprint arXiv:2208.03274},
year={2022}
}
📧 联系方式
如需支持或咨询,请通过Slack联系我。