arXiv:2506.11938cs.CLcs.AI2025-06EMNLP被引 7

用对比学习提升大模型安全,区分有害与正常输出

Improving Large Language Model Safety with Contrastive Representation Learning

  • 将防御问题转为对比表征学习,通过三元组损失训练
  • 在多种攻击下鲁棒性更强,且不影响正常任务表现
  • 适合关注大模型安全、对抗攻击防护的研究者

大型语言模型(LLMs)具有强大的社会影响力,但其对多样化和不受控输入的响应能力使其易受对抗攻击。现有防御方法往往难以跨攻击类型泛化。本文提出一种基于对比表示学习(CRL)的防御框架,通过三元组损失结合对抗性难负样本挖掘,微调模型以增强良性与有害表示之间的分离。实验结果表明,该方法在多个模型上均优于现有基于表示工程的防御方案,在不损害标准性能的前提下,显著提升了对输入级和嵌入空间攻击的鲁棒性。代码已公开于 https://github.com/samuelsimko/crl-llm-defense。

原文摘要 · Abstract (English)

Large Language Models (LLMs) are powerful tools with profound societal impacts, yet their ability to generate responses to diverse and uncontrolled inputs leaves them vulnerable to adversarial attacks. While existing defenses often struggle to generalize across varying attack types, recent advancements in representation engineering offer promising alternatives. In this work, we propose a defense framework that formulates model defense as a contrastive representation learning (CRL) problem. Our method finetunes a model using a triplet-based loss combined with adversarial hard negative mining to encourage separation between benign and harmful representations. Our experimental results across multiple models demonstrate that our approach outperforms prior representation engineering-based defenses, improving robustness against both input-level and embedding-space attacks without compromising standard performance. Our code is available at https://github.com/samuelsimko/crl-llm-defense

大模型安全对比学习对抗防御

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。