Abstract
Despite the effectiveness of deep neural networks in numerous natural language processing applications, recent findings have exposed the vulnerability of these language models when minor perturbations are introduced. While appearing semantically indistinguishable to humans, these perturbations can significantly reduce the performance of well-trained language models, raising concerns about the reliability of deploying them in safe-critical situations. In this work, we construct a computationally efficient self-healing process to correct undesired model behavior during online inference when perturbations are applied to input data. This is formulated as a trajectory optimization problem in which the internal states of the neural network layers are automatically corrected using a PID (Proportional-Integral-Derivative) control mechanism. The P controller targets immediate state adjustments, while the I and D controllers consider past states and future dynamical trends, respectively. We leverage the geometrical properties of the training data to design effective linear PID controllers. This approach reduces the computational cost to that of using just the P controller, instead of the full PID control. Further, we introduce an analytical method for approximating the optimal control solutions, enhancing the real-time inference capabilities of this controlled system. Moreover, we conduct a theoretical error analysis of the analytic solution in a simplified setting. The proposed PID control-based self-healing is a low-cost framework that improves the robustness of pre-trained large language models, whether standard or robustly trained, against a wide range of perturbations.
Introduction
Large Language Models (LLMs) are surprisingly fragile despite their impressive capabilities. Small, "adversarial" perturbations—such as swapping a word for a synonym that a human would find semantically identical—can cause a model’s performance to plummet. Standard defenses typically rely on adversarial training, which involves fine-tuning models on perturbed data. However, this approach is computationally expensive, often degrades performance on clean data, and frequently fails to generalize to unseen attack types.
This paper proposes a different paradigm: Self-healing. Instead of modifying the model's weights, the self-healing mechanism corrects the model’s internal hidden states in real-time as it processes a perturbed input. By treating an LLM as a discrete dynamical system, the authors steer internal trajectories back toward a "clean" data manifold using classical control theory.
Methodology: The PID Control Framework
The researchers treat a $T$-layer LLM as a dynamical system where the output of one layer serves as the input to the next. When an adversarial attack occurs, the "trajectory" of these internal states deviates from the expected path on the clean data manifold. To pull the model back on track, a PID controller is inserted at each layer.
As shown in the architecture above, the mechanism consists of three components:
- Proportional (P): Corrects the current state based on its immediate distance from the "clean" data manifold.
- Integral (I): Accounts for accumulated errors from previous layers to ensure small, persistent deviations are corrected.
- Derivative (D): Predicts future trends in the state dynamics to preemptively smooth out the trajectory.
Analytical Solutions for Real-Time Inference
Finding the optimal correction typically requires solving complex optimization problems (e.g., via Pontryagin’s Maximum Principle) during every inference step, which is computationally prohibitive. To address this, the authors derive a closed-form analytical solution by assuming that data manifolds are linear and layer transformations are roughly orthogonal. This allows the "healing" process to be implemented as a simple matrix multiplication, adding negligible overhead to the model's forward pass.
Experimental Evaluation
The method was evaluated across several Natural Language Inference (NLI) benchmarks, including SNLI, MNLI, and ANLI, against major attack algorithms like TextFooler and TextBugger.
Key Results
- Robustness Gains: On the SNLI dataset using DistilBERT, the PID controller improved accuracy against the "TextFooler" attack from 24.69% to 41.73%. For the larger OPT-1.3B model, accuracy against TextBugger improved by over 24%.
- Efficiency: The analytical PID solution is approximately 10x faster than iterative optimization methods, adding less than 1% to total inference time.
- Model Agnostic: The framework benefits both standard models and those already robustly trained (e.g., FreeLB), providing a consistent "robustness boost."
Conclusion and Future Work
PID control-based self-healing offers a low-cost, effective framework for improving LLM robustness at inference time. While the current analytical solution relies on certain linearity assumptions, it demonstrates significant practical success. Future research may explore automated hyperparameter tuning for the PID gains ($K_p, K_i, K_d$) and extending the framework to address other trustworthy AI goals, such as mitigating bias or improving fairness by defining manifolds for "fair" internal states.
Summary updated