Share your thoughts, 1 month free Claude Pro on usSee more
WorkDL logo mark

Improving Large Language Model Safety with Contrastive Representation Learning

About

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

Samuel Simko, Mrinmaya Sachan, Bernhard Sch\"olkopf, Zhijing Jin• 2025

Related benchmarks

TaskDatasetResultRank
Safety Alignment EvaluationImplicit Domain Risk Management Domain
JSR39.1
3
Safety Alignment EvaluationImplicit Domain Risk Education Domain
JSR0.291
3
Safety Alignment EvaluationImplicit Domain Risk Finance Domain
JSR22.6
3
Showing 3 of 3 rows

Other info

Follow for update