Improving Large Language Model Safety with Contrastive Representation Learning
Samuel Simko, Mrinmaya Sachan, Bernhard Sch\"olkopf, Zhijing Jin

TL;DR
This paper introduces a contrastive representation learning framework to enhance the robustness of large language models against adversarial attacks, effectively distinguishing harmful inputs from benign ones without sacrificing performance.
Contribution
It presents a novel finetuning method using triplet-based loss and adversarial hard negative mining to improve LLM safety against diverse attack types.
Findings
Outperforms previous defenses in robustness against input and embedding attacks
Maintains standard performance while increasing security
Effective across multiple language models
Abstract
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…
Peer Reviews
No public reviews on file for this paper yet. If you reviewed it on a platform where reviews are public (OpenReview, ICLR, NeurIPS, ICML), you can paste yours below so the community can read it here.
Code & Models
Videos
Taxonomy
TopicsTopic Modeling · Natural Language Processing Techniques
