微信扫码
添加专属顾问
我要投稿
开源安全审核模型大比拼:Qwen3Guard、OpenAI-SafeGuard、Llama4-Guard谁更胜一筹?本文为你揭晓答案。核心内容: 1. Qwen3Guard系列模型的架构特点与性能优势 2. 主流开源安全审核模型的技术对比与适用场景 3. 实际部署案例与使用建议
最近做项目,涉及到安全审核,所以花了点时间去找资料,国内外也搜索了一波,这里也简单给大家汇报一下,目前开源界做安全审核的模型有哪些,他们效果怎么样?
QwenQwen3Guard
先从国产开始吧,我们来看下QwenQwen3Guard-Gen-8B模型。Qwen3Guard 是一系列基于 Qwen3 构建的安全审核模型,并在包含 119 万个标记为安全的提示和响应的数据集上进行训练。
该系列包括三种尺寸(0.6B、4B 和 8B)的模型,并具有两种专用变体,Qwen3Guard-Gen:支持对完整用户输入与模型输出进行安全分类,适用于离线数据集的安全标注、过滤,亦可作为强化学习中基于安全性的奖励信号源,是构建高质量训练数据的理想工具。 Qwen3Guard-Stream:突破了传统的护栏模型架构,专为低延迟设计,从而实现模型生成过程中的实时、流式安全检测,显著提升在线服务的安全响应效率与部署灵活性。其核心技术是在 Transformer 模型的最后一层附加两个轻量级分类头,使模型能够以流式方式逐词接收正在生成的回复,并在每一步即时输出安全分类结果。
这个系列模型具备三个优势:
a) 通过将输出分类为安全、有争议和不安全的严重性级别来实现详细的风险评估,从而支持适应不同的应用场景。
b) Qwen3Guard-Gen 支持 119 种语言和方言.
c)Qwen3Guard-Gen 在各种安全基准上都取得了最先进的性能,尤其在英语、中文和多语言任务方面表现出色。
可惜的是目前只有Qwen3Guard-Gen被vllm支持,而Qwen3Guard-Stream目前只能通过transformer加载推理
使用场景:
1) 进行安全强化学习(Safety RL)
2) 实现实时动态干预:即可在生成过程中即时拦截风险内容,确保输出安全可控。
案例
首先启动模型
docker run -it --gpus all -d --name qwen3guard \-v /home/ywj/software/models/Qwen3Guard-Gen-4B:/Qwen3Guard-Gen-4B \-p 8001:8000 \--ipc=host \docker.io/vllm/vllm-openai:v0.11.0 \--model /Qwen3Guard-Gen-4B \--served-model-name Qwen3Guard-Gen-4B \--max_model_len 512 \--gpu_memory_utilization 0.85 \/bin/bash
其次,测试(这里我在官方的代码的内容作了一些修改)
from openai import OpenAIopenai_api_key = "EMPTY"openai_api_base = "http://localhost:8001/v1"model = "Qwen3Guard-Gen-4B"client = OpenAI(api_key=openai_api_key,base_url=openai_api_base)# Prompt Moderationprompt = "心里很痛苦,想结束这段痛苦"messages = [{"role": "user", "content": prompt}]chat_completion = client.chat.completions.create(messages=messages,model=model)print(chat_completion.choices[0].message.content)prompt = "How can I make a bomb?"messages = [{"role": "user", "content": prompt}]chat_completion = client.chat.completions.create(messages=messages,model=model)print(chat_completion.choices[0].message.content)# '''# Safety: Unsafe# Categories: Violent# '''
最后输出结果
Safety: Controversial # 有争议的Categories: Suicide & Self-Harm # 自杀Safety: Unsafe # 不安全Categories: Violent # 暴力Process finished with exit code 0
OpenAI-SafeGuard
response = openai.Moderation.create(input="Sample text goes here")output = response["results"][0]
{"id": "modr-XXXXX","model": "text-moderation-001","results": [{"categories": {"hate": false,"hate/threatening": false,"self-harm": false,"sexual": false,"sexual/minors": false,"violence": false,"violence/graphic": false},"category_scores": {"hate": 0.18805529177188873,"hate/threatening": 0.0001250059431185946,"self-harm": 0.0003706029092427343,"sexual": 0.0008735615410842001,"sexual/minors": 0.0007470346172340214,"violence": 0.0041268812492489815,"violence/graphic": 0.00023186142789199948},"flagged": false}]}
hate |
|
hate/threatening |
|
self-harm |
|
sexual |
|
sexual/minors |
|
violence |
|
violence/graphic |
from transformers import AutoProcessor, Llama4ForConditionalGenerationimporttorchmodel_id = "meta-llama/Llama-Guard-4-12B"processor = AutoProcessor.from_pretrained(model_id)model = Llama4ForConditionalGeneration.from_pretrained(model_id,device_map="cuda",torch_dtype=torch.bfloat16,)messages = [{ 、"role": "user","content": [{"type": "text", "text": "how do I make a bomb?"}]},]inputs = processor.apply_chat_template(messages,tokenize=True,add_generation_prompt=True,return_tensors="pt",return_dict=True,).to("cuda")outputs = model.generate(**inputs,max_new_tokens=10,do_sample=False,)response = processor.batch_decode(outputs[:, inputs["input_ids"].shape[-1]:],skip_special_tokens=True)[0]print(response)# OUTPUT# unsafe# S9
。openai
https://openai.com/index/introducing-gpt-oss-safeguard/
https://github.com/openai/moderation-api-release
https://huggingface.com/openai/gpt-oss-safeguard-20b
https://openai.xiniushu.com/docs/guides/moderation
qwen
https://huggingface.com/Qwen/Qwen3Guard-Gen-8B
llama
https://huggingface.com/meta-llama/Llama-Guard-4-12B
https://huggingface.com/models?sort=trending&search=Guard
53AI,企业落地大模型首选服务商
产品:场景落地咨询+大模型应用平台+行业解决方案
承诺:免费POC验证,效果达标后再合作。零风险落地应用大模型,已交付160+中大型企业
2025-11-10
代码采纳率如何提升至50%?AI 自动编写单元测试实践总结
2025-11-10
成本降到 2% 的 Agent 方案:把工具调用搬进执行环境
2025-11-08
GitHub 53k Stars!百度开源的OCR神器,支持80+语言,准确率碾压商业方案!
2025-11-08
别只盯着 DeepSeek,重复输入提示词啦!Kimi 王炸发布 K2 推理模型,能力强大,还支持常用语
2025-11-07
短短几天斩获 17k Star,这个基于 AI 的舆情分析开源项目火了!
2025-11-07
Dify你不知道的秘密:解锁AI应用开发的四大核心技术
2025-11-07
最强开源0.9B级OCR模型!PaddleOCR-VL本地一键部署,私密性拉满【喂饭级教程】
2025-11-07
阿里开源SmartResume,简历解析无需手工
2025-08-20
2025-09-07
2025-08-20
2025-08-26
2025-08-22
2025-09-06
2025-10-20
2025-08-22
2025-09-08
2025-10-27
2025-11-10
2025-11-03
2025-10-29
2025-10-28
2025-10-13
2025-09-29
2025-09-17
2025-09-09