让大模型主动提取上下文,更安全地理解用户意图。
Learning to Extract Context for Context-Aware LLM Inference
- 用强化学习自动从提示中提取意图、风险等上下文信号。
- 在SafetyInstruct上减少5.6%有害输出,提升良性请求响应率6.2%。
- 适合需要安全推理的场景,如内容审核与对话系统优化。
用户向大语言模型(LLMs)提出的指令常存在模糊或信息不足的问题,而用户意图、先验知识和风险因素等微妙的上下文线索强烈影响何为恰当回应。误解意图或风险可能导致不安全输出,过度谨慎则可能误拒良性请求。本文挑战传统框架——模型对请求立即生成响应而不考虑更广泛上下文。用户请求嵌入于意图、知识与过往经验等背景中,这些因素显著影响合理回答。我们提出一种框架,从用户提示中提取并利用此类上下文信息。具体而言,设计了一个基于强化学习的上下文生成器,采用自编码器式结构,训练其从提示中推断上下文信号,并用于引导回复生成。该方法在安全任务中尤为重要:模糊请求可能绕过防护机制,而看似可疑但无害的请求却可能触发不必要拒绝。实验表明,本方法在多个基础模型上使SafetyInstruct数据集的有害输出平均降低5.6%,并在XSTest和WildJailbreak上将攻击成功率与合规性的调和均值提升6.2%。结果验证了上下文提取对更安全、更可靠大模型推理的有效性。
原文摘要 · Abstract (English)
User prompts to large language models (LLMs) are often ambiguous or under-specified, and subtle contextual cues shaped by user intentions, prior knowledge, and risk factors strongly influence what constitutes an appropriate response. Misinterpreting intent or risks may lead to unsafe outputs, while overly cautious interpretations can cause unnecessary refusal of benign requests. In this paper, we question the conventional framework in which LLMs generate immediate responses to requests without considering broader contextual factors. User requests are situated within broader contexts such as intentions, knowledge, and prior experience, which strongly influence what constitutes an appropriate answer. We propose a framework that extracts and leverages such contextual information from the user prompt itself. Specifically, a reinforcement learning based context generator, designed in an autoencoder-like fashion, is trained to infer contextual signals grounded in the prompt and use them to guide response generation. This approach is particularly important for safety tasks, where ambiguous requests may bypass safeguards while benign but confusing requests can trigger unnecessary refusals. Experiments show that our method reduces harmful responses by an average of 5.6% on the SafetyInstruct dataset across multiple foundation models and improves the harmonic mean of attack success rate and compliance on benign prompts by 6.2% on XSTest and WildJailbreak. These results demonstrate the effectiveness of context extraction for safer and more reliable LLM inferences.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。