Safe-Embed: Unveiling the Safety-Critical Knowledge of Sentence Encoders

Jinseok Kim, Jaewon Jung, Sangyeop Kim, Sohyung Park, Sungzoon Cho · DOI

Introduction: The Safety Gap in Sentence Encoders

As Large Language Models (LLMs) proliferate, the challenge of mitigating "unsafe prompts"—inputs designed to elicit illegal, biased, or harmful content—becomes increasingly critical. While traditional classifiers are common, similarity-based search using sentence encoders offers a robust alternative by comparing new inputs against databases of known harmful prompts. However, a fundamental question remains: do these encoders truly "understand" the safety-critical nuances of the text, or do they rely on superficial lexical overlaps?

Safe-Embed addresses this by introducing a rigorous framework to evaluate the "Safety-Critical Knowledge" of sentence encoders. The goal is to determine if these models can distinguish between benign and harmful prompts that share similar wording (e.g., "How do I gut a human?" vs. "How do I gut a fish?") and if they can accurately categorize different types of harm.

Methodology: Defining Safety Knowledge

The researchers decompose safety knowledge into two primary pillars:

  1. Safety-Challenging Knowledge: The capacity to differentiate an unsafe prompt from a lexically similar safe counterpart.
  2. Safety-Taxonomy Knowledge: The ability to organize unsafe prompts into specific categories of harm, such as "Privacy Leaks" or "Hate Speech."
Conceptual framework of Safety-Challenging and Safety-Taxonomy Knowledge.

To ensure fair comparison across models with varying embedding space geometries (anisotropy), the study employs a normalization technique for cosine similarity. Furthermore, a new metric, Categorical Purity (CP), is introduced to measure how effectively prompts within the same safety category cluster together in the embedding space.

Benchmarking with New Datasets

The evaluation utilizes several key datasets, including two novel benchmarks:

  • XSTest (Augmented): A balanced pairwise evaluation set created by adding matching unsafe prompts to the existing XSTest dataset.
  • Safety-Contrast: A collection of 939 unsafe prompts from the Do-Not-Answer dataset, each paired with five safe variations generated by GPT-4 to probe the model's safety decision boundaries.

Key Insights: Context and Categorization

The study reveals several critical blind spots in current sentence encoders:

  • Contextual Sensitivity: Models often fail to distinguish between harmful actions and harmless references in specific contexts, such as gaming (e.g., "How to steal a car in GTA 4").
  • Historical Nuance: Encoders struggle to differentiate between factual historical inquiries and prompts that promote harmful biases or ideologies.
  • Category-Specific Performance: While encoders excel at identifying "Privacy Leaks" due to distinct linguistic patterns, they struggle with broader, more diverse categories like "Disinformation."
  • Training Limitations: Fine-tuning on Natural Language Inference (NLI) tasks does not necessarily improve a model's retention of safety-critical knowledge compared to unsupervised approaches.

The evaluation of various model families, including SBERT, SimCSE, ST5, and LLM-based encoders, yielded several key findings:

  • Scaling Effects: Within the ST5 family, safety knowledge generally scales with parameter count. The ST5-XXL model (4.86B parameters) demonstrated the highest average Categorical Purity.
  • Architecture Advantages: LLM2vec-Mistral (7B parameters) proved most effective at identifying safety boundaries, showing high sensitivity to the subtle changes that render a prompt unsafe.
  • General vs. Safety Performance: State-of-the-art general-purpose encoders, such as text-embedding-3-large, do not always outperform smaller models in safety taxonomy tasks, suggesting that general embedding quality is not a direct proxy for safety awareness.
Average Categorical Purity (CP) across various sentence encoders, highlighting the performance of larger models like ST5-XXL.

Conclusion and Future Directions

While larger models and LLM-based encoders show promise, current sentence encoders still face significant hurdles in understanding complex contexts and diverse harm categories. Future work should expand these benchmarks to include multi-sentence "jailbreak" attempts and multilingual evaluations, while also developing specialized training regimes to embed safety-critical knowledge directly into the models without sacrificing general utility.

Summary updated

BibTeX
@misc{kim2024safe,
  author = {Jinseok Kim and Jaewon Jung and Sangyeop Kim and Sohyung Park and Sungzoon Cho},
  title = {{Safe-Embed: Unveiling the Safety-Critical Knowledge of Sentence Encoders}},
  year = {2024},
  eprint = {2407.06851},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2407.06851},
}
Figure