微信扫码
添加专属顾问
我要投稿
开源安全审核模型大比拼: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
。53AI,企业落地大模型首选服务商
产品:场景落地咨询+大模型应用平台+行业解决方案
承诺:免费POC验证,效果达标后再合作。零风险落地应用大模型,已交付160+中大型企业
2026-02-09
Virustotal对OpenClaw恶意技能(Skills)的跟踪分析
2026-02-09
ollama v0.15.6发布:上下文限制修复、自动模型下载、Claude环境变量优化、Droid与Qwen全面更新详解
2026-02-09
【开源】港大开源“纳米级OpenClaw”:超轻量AI助手,仅4000行代码复刻OpenClaw核心战力!
2026-02-06
Qwen3-Coder-Next 上线模力方舟:仅 3B 激活参数,媲美主流大模型的 Agent 编码能力
2026-02-06
给自己搭一个 AI 搭档:OpenClaw 安装使用全记录
2026-02-06
Qwen3-TTS:2026年最强开源文本转语音模型完全指南
2026-02-06
OpenClaw 爆火之后,我们看到了这些创业信号
2026-02-05
从Clawdbot到OpenClaw:爆款本地AI Agent的产品逻辑与争议
2025-11-19
2026-01-27
2025-12-22
2026-01-12
2026-01-29
2025-11-17
2025-12-10
2026-01-28
2025-12-23
2026-01-06
2026-02-05
2026-01-28
2026-01-26
2026-01-21
2026-01-21
2026-01-20
2026-01-16
2026-01-02