Preconditioned Test-Time Adaptation for Out-of-Distribution Debiasing in Narrative Generation

arXiv cs.CL Papers

Summary

This paper proposes CAP-TTA, a test-time adaptation framework that uses preconditioned LoRA updates triggered by bias-risk scores to mitigate toxicity and bias in large language models during narrative generation, achieving faster optimization and better fluency than standard baselines.

arXiv:2603.13683v3 Announce Type: replace Abstract: Although debiased large language models (LLMs) excel at handling known or low-bias prompts, they often fail on unfamiliar and high-bias prompts. We demonstrate via out-of-distribution (OOD) detection that these high-bias prompts cause a distribution shift, degrading static model performance. To enable real-time correction, we propose CAP-TTA, a test-time adaptation framework. CAP-TTA triggers context-aware LoRA updates only when a bias-risk score exceeds a set threshold. By utilizing an offline precomputed diagonal preconditioner, it ensures fast and stable optimization. Across multiple benchmarks and human evaluations, CAP-TTA effectively reduces toxicity/bias score with significantly lower latency than standard optimization methods (e.g., AdamW or SGD). Furthermore, it prevents catastrophic forgetting, and substantially improves narrative fluency over state-of-the-art baselines without compromising debiasing performance.
Original Article
View Cached Full Text

Cached at: 04/20/26, 08:32 AM

# Preconditioned Test-Time Adaptation for Out-of-Distribution Debiasing in Narrative Generation

Source: https://arxiv.org/html/2603.13683

Hanwen Shen¹,∗ Ting Ying²,∗ Jiajie Lu¹ Shanshan Wang³,†

¹Laboratory for Artificial Intelligence in Mathematics Education, Stevens Institute of Technology
²Independent Researcher
³NLP2CT Lab, Department of Computer and Information Science, University of Macau

[email protected], [email protected]

###### Abstract

Although debiased large language models (LLMs) excel at handling known or low-bias prompts, they often fail on unfamiliar and high-bias prompts. We demonstrate via out-of-distribution (OOD) detection that these high-bias prompts cause a distribution shift, degrading static model performance. To enable real-time correction, we propose CAP-TTA, a test-time adaptation framework. CAP-TTA triggers context-aware LoRA updates only when a bias-risk score exceeds a set threshold. By utilizing an offline precomputed diagonal preconditioner, it ensures fast and stable optimization. Across multiple benchmarks and human evaluations, CAP-TTA effectively reduces toxicity/bias scores with significantly lower latency than standard optimization methods (e.g., AdamW or SGD). Furthermore, it prevents catastrophic forgetting, and substantially improves narrative fluency over state-of-the-art baselines without compromising debiasing performance.

## 1 Introduction

Large language models (LLMs) have achieved substantial progress in natural language understanding and generation. As generated content scales and spreads, social bias and toxicity risks in model outputs are amplified. Bias is commonly understood as a systematic skew that produces harm, including unfair resource allocation and representational harms such as stereotyping or misrepresentation (Suresh and Guttag, 2021). At the same time, bias is inherently a normative concept: it requires specifying who is harmed and in what ways, why mitigation is warranted, and whether evaluation metrics align with the intended mitigation goals (Blodgett et al., 2020). Importantly, what counts as biased or harmful is neither static nor universal but varies across historical periods, cultural contexts, and regions (Mitchell et al., 2021). Consequently, bias cannot be fully characterized by a single fixed dimension or predefined attributes. This creates challenges for large language models, since static models and benchmarks may overlook emergent biases, particularly in out-of-distribution settings such as creative narrative generation.

To address these issues, prior work has proposed a range of debiasing approaches, including data- and representation-level interventions (Bolukbasi et al., 2016; Zhao et al., 2018), as well as analyses and control methods for bias and toxicity in generative models (Sheng et al., 2019; Gehman et al., 2020). Prompt-based techniques further enable inference-time (or test-time) self-diagnosis and self-debiasing (Schick et al., 2021). However, most existing methods learn fixed bias patterns in an offline, static manner. In real-world deployment, bias expressions can emerge and drift with changes in prompt distributions and contexts; consequently, static constraints may degrade under out-of-distribution (OOD) conditions, sometimes addressing only superficial trigger patterns. Moreover, if an LLM were made "perfectly unbiased," how could it faithfully generate a biased character or depict bias within a narrative? This resembles constructing a bias-free utopia while losing the capacity for self-correction (Becker, 1967; Harding, 1992). We therefore seek a genuinely debiased model that is not merely instructed not to discriminate, but can adapt dynamically—ideally with continual learning ability (Wu et al., 2024).

Motivated by this gap, we view debiasing as a continual adaptation problem under distribution shift and propose **CAP-TTA** (Preconditioned Context-Aware Test-Time Adaptation), a threshold-triggered test-time adaptation (TTA) approach for debiasing. CAP-TTA monitors bias/toxicity signals online during generation and triggers lightweight updates only when the risk score crosses a threshold, thereby controlling test-time overhead and reducing unnecessary parameter drift. Upon triggering, it updates only a small adapter module, e.g., LoRA (Hu et al., 2021); and performs preconditioned few-step updates to improve stability and efficiency (Sun et al., 2020). The design also draws on continual learning principles for mitigating forgetting (Kirkpatrick et al., 2017), aiming to improve safety while preserving generation quality.

This work makes three main contributions:

- Using a standard OOD detection method, we find that the high-bias set is consistently more OOD than the low-bias set in the base model, and that static LLMs degrade under such OOD shifts.
- We introduce CAP-TTA, a test-time adaptation framework for debiasing under distribution shift. CAP-TTA matches the SOTA bias scores of self-correction methods while increasing fluency by 12%, under safety-prioritized hyperparameters.
- We compare different trigger thresholds and prompt lengths. In fluent setting, CAP-TTA yields a marginally significant (p=0.07) reduction in bias under a DiD analysis, compared to base model, with higher fluency, suggesting a solid potential to mitigate degradation and resist catastrophic forgetting. We validate reduced bias judgments with human evaluation.

## 2 Related Work

### 2.1 Social Bias in LLMs and Benchmarks

A large literature documents social harms in language models and provides taxonomies, evaluation protocols, and mitigation strategies (Gallegos et al., 2024). Foundational work shows that stereotypical associations are embedded in representation space and can be studied systematically (Bolukbasi et al., 2016). Benchmarks operationalize these harms: RealToxicityPrompts (RTP) measures toxic degeneration under prompt variation (Gehman et al., 2020), while StereoSet and CrowS-Pairs target stereotypical and implicit biases (Nadeem et al., 2021; Nangia et al., 2020). Broader evaluations such as HELM treat bias and toxicity as first-class dimensions (Liang et al., 2022). However, bias measurement is sensitive to prompt format and multitask prompting (Akyürek et al., 2022), and harms can persist or re-emerge in long-form narrative settings where context increases degrees of freedom (Jeung et al., 2024). We build on this line by focusing on long-form narrative generation under distribution shift, where biases may surface in forms not covered by static benchmarks alone.

### 2.2 Debiasing and Safety Alignment for Generation

Debiasing spans data-, model-, and decoding-level interventions. Data-centric approaches mitigate bias amplification via corpus constraints or reweighting (Zhao et al., 2017); model-centric methods reduce protected-attribute information using adversarial training or representation editing (Zhang et al., 2018; Ravfogel et al., 2020). Inference-time control can directly reshape generation, including gradient-based steering (Datharaju et al., 2020), discriminator-guided decoding (Yang and Klein, 2021), expert/anti-expert composition (Liu et al., 2021), and prompting-based self-debiasing (Schick et al., 2021). Prior work shows these methods are highly setting-dependent and may not transfer under prompt shift (Meade et al., 2022). Large-scale alignment pipelines—e.g., RLHF-style instruction tuning (Ouyang et al., 2022) and preference optimization (Rafailov et al., 2023)—and user-steerable variants such as SteerLM (Dong et al., 2023) are widely used to reduce harmful outputs, yet recent studies suggest brittleness under long contexts or subsequent updates (Anil et al., 2024; Hubinger et al., 2024; Qi et al., 2024). Wang et al. (2025) showed that existing detectors cannot reliably identify LLM-generated poetry, highlighting that style and cultural context may undermine static mechanisms. In contrast, we study selective on-the-fly correction during generation to improve robustness under unknown prompts while preserving narrative quality, beyond simple memorization.

### 2.3 Continual Learning and TTA

Distribution shift is classically formalized as a mismatch between training and deployment distributions (Quiñonero-Candela et al., 2009). Continual learning provides a framework for adapting under non-stationary data streams while maintaining prior knowledge (Parisi et al., 2019), and recent surveys discuss additional challenges for LLMs such as stability, data selection, and preserving general capabilities (Wang et al., 2024a; Wu et al., 2024; Xiao et al., 2025). Test-time adaptation (TTA) updates models at inference time to improve robustness under shift. Test-Time Training leverages self-supervision (Sun et al., 2020; Team, 2025; Snell et al., 2024), while Tent adapts via entropy minimization (Wang et al., 2021); subsequent work improves objectives and stability in dynamic settings (Gandelsman et al., 2022; Zhang et al., 2022; Niu et al., 2023) and studies continual test-time adaptation under streaming shifts (Wang et al., 2022). Test-time adaptation includes training-based (i.e., fine-tuning) and training-free methods. Parameter-Efficient Fine-Tuning (PEFT) methods, notably Low-Rank Adaptation (LoRA) and its recent efficient variants, have significantly reduced the computational overhead of optimizing LLMs by updating only a fraction of the weights (Hu et al., 2021; Dettmers et al., 2023; Zhang et al., 2023; Liu et al., 2024; Xiao et al., 2026). Also, training-free activation steering can effectively intervene in the internal representations of LLMs during inference, enabling depth-weighted enhancements for truthful reporting (Góral et al., 2025; García-Ferriero et al., 2025). A recurring issue in continual and test-time learning is catastrophic forgetting, commonly addressed with importance-weighted regularization such as EWC (Kirkpatrick et al., 2017). Curvature-aware optimization (e.g., K-FAC) provides efficient approximations for stabilizing updates (Martens and Grosse, 2015). CAP-TTA instantiates these principles with a lightweight adapter and a thresholded trigger to reduce unnecessary updates.

| Model | Method | Type | Safety (Mean Bias ↓) | Efficiency | Dynamic? |
|-------|--------|------|----------------------|-----------|----------|
| | | | ID (Safe) | OOD (Toxic) | Speed (tok/s) |
| **Base Models** | | | | | |
| Qwen3-4B | Base Pretrained | | 0.289 | 0.452 | 19.4 | No |
| DeepSeek-R1-8B | Base Pretrained | | 0.395 | 0.454 | 26.0 | No |
| **Static Alignment / Debiasing Baselines** | | | | | |
| DeepSeek-R1-8B-Debiased | Offline Detox | | 0.389 | 0.471 | 21.9 | No |
| Mistral-7B-Instruct | Offline Detox | | 0.449 | 0.525 | 25.3 | No |
| **Dynamic / Self-Correction Baselines** | | | | | |
| Qwen3-4B-Sherlock | Self-Correction | | 0.395 | 0.437 | 18.8 | Yes (CoT) |

**Table 1:** Quantitative comparison on ID (safe)/OOD (toxic) prompts. We report BB Bias score on the ID/OOD set. Speed is decoding throughput (tok/s). Dynamic? indicates whether the method performs Chain-of-Thought.

## 3 Method

### 3.1 Problem Definition

**Narrative generation.** A deployed LLM with frozen base parameters θ is usually treated as a conditional distribution p_θ(y | x), where x is a user prompt (potentially long narrative instructions) and y = (y₁, ..., y_T) is the generated continuation. We generate narratives in K segments. Let y^(0) ~ p_θ(· | x). For k = 1, ..., K, define

h_k ≜ (x, y^(0), ..., y^(k-1)),

y^(k) ~ p_θ(· | h_k).

h_k represents the history (prompt plus previously generated segments) before generating segment k.

**Episodic test-time adaptation.** We attach a parameter-efficient adapter φ (e.g., LoRA) and keep θ fixed: p_{θ,φ}(y | x). Adaptation proceeds episodically. At the start of each prompt/session, we re-initialize the adapter pa

Similar Articles

Selective Test-Time Debiasing for CLIP via Reward Gating

arXiv cs.CL

Introduces Reward-Gated Test-Time Adaptation (RG-TTA), a reinforcement learning framework that selectively applies debiasing to CLIP models based on input bias sensitivity, resolving the fairness-utility trade-off.