Textual Self-Attention Network: Test-Time Preference Optimization Through Textual Gradient-Based Attention

Shibing Mo, Haoyang Ruan, Kai Wu, Jing Liu

TL;DR

The Textual Self-Attention Network (TSAN) is a novel "test-time" alignment framework that optimizes LLM responses without updating a single parameter. By emulating the self-attention mechanism entirely in natural language—treating multiple candidate responses as textual "keys" and "values"—TSAN systematically synthesizes the strengths of diverse outputs into a single, high-quality response that outperforms many traditionally fine-tuned models.

What Problem Does This Paper Address?

Aligning Large Language Models (LLMs) with human preferences is usually a "training-time" endeavor. Techniques like RLHF (Reinforcement Learning from Human Feedback) or DPO (Direct Preference Optimization) bake preferences into the model's weights. However, this approach is static; once trained, the model cannot easily adapt to new preferences without expensive retraining.

Existing "test-time" methods—which try to improve the model during inference—often suffer from two main issues:

  1. The Scalar Bottleneck: Many rely on a single numerical reward score to pick the "best" of $N$ samples. This is a low-signal feedback loop prone to "reward hacking" (e.g., the model learns that longer answers get higher scores, regardless of quality).
  2. Linear Revision: Methods that use textual feedback (critiques) usually iterate on a single candidate response. They lack a principled way to compare, weigh, and merge the best parts of multiple different candidate answers.

Methods

The authors introduce TSAN, which operationalizes the classic Query-Key-Value (QKV) attention mechanism within the textual domain. The process follows an iterative loop:

  1. Candidate Generation & Selection: The model generates $N$ diverse responses. An independent Reward Model (RM) scores them, and the top-$k$ are selected.
  2. Textual QKV Construction:
    • Query ($Q$): The user's original prompt.
  3. Keys ($K$) & Values ($V$): The top-$k$ candidate responses.
  4. Textual Attention Score ($AS_{text}$): Instead of a dot-product matrix, an LLM acts as the "attention module." It analyzes the candidates against the query, producing a natural language report that weighs the merits, factual accuracy, and tone of each response.
  5. Textual Aggregate Update: A second LLM (the "aggregator") takes the candidates ($V$) and the attention report ($AS_{text}$) to synthesize a new, superior response that combines the strengths identified in the report.
  6. Iterative Refinement (Textual Gradients): The system doesn't stop at one go. It uses a "textual gradient" approach—where an LLM critiques the synthesized output—to refine the prompts used for the attention and aggregation modules, iteratively improving the output over several steps ($T$).

Crucially, this entire process requires no parameter updates, making it a "plug-and-play" enhancement for any model, including closed-source APIs.

Datasets

The authors evaluated TSAN across a comprehensive suite of benchmarks covering instruction following, reasoning, and safety:

  • AlpacaEval 2 & Arena-Hard 2: For general instruction following and human-like preference.
  • HH-RLHF: For helpfulness and harmlessness.
  • BeaverTails & XSTest: For safety and refusal behavior.
  • MATH-500: For mathematical reasoning capabilities.

Key Insights and Ideas

  • Compositional Synthesis vs. Selection: The "aha moment" here is that the best possible response often doesn't exist in the initial pool of candidates. By using textual attention to identify that "Candidate A has the best tone, but Candidate B has the correct facts," the model can build a "Frankenstein" response that is better than any individual part.
  • Lowering Cognitive Load: The authors suggest that by decomposing the task into "analyze first, then synthesize," they lower the cognitive load on the model compared to abstract "self-critique" methods.
  • Multi-Head Textual Attention: Just like in Transformers, TSAN benefits from "multiple heads." By generating multiple parallel updates (analogous to attention heads), the model explores a more diverse optimization space, preventing it from getting stuck in local optima during the refinement process.
  • Extreme Efficiency: Despite the extra computation at inference, TSAN is incredibly cheap compared to training. A full optimization cycle costs roughly 0.016% of the cost to train a Llama-3.1-70B DPO model.

Key Results

TSAN demonstrates significant performance boosts across the board:

  • Outperforming SOTA: On a base Llama-3.1-70B SFT model, TSAN boosted the Arena-Hard score from 5.5% to 8.5%, surpassing the previous state-of-the-art test-time method (TPO).
  • Closing the Gap with Instruct Models: With just three iterations, a base SFT model equipped with TSAN outperformed the official Llama-3.1-70B-Instruct on several benchmarks.
  • Scaling with Iterations: Performance consistently improved as the number of iterations ($T$) increased from 1 to 5, showing a stable optimization trajectory even on smaller models like Llama-3.1-8B.
  • API Compatibility: The method was successfully applied to closed-source models like Qwen-3-Plus via API, boosting its Arena-Hard score from 47.3% to a remarkable 72.1%.

Limitations and Future Work

  • Inference Latency: While computationally "efficient" in terms of total FLOPs compared to training, TSAN significantly increases the time-to-first-token and total generation time because it requires multiple LLM calls per query.
  • Reward Model Dependency: The system still relies on an external Reward Model to pick the initial "Keys." If the RM is biased or poor, the "Keys" provided to the attention module will be low quality.
  • Future Directions: The authors suggest exploring more complex "textual architectures" beyond self-attention and investigating how to further reduce the number of iterations needed to reach peak performance.

Summary updated

BibTeX
@inproceedings{mo2026textual,
  author = {Shibing Mo and Haoyang Ruan and Kai Wu and Jing Liu},
  title = {{Textual Self-Attention Network: Test-Time Preference Optimization Through Textual Gradient-Based Attention}},
  booktitle = {AAAI Conference on Artificial Intelligence},
  year = {2026},
  doi = {10.1609/aaai.v40i38.40527},
}
Figure