概述
恶意评论分类器(Toxic Comment Classifier)能够检测出文本片段中的 6 种恶意评论。这 6 种可检测类型为:恶意(toxic)、非常恶意(severe toxic)、淫秽(obscene)、威胁性(threat)、侮辱性(insult)以及身份歧视(identity hate)。底层的神经网络基于预训练的 BERT-Base English Uncased 模型,并使用 Huggingface BERT Pytorch 代码库根据恶意评论分类数据集进行了调优。
下面是六种恶意评论类型的简要定义。
Toxic: very bad, unpleasant, or harmful
Severe toxic: extremely bad and offensive
Obscene: (of the portrayal or description of sexual matters) offensive or disgusting by accepted standards of morality and decency
Threat: a statement of an intention to inflict pain, injury, damage, or other hostile action on someone in retribution for something done or not done
Insult: speak to or treat with disrespect or scornful abuse
Identity hate: hatred, hostility, or violence towards members of a race, ethnicity, nation, religion, gender, gender identity, sexual orientation or any other designated sector of society
模型元数据
领域 | 应用 | 行业 | 框架 | 训练数据 | 输入数据 |
---|---|---|---|---|---|
自然语言处理 (NLP) | 文本分类 | 通用 | PyTorch | 恶意评论分类数据集 | 文本 |
基准
此模型在 Kaggle 恶意评论分类竞赛中获得了 0.98355 的列向 ROC AUC 得分(非公开得分)。这种实现采用最大序列长度 256(而不是 512)进行训练,因此能够提供更快的推理速度。对于 Kaggle 竞赛以外的大多数应用,256 的序列长度已经绰绰有余。
参考资料
- J.Devlin、M. Chang、K. Lee 和 K. Toutanova,BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding,出自 arXiv(2018 年)。
- Google BERT 代码库
- Huggingface BERT Pytorch 代码库
- 使用 BERT 进行多标签文本分类 – 强大的转换器
- Kaggle 恶意评论分类
许可
组件 | 许可 | 链接 |
---|---|---|
模型 GitHub 代码库 | Apache 2.0 | 许可 |
调优模型权重 | Apache 2.0 | 许可 |
预训练模型权重 | Apache 2.0 | 许可 |
TensorFlow 模型代码(第三方) | Apache 2.0 | 许可 |
PyTorch 模型代码(第三方) | Apache 2.0 | 许可 |
恶意评论分类数据集 | CC0 | 许可 |
此模型的可用部署选项
可以使用以下方式来部署此模型:
通过 Dockerhub 进行部署:
docker run -it -p 5000:5000 codait/max-toxic-comment-classifier
在 Red Hat OpenShift 上部署:
遵循本教程中有关 OpenShift Web 控制台或 OpenShift Container Platform CLI 的操作说明,并指定
codait/max-toxic-comment-classifier
作为镜像名称。在 Kubernetes 上部署:
kubectl apply -f https://raw.githubusercontent.com/IBM/MAX-Toxic-Comment-Classifier/master/max-toxic-comment-classifier.yaml
本地部署:遵循 GitHub 上的模型 README 文件中的操作说明
用法示例
您可以测试或使用此模型
使用 cURL 测试模型
在部署模型后,可以在命令行中测试该模型。例如:
curl -d "{ \"text\": [ \"I would like to punch you.\", \"In hindsight, I do apologize for my previous statement.\"]}" -X POST "http://localhost:5000/model/predict" -H "Content-Type: application/json"
您应该会看到与下面类似的 JSON 响应:
{
"status": "ok",
"predictions": [
{
"toxic": 0.9796434044837952,
"severe_toxic": 0.07256636023521423,
"obscene": 0.058431386947631836,
"threat": 0.8635178804397583,
"insult": 0.11121545732021332,
"identity_hate": 0.013826466165482998
},
{
"toxic": 0.00029103411361575127,
"severe_toxic": 0.00012417171092238277,
"obscene": 0.0001522742968518287,
"threat": 0.00008440738747594878,
"insult": 0.00016013195272535086,
"identity_hate": 0.00012860879360232502
}
]
}
在无服务器应用程序中测试模型
通过遵循在 IBM Cloud Functions 中利用深度学习教程中的操作说明,可以在无服务器应用程序中使用此模型。
资源与贡献
如果您有兴趣为 Model Asset Exchange 项目做出贡献或有任何疑问,遵循此处的操作说明。
本文翻译自:Toxic Comment Classifier(2019-06-04)