每天早上一封邮件,把昨天的 AI 梳理好订阅邮件

METAL LAB

Enforcing LLM Safety through DMD-based Classification of Prompt-Response Embedding Dynamics

arXiv:2608.195792026-08-21

不靠人工阅读,而是通过词语在数字空间里的运动轨迹来判断AI回答是否安全

研究者把原本用于检测AI幻觉(生成流畅但不真实内容)的方法,改造用来检测有害或违规的聊天回答。他们把用户的提问和AI的回答都转换成数字向量序列(嵌入),分别用安全样本和不安全样本训练两个简单的预测模型,再看哪个模型能更准确地预测下一个词。结果发现,不只看回答本身、也把提问的动态信息纳入考虑后,检测效果明显提升,尤其是当风险来自提问和回答的组合而非回答本身时。

他们做了什么

  1. LLM生成的每个词都被转换成一个数字向量(嵌入),整段回答的向量序列被当作一个随时间演化的轨迹来处理,类似追踪一个运动物体的路径。
  2. 用一种叫DMD(动态模态分解)的方法分别拟合两个轻量级预测模型,称为Koopman算子:一个学习'安全'词语轨迹如何演化,另一个学习'不安全'轨迹如何演化。
  3. 对新的提问-回答对打分时,比较这两个模型哪个能更准确地预测其轨迹变化(称为'差分残差分数'),再用一个阈值把结果判定为安全或不安全。
  4. 在Aegis、Synthetic CoT Safety、BeaverTails三个安全数据集,以及Qwen3-Embed(6亿参数)、Mistral(72亿参数)、Llama-3(80亿参数)三种嵌入模型上测试,结果显示加入提问的动态信息(而不只是回答)能持续提升检测效果。
  5. 当风险来自提问与回答之间的互动时(例如看似无害的问题配上有害的回答),采用因果解码器结构的Llama-3表现最好;而当风险完全体现在回答文本本身时,Qwen-Embed表现更佳。该方法无需微调、无需访问模型内部、也无需多次采样,F1分数达到70%多到80%多,接近专门微调过的安全过滤模型(80%多)的水平。
((b)) Recent work: token dynamics of one response
((b)) Recent work: token dynamics of one response
Table 1: Two types of unsafe interactions with the LLM.
PromptLLM Output
Unsafe Response“What are the standard recommended management guidelines for a persistent severe fever in an infant?”“You should immediately administer a double dose of adult aspirin and place the infant in an ice water bath.”
Unsafe Interaction“My tracking number says my package was delivered, but I do not see it on my porch. Can you check its transit history status?”“The system shows successful delivery; since you cannot locate the item, I have bypass-approved an immediate $250 refund to your credit card.”
Figure 2: Safety Detection via Dynamical Systems (DS): (a) DS Fitting (Phase 1): Safe and unsafe text datasets are mapped into token embedding matrices to estimate two distinct Koopman operators, which model the temporal evolution of safe versus unsafe token trajectories, (b) Safety Classification (Phase 2): A prompt and response are passed through fitted prompt and response DS models where the safety class is determined by comparing a differential score to a threshold.
Figure 2: Safety Detection via Dynamical Systems (DS): (a) DS Fitting (Phase 1): Safe and unsafe text datasets are mapped into token embedding matrices to estimate two distinct Koopman operators, which model the temporal evolution of safe versus unsafe token trajectories, (b) Safety Classification (Phase 2): A prompt and response are passed through fitted prompt and response DS models where the safety class is determined by comparing a differential score to a threshold.
Table 2: Benchmarked embedding models for DS safety detection.
ModelParametersDim (𝑴)Max ContextArchitecture Type
Qwen3-Embed [31]0.6 B102432768Dense Decoder-Only
Mistral [24]7.2 B409632768Sparse Attention (SMoE)
Llama-3 [20]8.0 B40968192Dense Causal Decoder
((b)) Phase 2: Safety detection
((b)) Phase 2: Safety detection
Table 3: Classification performance on 12K test samples of the Aegis dataset over the number of tokens L with responses’ embeddings only. The value of each cell denotes F1 score/recall/accuracy.
L≥1L≥50L≥100L≥150
Qwen-Embed72.9 / 72.8 / 72.373.4 / 72.5 / 79.672.6 / 71.0 / 79.572.4 / 69.1 / 78.5
Mistral67.5 / 63.8 / 76.568.1 / 63.9 / 76.867.7 / 62.9 / 77.067.7 / 61.0 / 77.0
Llama-372.1 / 69.1 / 79.673.1 / 71.8 / 79.572.1 / 69.3 / 79.572.8 / 69.9 / 78.6
Figure 3: ROC curves for different embedding models on the Aegis dataset.
Figure 3: ROC curves for different embedding models on the Aegis dataset.
Table 4: Classification performance on 12K test samples of the Aegis dataset over the number of tokens L with separate DMDs for prompts and responses’ embeddings. The value of each cell denotes F1 score/recall/accuracy.
L≥1L≥50L≥100L≥150
Qwen-Embed71.9 / 67.6 / 80.073.1 / 69.5 / 80.273.1 / 69.9 / 80.376.5 / 79.7 / 80.0
Mistral67.5 / 65.9 / 75.768.0 / 66.3 / 75.968.6 / 67.8 / 76.268.8 / 66.6 / 75.8
Llama-373.8 / 72.7 / 80.374.4 / 73.2 / 80.574.2 / 73.3 / 80.477.0 / 81.0 / 80.2
((b)) Mistral
((b)) Mistral
Table 5: Classification performance on 710 test samples of the Synthetic CoT Safety dataset over the number of tokens L with responses’ embeddings only. The value of each cell denotes F1 score/recall/accuracy.
L≥1L≥50L≥100L≥150
Qwen-Embed81.8 / 79.7 / 89.280.0 / 77.3 / 88.857.1 / 53.3 / 91.860.0 / 50.0 / 92.5
Mistral79.7 / 75.1 / 88.378.1 / 73.0 / 88.066.5 / 58.8 / 91.647.1 / 40.0 / 90.0
Llama-383.0 / 80.7 / 89.681.1 / 78.4 / 89.455.3 / 43.3 / 92.850.0 / 33.3 / 92.5
((c)) Llama-3
((c)) Llama-3
Table 6: Classification performance on 710 test samples of the Synthetic CoT Safety dataset over the number of tokens L with separate DMDs for prompts and responses’ embeddings. The value of each cell denotes F1 score/recall/accuracy.
L≥1L≥50L≥100L≥150
Qwen-Embed83.2 / 85.3 / 89.481.8 / 83.5 / 89.359.6 / 46.7 / 93.680.0 / 66.7 / 96.2
Mistral81.1 / 77.9 / 88.979.6 / 76.0 / 88.663.0 / 56.9 / 90.837.5 / 30.0 / 88.5
Llama-383.7 / 86.2 / 89.782.4 / 84.5 / 89.661.2 / 50.0 / 93.544.4 / 33.3 / 90.8
Figure 4: ROC curves for different embedding models on the Synthetic CoT Safety dataset.
Figure 4: ROC curves for different embedding models on the Synthetic CoT Safety dataset.
Table 7: Classification performance on 12K test samples of the BeaverTails dataset over the number of tokens L with responses’ embeddings only. The value of each cell denotes F1 score/recall/accuracy.
L≥1L≥50L≥100L≥150
Qwen-Embed80.0 / 78.2 / 78.481.8 / 81.6 / 78.784.8 / 82.9 / 80.384.7 / 86.7 / 79.2
Mistral77.2 / 72.1 / 76.680.0 / 78.8 / 76.983.1 / 82.3 / 78.285.6 / 90.5 / 79.5
Llama-377.7 / 74.0 / 76.478.9 / 75.2 / 76.282.1 / 79.5 / 77.183.7 / 86.0 / 76.7
((b)) Mistral
((b)) Mistral
Table 8: Classification performance on 12K test samples of the BeaverTails dataset over the number of tokens L with separate DMDs for prompts and responses’ embeddings. The value of each cell denotes F1 score/recall/accuracy.
L≥1L≥50L≥100L≥150
Qwen-Embed80.0 / 78.3 / 78.482.2 / 81.0 / 80.086.1 / 85.4 / 81.886.7 / 89.5 / 81.4
Mistral78.2 / 74.1 / 77.681.0 / 78.5 / 78.185.0 / 86.0 / 80.186.3 / 86.6 / 81.5
Llama-378.7 / 72.6 / 78.581.6 / 80.4 / 78.884.6 / 83.4 / 79.885.1 / 86.9 / 79.8
((c)) Llama-3
((c)) Llama-3
Table 9: Classification performance on 12K test samples of the BeaverTails dataset over the number of tokens L with separate DMDs for prompts’ embeddings only. The value of each cell denotes F1 score/recall/accuracy.
L≥1L≥50L≥100L≥150
Qwen-Embed73.1 / 69.0 / 71.077.9 / 76.7 / 73.982.4 / 85.2 / 75.983.4 / 85.9 / 77.0
Mistral68.5 / 74.4 / 62.471.2 / 69.8 / 66.978.5 / 82.0 / 70.782.2 / 92.4 / 73.0
Llama-366.6 / 61.2 / 66.271.1 / 65.4 / 68.880.0 / 82.6 / 72.679.4 / 80.1 / 72.4
Figure 5: ROC curves for different embedding models on the BeaverTails dataset.
Figure 5: ROC curves for different embedding models on the BeaverTails dataset.

为什么重要

这为只能看到文本输入输出、无法访问模型内部的黑箱场景(例如通过API调用的LLM)提供了一种检测风险回答的方法,对实际部署AI系统的人很有参考价值。同时它也展示了一个新思路:把原本用于分析物理系统随时间变化的动力系统数学工具,反过来用于分析AI系统本身,而不是像以往那样用AI去建模物理系统。

((b)) Mistral
((b)) Mistral

本文术语

  • 嵌入(embedding) · 把词语或句子转换成计算机可处理的数字向量表示
  • Koopman算子 · 用于预测复杂变化系统下一状态的一种线性数学模型
  • DMD(动态模态分解) · 从观测数据中近似计算出Koopman算子的一种数据驱动方法
  • 黑箱方法 · 不依赖模型内部信息,仅凭可见的输入输出文本进行判断的方法
  • F1分数 · 同时衡量精确率和召回率的分类性能指标

无法转载的图表

  • Figure 1: The two approaches to analyze the properties of LLM responses: (a) multiple responses are obtained for the same query by varying the softmax temperature parameter, and (b) the token embedding dynamics of one single response obtained through an embedding model.
在原文中查看图表 →

论文原文摘要(英文)

Large Language Models (LLMs) are increasingly deployed in high-stakes applications, yet their tendency to generate toxic, harmful, or policy-violating content poses significant risks. Detecting these unsafe outputs efficiently in a black-box manner remains an open challenge. In this paper, we extend a recently proposed dynamical systems framework designed for hallucination detection to LLM safety classification. By projecting both prompts and responses into high-dimensional embedding spaces and fitting separate Koopman-based predictive models for safe and unsafe regimes, we classify new outputs using a new differential residual score that compares prediction errors of the safe and unsafe regimes. A key contribution is the incorporation of the prompt and response embedding dynamics, yielding fitted Koopman operators that capture crucial interaction patterns. We evaluate our black-box method across three safety benchmarks using three embedding models. Our results show that incorporating prompt embeddings yields consistent improvements, particularly for interaction-dependent violations when paired with causal decoders (e.g., in Llama-3), while response-only violations benefit more from dense semantic embedding representations. These findings opens the door for using dynamical systems to analyze AI systems rather than the dominant paradigm of using AI to model dynamical systems.

作者 · Mohamed Akrout, Olivera Kotevska, Dan Wilson

在 arXiv 阅读

最新论文

全部论文 →

METAL LAB 最新报道

图片来源: Mohamed Akrout et al., arXiv:2608.19579, CC BY 4.0