DIESEL - Dynamic Inference-Guidance via Evasion of Semantic Embeddings in LLMs

Ben Ganon, Alon Zolfi, Omer Hofman, Inderjeet Singh, Hisashi Kojima, Yuval Elovici, Asaf ShabtaiSubmission to ICLR 2025 · Withdrawn

TL;DR

DIESEL (Dynamic Inference-Guidance via Evasion of Semantic Embeddings in LLMs) is a training-free, post-hoc decoding method that steers large language models away from unsafe or unwanted content during generation. By reranking candidate tokens using an external, lightweight sentence embedder that measures semantic similarity against natural-language descriptions of negative concepts, DIESEL dramatically improves safety and jailbreak resistance with only a ~1.5× inference runtime overhead.

What Problem Does This Paper Address?

Ensuring that conversational LLMs remain aligned with human values (avoiding toxic outputs, malware generation, or compliance with adversarial jailbreaks) typically relies on three paradigms:

  1. Ad-hoc fine-tuning (RLHF/RLAIF): Computationally expensive, requires extensive annotations, and remains vulnerable to adversarial attacks like Greedy Coordinate Gradient (GCG).
  2. Input/Output filtering: Static guards that often resort to blunt, unhelpful canned refusals (e.g., "As an AI, I cannot...").
  3. Inference guidance: Methods like RAIN use search-and-backward loops that incur massive runtime penalties (~190× slowdown), while others (like SafeDecoding) require fine-tuning an auxiliary "expert" safety model.

There is a lack of lightweight, real-time decoding interventions that steer models toward safe, nuanced responses without retraining parameters or relying on rigid safety taxonomies.

Methods

DIESEL operates entirely at inference time as a three-step token adjustment loop:

[Candidate Selection (Top-p)] ──> [Embed & Compare to Concepts] ──> [Score Fusion & Token Selection]
  1. Candidate Selection: For the current generation step, the base LLM produces a next-token distribution. Using standard Top-$p$ (Nucleus) truncation, DIESEL samples a pool of $b$ candidate tokens ($V_b$, with $b=20$).
  2. Latent Space Semantic Similarity: DIESEL appends each candidate token $x_n^i$ to the currently generated response text and embeds the sequence using a tiny, off-the-shelf sentence transformer (MiniLM, ~33M parameters; under 0.5% the size of a 7B model). It computes the maximum cosine similarity between this candidate continuation and pre-computed embeddings of user-defined negative concepts $R$ (e.g., "violence and violent crimes"). This yields a normalized safety score: $$\gamma(x_n^i) = \frac{1}{2} \left(1 - \max_{r \in R} \text{CS}\left(f_{\theta_2}(X_G + \{x_n^i\}), f_{\theta_2}(r)\right)\right)$$
  3. Token Reranking: The final token is selected by maximizing a convex combination of the original LM probability and the safety score: $$S(x_n^i) = (1 - \alpha) P(x_n^i \mid x_{1:n-1}) + \alpha \gamma(x_n^i)$$ with $\alpha = 0.98$. The token with the highest score is appended, steering the continuation away from negative semantic clusters.

Datasets

The authors evaluated DIESEL across three open-weight models (Llama-3-8B, Mistral-7B, Vicuna-7B) using:

  • AdvBench: ~500 malicious and unsafe prompts spanning harmful behaviors, tested on uncensored models and standard chat models subjected to GCG jailbreak attacks.
  • TruthfulQA: 817 multi-category questions to evaluate whether safety steering degrades factual accuracy or response coherence on benign queries.
  • Wiki Movie Plots: Used to demonstrate domain generalizability by treating the genre "horror" as a negative concept during movie summarization.

Key Insights and Ideas

  • Decoupling semantic filtering from the generative LLM: Sentence-level semantic comparisons do not require a multi-billion-parameter backbone. Offloading similarity checks to a 33M-parameter encoder provides a strong safety signal while keeping generation fast.
  • Steering, not stonewalling: Instead of triggering hard refusals, DIESEL acts as a semantic "rudder," encouraging nuanced, constructive, and de-escalated replies.
  • Zero-shot negative concept authoring: Negative concepts are specified as plain text strings. Safety engineers or end users can introduce or remove disallowed concepts on the fly without updating model weights or gathering fine-tuning datasets.

Key Results

  • Safety Improvement: On uncensored Llama-3-8B evaluated on AdvBench via GPT-4o (1–5 severity scale), level-5 (maximally harmful) outputs dropped from 313 to 215. Across all tested models, 94 prompts originally scoring 5 shifted down to score 1 (safe refusal/de-escalation).
  • Jailbreak Defense: Under GCG adversarial suffix attacks, DIESEL significantly flattened the severity distribution on Mistral and Vicuna, preventing successful adversarial bypasses.
  • Speed & Latency: DIESEL introduced only a 1.46×–1.64× runtime overhead compared to vanilla inference. In contrast, the training-free baseline RAIN introduced a ~186×–202× slowdown.
  • Benign Preservation: On TruthfulQA, response coherence remained intact (<5% degradation), with 51% truthfulness (comparable to vanilla inference at 60%).
  • Human Evaluation: In a double-blind user study (20 participants), 80% of DIESEL responses were judged safer than vanilla model responses.
  • Beyond Safety: When applied to horror movie summaries, DIESEL successfully filtered horror elements in 82% of cases.

Limitations and Future Work

  • Long-context embedding attenuation: As generation length grows, sentence transformers struggle to capture fine-grained semantic shifts from a single newly added token. While early tokens usually lock in the response trajectory, long-form sequences may require chunked or dynamic embedding schemes.
  • Irrevocable token selection: Decoding is strictly forward-looking; an innocent-looking token chosen at step $t$ might enable an unsafe phrase at step $t+1$. The authors avoided multi-step look-ahead beam searches to prioritize real-time inference speeds.

Summary updated

Abstract

In recent years, conversational large language models (LLMs) have shown tremendous success in tasks such as casual conversation, question answering, and personalized dialogue, making significant advancements in domains like virtual assistance, social interaction, and online customer engagement. However, they often generate responses that are not aligned with human values (e.g., ethical standards, safety, or social norms), leading to potentially unsafe or inappropriate outputs. While several techniques have been proposed to address this problem, they come with a cost, requiring computationally expensive training or dramatically increasing the inference time. In this paper, we present DIESEL, a lightweight inference guidance technique that can be seamlessly integrated into any autoregressive LLM to semantically filter undesired concepts from the response. DIESEL can function either as a standalone safeguard or as an additional layer of defense, enhancing response safety by reranking the LLM's proposed tokens based on their similarity to predefined negative concepts in the latent space. This approach provides an efficient and effective solution for maintaining alignment with human values. Our evaluation demonstrates DIESEL's effectiveness on state-of-the-art conversational models (e.g., Llama 3), even in challenging jailbreaking scenarios that test the limits of response safety. We further show that DIESEL can be generalized to use cases other than safety, providing a versatile solution for general-purpose response filtering with minimal computational overhead.
BibTeX
@misc{ganon2024diesel,
  author = {Ben Ganon and Alon Zolfi and Omer Hofman and Inderjeet Singh and Hisashi Kojima and Yuval Elovici and Asaf Shabtai},
  title = {{DIESEL - Dynamic Inference-Guidance via Evasion of Semantic Embeddings in LLMs}},
  year = {2024},
  eprint = {2411.19038},
  archivePrefix = {arXiv},
  url = {https://arxiv.org/abs/2411.19038},
}
Figure