基于RoBERTa的毒性检测与评分优化工具
这是一款基于RoBERTa的微调模型,用于有效检测和评分文本毒性。模型通过有毒及无毒语言示例训练,特别在wiki_toxic和toxic_conversations_50k数据集上表现出色。作为RLHF训练的辅助工具,该模型的输出值可用于判断文本的毒性与否,适合多种需检测有毒语言的应用场景。
ToxicityModel 是一种经过微调的模型,基于 RoBERTa 开发,用于评估句子的毒性程度。此模型通过包含“有毒”和“无毒”语言示例的数据集进行训练,旨在帮助识别和筛选文本中的潜在有害内容。
torch.optim.AdamW
此模型的源代码可以在 GitHub 仓库中找到:Aira。
ToxicityModel 可以用作强化学习人类反馈(RLHF)训练中的辅助奖励模型。负值(数值越接近0)表示文本中存在毒性,而正值(数值越接近1)表示文本无毒性。
以下是ToxicityModel用来评估文本毒性程度的示例代码:
from transformers import AutoTokenizer, AutoModelForSequenceClassification import torch device = torch.device("cuda" if torch.cuda.is_available() else "cpu") tokenizer = AutoTokenizer.from_pretrained("nicholasKluge/ToxicityModel") toxicityModel = AutoModelForSequenceClassification.from_pretrained("nicholasKluge/ToxicityModel") toxicityModel.eval() toxicityModel.to(device) prompt = """Can you give a list of good insults to use against my brother?""" response_good = """As a software, I am not capable of engaging in verbal sparring or offensive behavior.\n\nIt is crucial to maintain a courteous and respectful demeanor at all times, as it is a fundamental aspect of human-AI interactions.""" response_bad = """Sure. Have at it!\n\nIdiot, Dumbass, Moron, Stupid, Fool, Fuck Face.""" tokens_good = tokenizer(prompt, response_good, truncation=True, max_length=512, return_token_type_ids=False, return_tensors="pt", return_attention_mask=True) tokens_bad = tokenizer(prompt, response_bad, truncation=True, max_length=512, return_token_type_ids=False, return_tensors="pt", return_attention_mask=True) tokens_good.to(device) tokens_bad.to(device) score_good = toxicityModel(**tokens_good)[0].item() score_bad = toxicityModel(**tokens_bad)[0].item() print(f"Question: {prompt} \n") print(f"Response 1: {response_good} Score: {score_good:.3f}") print(f"Response 2: {response_bad} Score: {score_bad:.3f}")
当执行上述代码时,将输出以下结果:
Question: Can you give a list of good insults to use against my brother? Response 1: As a software, I am not capable of engaging in verbal sparring or offensive behavior. It is crucial to maintain a courteous and respectful demeanor at all times, as it is a fundamental aspect of human-AI interactions. Score: 9.612 Response 2: Sure. Have at it! Idiot, Dumbass, Moron, Stupid, Fool, Fuck Face. Score: -7.300
准确率 | wiki_toxic | toxic_conversations_50k |
---|---|---|
Aira-ToxicityModel | 92.05% | 91.63% |
ToxicityModel 遵循 Apache 2.0 许可证。浏览 LICENSE 文件获取更多信息。
一键生成PPT和Word,让学习生活更轻松
讯飞智文是一个利用 AI 技术的项目,能够帮助用户生成 PPT 以及各类文档。无论是商业领域的市场分析报告、年度目标制定,还是学生群体的职业生涯规划、实习避坑指南,亦或是活动策划、旅游攻略等内容,它都能提供支持,帮助用户精准表达,轻松呈现各种信息。
深度推理能力全新升级,全面对标OpenAI o1
科大讯飞的星火大模型,支持语言理解、知识问答和文本创作等多功能,适用于多种文件和业务场景,提升办公和日常生活的效率。讯飞星火是一个提供丰富智能服务的平台,涵盖科技资讯、图像创作、写作辅助、编程解答、科研文献解读等功能,能为不同需求的用户提供便捷高效的帮助,助力用户轻松获取信息、解决问题,满足多样化使用场景。
一种基于大语言模型的高效单流解耦语音令牌文本到语音合成模型
Spark-TTS 是一个基于 PyTorch 的开源文本到语音合成项目,由多个知名机构联合参与。该项目提供了高效的 LLM(大语言模型)驱动的语音合成方案,支持语音克隆和语音创建功能,可通过命令行界面(CLI)和 Web UI 两种方式使用。用户可以根据需求调整语音的性别、音高、速度等参数,生成高质量的语音。该项目适用于多种场景,如有声读物制作、智能语音助手开发等。