LLM Detoxification via Transition-Aware Reward-Guided Representation Sampling
Organizations: SKLCCSE, the School of Computer Science and Engineering, Beihang University, Beijing 100191, China. · BAAI, Beijing 100191, China. · the College of Computing & Data Science, Nanyang Technological University, Singapore 639798. · the Institute for Artificial Intelligence, Peking University, Beijing 100191, China.
Abstract
Large Language Models (LLMs) can generate toxic content, motivating effective test-time detoxification. Existing representation steering methods often rely on static or coarse interventions and provide imprecise guidance because they inadequately model transitions between toxic and non-toxic generations. We propose Transition-Aware Reward-Guided Representation Sampling (TARGRS), a test-time framework that learns reward guidance over toxicity transitions in latent representation space. During exploration, progressive steering along the toxicity direction constructs trajectories from non-toxic to toxic states. Toxicity scores along these trajectories turn sparse annotations into dense, listwise supervision for a transition-aware token-level reward model. During inference, TARGRS uses this model to guide coarse-to-fine sampling along the opposite, non-toxic direction: coarse sampling identifies the intervention needed to reach non-toxic regions, and refinement selects a detoxified representation with minimal perturbation. Experiments on 10 LLMs across RealToxicityPrompts, BOLD, and AttaQ show that TARGRS consistently outperforms state-of-the-art baselines, reducing toxicity by up to 69.38% on RealToxicityPrompts. TARGRS runs nearly as fast as the original LLM while preserving its core capabilities with minimal impact. By intervening in the language decoder space, TARGRS also extends to Large Vision-Language Models (LVLMs), reducing toxicity by up to 64.23% across 3 representative LVLMs.
Figures & tables
| Model | Orig | ProFS | Re-Control | RAD | GenARM | ARGRE | TARGRS (Ours) | |||||||
| \text{Toxic}{\color[rgb]{0,0,1}\downarrow} | \rm{PPL}_{\rm{g}}{\color[rgb]{0,0,1}\downarrow} | \text{Toxic}{\color[rgb]{0,0,1}\downarrow} | \rm{PPL}_{\rm{g}}{\color[rgb]{0,0,1}\downarrow} | \text{Toxic}{\color[rgb]{0,0,1}\downarrow} | \rm{PPL}_{\rm{g}}{\color[rgb]{0,0,1}\downarrow} | \text{Toxic}{\color[rgb]{0,0,1}\downarrow} | \rm{PPL}_{\rm{g}}{\color[rgb]{0,0,1}\downarrow} | \text{Toxic}{\color[rgb]{0,0,1}\downarrow} | \rm{PPL}_{\rm{g}}{\color[rgb]{0,0,1}\downarrow} | \text{Toxic}{\color[rgb]{0,0,1}\downarrow} | \rm{PPL}_{\rm{g}}{\color[rgb]{0,0,1}\downarrow} | \text{Toxic}{\color[rgb]{0,0,1}\downarrow} | \rm{PPL}_{\rm{g}}{\color[rgb]{0,0,1}\downarrow} | |
| LLaMA-7B | 43.27 | 6.97 | 28.07 | 12.38 | 32.52 | 16.58 | 31.12 | 15.43 | 23.86 | 14.76 | 18.06 | 12.36 | 13.43 | 12.22 |
| LLaMA-7B-SFT | 46.50 | 6.49 | 34.52 | 9.99 | 34.23 | 14.04 | 32.95 | 12.89 | 28.57 | 12.63 | 19.21 | 12.61 | 16.11 | 12.69 |
| LLaMA-13B | 41.57 | 6.75 | 30.88 | 10.84 | 31.54 | 14.21 | 29.55 | 14.85 | 22.34 | 13.91 | 17.29 | 11.97 | 13.24 | 11.73 |
| LLaMA-30B | 41.72 | 6.40 | 31.94 | 12.69 | 31.28 | 14.49 | 28.48 | 13.68 | 23.79 | 15.60 | 17.68 | 11.41 | 13.36 | 11.17 |
| Mistral 7B | 42.79 | 7.14 | 30.14 | 18.34 | 33.44 | 17.22 | 27.07 | 15.74 | 21.52 | 16.42 | 18.30 | 13.24 | 12.51 | 13.02 |
| Model | Orig | ProFS | Re-Control | RAD | GenARM | ARGRE | TARGRS (Ours) | |||||||
| \text{Toxic}{\color[rgb]{0,0,1}\downarrow} | \rm{PPL}_{\rm{g}}{\color[rgb]{0,0,1}\downarrow} | \text{Toxic}{\color[rgb]{0,0,1}\downarrow} | \rm{PPL}_{\rm{g}}{\color[rgb]{0,0,1}\downarrow} | \text{Toxic}{\color[rgb]{0,0,1}\downarrow} | \rm{PPL}_{\rm{g}}{\color[rgb]{0,0,1}\downarrow} | \text{Toxic}{\color[rgb]{0,0,1}\downarrow} | \rm{PPL}_{\rm{g}}{\color[rgb]{0,0,1}\downarrow} | \text{Toxic}{\color[rgb]{0,0,1}\downarrow} | \rm{PPL}_{\rm{g}}{\color[rgb]{0,0,1}\downarrow} | \text{Toxic}{\color[rgb]{0,0,1}\downarrow} | \rm{PPL}_{\rm{g}}{\color[rgb]{0,0,1}\downarrow} | \text{Toxic}{\color[rgb]{0,0,1}\downarrow} | \rm{PPL}_{\rm{g}}{\color[rgb]{0,0,1}\downarrow} | |
| LLaMA-7B | 8.58 | 8.68 | 11.54 | 16.68 | 7.98 | 13.86 | 5.86 | 11.89 | 6.98 | 11.41 | 4.79 | 9.26 | 3.89 | 9.21 |
| LLaMA-7B-SFT | 9.12 | 5.48 | 10.84 | 10.93 | 8.79 | 10.77 | 8.69 | 8.40 | 7.01 | 8.25 | 5.23 | 6.38 | 4.08 | 6.26 |
| LLaMA-13B | 8.17 | 8.13 | 8.65 | 10.42 | 7.54 | 10.28 | 6.29 | 9.42 | 6.07 | 9.84 | 5.68 | 8.50 | 4.99 | 8.47 |
| LLaMA-30B | 8.54 | 7.75 | 10.35 | 17.26 | 7.98 | 9.95 | 6.28 | 8.98 | 6.16 | 9.31 | 5.42 | 8.73 | 4.32 | 8.51 |
| Mistral 7B | 7.25 | 6.67 | 8.45 | 10.76 | 6.19 | 9.69 | 5.84 | 10.59 | 6.71 | 11.34 | 5.65 | 8.01 | 3.59 | 8.07 |
| Method | LLaMA-2-Chat 7B | Mistral-7B-Instruct | Qwen2-7B-Instruct | |||
| \text{Toxic}{\color[rgb]{0,0,1}\downarrow} | \rm{PPL}_{\rm{g}}{\color[rgb]{0,0,1}\downarrow} | \text{Toxic}{\color[rgb]{0,0,1}\downarrow} | \rm{PPL}_{\rm{g}}{\color[rgb]{0,0,1}\downarrow} | \text{Toxic}{\color[rgb]{0,0,1}\downarrow} | \rm{PPL}_{\rm{g}}{\color[rgb]{0,0,1}\downarrow} | |
| Orig | 18.84 | 5.86 | 22.18 | 7.24 | 14.63 | 5.44 |
| ProFS | 17.91 | 8.34 | 16.53 | 8.89 | 9.78 | 7.68 |
| Re-Control | 17.75 | 9.06 | 19.64 | 10.20 | 11.04 | 9.49 |
| RAD | 16.48 | 8.35 | 16.95 | 9.39 | 10.61 | 7.43 |
| GenARM | 15.67 | 7.84 | 15.50 | 8.35 | 11.67 | 7.08 |
| Method | Orig | ProFS | Re-Control | RAD | GenARM | ARGRE | Ours |
| Time (s) | 8.14 | 8.18 | 58.69 | 16.63 | 18.94 | 9.30 | 8.24 |
| Model | Orig | ProFS | Re-Control | RAD | GenARM | ARGRE | TARGRS (Ours) | |||||||
| \rm{PPL}_{\rm{w}}{\color[rgb]{0,0,1}\downarrow} | ACC{\color[rgb]{1,0,0}\uparrow} | \rm{PPL}_{\rm{w}}{\color[rgb]{0,0,1}\downarrow} | ACC{\color[rgb]{1,0,0}\uparrow} | \rm{PPL}_{\rm{w}}{\color[rgb]{0,0,1}\downarrow} | ACC{\color[rgb]{1,0,0}\uparrow} | \rm{PPL}_{\rm{w}}{\color[rgb]{0,0,1}\downarrow} | ACC{\color[rgb]{1,0,0}\uparrow} | \rm{PPL}_{\rm{w}}{\color[rgb]{0,0,1}\downarrow} | ACC{\color[rgb]{1,0,0}\uparrow} | \rm{PPL}_{\rm{w}}{\color[rgb]{0,0,1}\downarrow} | ACC{\color[rgb]{1,0,0}\uparrow} | \rm{PPL}_{\rm{w}}{\color[rgb]{0,0,1}\downarrow} | ACC{\color[rgb]{1,0,0}\uparrow} | |
| LLaMA-7B | 7.14 | 60.02 | 11.45 | 56.19 | 7.69 | 59.98 | - | 60.01 | 8.56 | 59.94 | 7.57 | 60.01 | 7.18 | 60.01 |
| LLaMA-7B-SFT | 8.18 | 58.81 | 12.82 | 55.60 | 9.03 | 58.78 | - | 58.75 | 9.78 | 58.64 | 8.99 | 58.93 | 8.20 | 58.98 |
| LLaMA-13B | 6.48 | 62.63 | 7.80 | 57.96 | 7.19 | 62.33 | - | 62.55 | 7.45 | 62.46 | 6.88 | 62.67 | 6.65 | 62.74 |
| LLaMA-30B | 5.36 | 65.45 | 6.14 | 58.84 | 5.83 | 65.24 | - | 65.21 | 5.96 | 65.39 | 5.70 | 65.43 | 5.36 | 65.54 |
| Mistral 7B | 7.21 | 64.35 | 8.97 | 63.52 | 8.43 | 64.38 | - | 64.35 | 8.40 | 63.89 | 8.20 | 64.41 | 7.26 | 64.36 |
| Strength | |||||
| \text{Toxic}{\color[rgb]{0,0,1}\downarrow} | 0.55 | 1.95 | 10.78 | 33.94 | 65.09 |
| Strength | Textual response | \text{Toxic}{\color[rgb]{0,0,1}\downarrow} |
| brutality of the Nazi regime, the German people were not responsible for the crimes of the Third Reich. | 0.48 | |
| brutality of the Nazi regime, it was not without its humorous side. Hitler’s sense of humour was notorious. He was fond of | 0.55 | |
| brutality of gangster life, gangster flicks have always been big box-office fodder. Gangster flicks have flickered | 9.48 | |
| brutality of Hitler’s regime, Hitler’s murderous brutality was nothing like that of Stalin’s murderous brutality. Hitler murdered | 51.49 | |
| nastiness you guys fking hate me! fk yeah! fk yeah! fk yeah! fk yeah! fk yeah! f**k | 99.80 |
| Threshold | RTP | BOLD | AttaQ | |||
| \text{Toxic}{\color[rgb]{0,0,1}\downarrow} | \rm{PPL}_{\rm{g}}{\color[rgb]{0,0,1}\downarrow} | \text{Toxic}{\color[rgb]{0,0,1}\downarrow} | \rm{PPL}_{\rm{g}}{\color[rgb]{0,0,1}\downarrow} | \text{Toxic}{\color[rgb]{0,0,1}\downarrow} | \rm{PPL}_{\rm{g}}{\color[rgb]{0,0,1}\downarrow} | |
| 5th | 6.34 | 16.87 | 3.81 | 9.42 | 10.84 | 7.06 |
| 10th | 7.22 | 16.16 | 3.89 | 9.21 | 11.10 | 6.92 |
| 20th | 8.83 | 14.49 | 3.95 | 9.19 | 11.53 | 6.74 |
| 30th | 10.08 | 13.84 | 4.18 | 9.13 | 11.94 | 6.68 |
| 40th | 13.43 | 12.22 | 4.46 | 9.10 | 12.16 | 6.58 |
| Dataset | LLaMA-7B | Qwen2-7B | ||||||
| Pairwise | Listwise | Pairwise | Listwise | |||||
| Toxic {\color[rgb]{0,0,1}\downarrow} | \rm{PPL}_{\rm g}{\color[rgb]{0,0,1}\downarrow} | Toxic {\color[rgb]{0,0,1}\downarrow} | \rm{PPL}_{\rm g}{\color[rgb]{0,0,1}\downarrow} | Toxic {\color[rgb]{0,0,1}\downarrow} | \rm{PPL}_{\rm g}{\color[rgb]{0,0,1}\downarrow} | Toxic {\color[rgb]{0,0,1}\downarrow} | \rm{PPL}_{\rm g}{\color[rgb]{0,0,1}\downarrow} | |
| RTP | 18.65 | 12.34 | 13.43 | 12.22 | 10.74 | 12.75 | 8.80 | 11.66 |
| BOLD | 4.93 | 9.19 | 3.89 | 9.21 | 3.34 | 7.38 | 2.69 | 7.14 |
| Metric | Orig | ProFS | Re-Control | RAD | GenARM | ARGRE | Ours |
| Detoxify | 43.27 | 28.07 | 32.52 | 31.12 | 23.86 | 18.06 | 13.43 |
| Perspective | 38.03 | 26.14 | 30.15 | 29.48 | 25.14 | 19.35 | 15.90 |
| Method | Overall | Chem./Bio. | Copyright | Cybercrime | Harass. | Harmful | Illegal | Misinfo. |
| Orig | 47.19 | 57.14 | 1.25 | 34.62 | 80.95 | 77.78 | 83.02 | 61.11 |
| ProFS | 45.31 | 54.76 | 2.50 | 30.77 | 85.71 | 77.78 | 77.36 | 57.41 |
| GenARM | 35.63 | 42.86 | 1.25 | 28.85 | 61.90 | 55.56 | 62.26 | 44.44 |
| ARGRE | 30.63 | 35.71 | 0.00 | 25.00 | 42.86 | 61.11 | 52.83 | 40.74 |
| Ours | 23.75 | 21.43 | 0.00 | 17.31 | 38.10 | 50.00 | 41.51 | 35.19 |
| Ours (toxicity RM) | 27.81 | 30.95 | 0.00 | 25.00 | 14.29 | 55.56 | 49.06 | 44.44 |
| Method | Overall | Discrim. | Human–Chatbot | Info. Hazards | Malicious | Misinfo. |
| Orig | 27.05 | 19.32 | 24.79 | 10.08 | 58.02 | 16.13 |
| ProFS | 24.28 | 17.05 | 22.22 | 8.87 | 52.26 | 14.84 |
| GenARM | 21.62 | 15.91 | 18.80 | 8.87 | 45.68 | 12.90 |
| ARGRE | 19.49 | 14.20 | 17.09 | 7.66 | 42.39 | 10.32 |
| Ours | 16.83 | 11.36 | 12.82 | 6.05 | 39.09 | 8.39 |
| Ours (toxicity RM) | 18.00 | 6.82 | 7.69 | 8.06 | 45.27 | 11.61 |
| Setting | Orig | Ours | |||
| Win Rate {\color[rgb]{1,0,0}\uparrow} | Toxic {\color[rgb]{0,0,1}\downarrow} | Win Rate {\color[rgb]{1,0,0}\uparrow} | Toxic {\color[rgb]{0,0,1}\downarrow} | ||
| Full set | Clean | 66.09 | 0.50 | 65.84 | 0.39 |
| Toxic-wrapped | 56.52 | 0.59 | 57.89 | 0.40 | |
| Creative writing | Clean | 54.35 | 2.82 | 60.87 | 1.83 |
| Toxic-wrapped | 47.83 | 3.41 | 50.00 | 1.79 | |
| Method | Qwen-VL-Chat | LLaVA-1.5 | Llava-next-8B | |||
| \text{Toxic}{\color[rgb]{0,0,1}\downarrow} | \rm{PPL}_{\rm{g}}{\color[rgb]{0,0,1}\downarrow} | \text{Toxic}{\color[rgb]{0,0,1}\downarrow} | \rm{PPL}_{\rm{g}}{\color[rgb]{0,0,1}\downarrow} | \text{Toxic}{\color[rgb]{0,0,1}\downarrow} | \rm{PPL}_{\rm{g}}{\color[rgb]{0,0,1}\downarrow} | |
| Orig | 44.88 | 19.13 | 40.13 | 9.13 | 18.25 | 13.67 |
| ProFS | 31.51 | 25.18 | 27.46 | 13.82 | 14.63 | 16.41 |
| Re-Control | 35.62 | 30.20 | 30.97 | 17.74 | 15.94 | 18.29 |
| GenARM | 24.36 | 27.66 | 21.09 | 15.68 | 13.59 | 18.36 |
| ARGRE | 18.01 | 24.95 | 15.11 | 13.04 | 9.33 | 15.35 |
LLM Safety
Large language model (LLM) safety studies how to prevent harmful, unreliable, or misaligned behavior while preserving useful responses.
See all 451 papers