Textual Self-attention Network: Test-Time Preference Optimization through Textual Gradient-based Attention

Shibing Mo, Haoyang Ruan, Kai Wu, Jing Liu · DOI

Abstract

Aligning Large Language Models (LLMs) with human preferences typically involves computationally intensive training-time methods like RLHF or DPO. This paper introduces the Textual Self-Attention Network (TSAN), a novel test-time alignment framework that optimizes responses during inference without updating model parameters. TSAN emulates the Query-Key-Value (QKV) attention mechanism entirely in natural language, treating candidate responses as textual "keys" and "values." By iteratively synthesizing the strengths of diverse outputs, TSAN produces high-quality responses that outperform existing state-of-the-art test-time methods and even surpass some traditionally fine-tuned models on benchmarks such as Arena-Hard and AlpacaEval 2.

Introduction

Traditional alignment techniques for LLMs are static; once a model is trained via Reinforcement Learning from Human Feedback (RLHF) or Direct Preference Optimization (DPO), its behavior is fixed. Adapting to new preferences requires expensive retraining. Furthermore, existing test-time methods often suffer from the "scalar bottleneck," where a single numerical reward score provides insufficient signal for complex refinement, leading to issues like reward hacking.

TSAN addresses these challenges by shifting the optimization process to the inference phase. It moves beyond simple selection from a pool of candidates to a compositional synthesis approach, where the model identifies and merges the best components of multiple potential answers.

Methodology: The TSAN Framework

TSAN operationalizes the classic Transformer self-attention mechanism within the textual domain. Unlike training-time methods that modify weights, TSAN treats the alignment task as a structured communication problem between LLM modules.

Comparison of Training-Time (RLHF, DPO) vs. Test-Time (TPO, TSAN) Preference Optimization frameworks.

The process follows an iterative loop:

  1. Candidate Generation & Selection: The base model generates $N$ diverse responses. A Reward Model (RM) scores these, and the top-$k$ are selected as the foundation.
  2. Textual QKV Construction: The user's prompt acts as the Query ($Q$), while the selected candidates serve as both Keys ($K$) and Values ($V$).
  3. Textual Attention Scoring: An LLM acts as an "attention module," generating a natural language report that weighs the merits, factual accuracy, and tone of each candidate relative to the query.
  4. Textual Aggregate Update: An "aggregator" LLM synthesizes a new response by combining the strengths identified in the attention report.
  5. Iterative Refinement: The system employs "textual gradients"—LLM-generated critiques—to refine the prompts for the attention and aggregation modules over several iterations ($T$).

Experimental Evaluation

The authors evaluated TSAN across a comprehensive suite of benchmarks, including AlpacaEval 2 and Arena-Hard 2 for general instruction following, HH-RLHF for safety, and MATH-500 for reasoning. The framework was tested on both open-source models (Llama-3.1, Mistral) and closed-source APIs (Qwen-3-Plus).

Key Results and Scaling

TSAN demonstrates significant performance gains across all tested models. On a base Llama-3.1-70B SFT model, TSAN increased the Arena-Hard score from 5.5% to 8.5%, surpassing the previous state-of-the-art test-time method, TPO. Notably, with just three iterations, the TSAN-equipped base model outperformed the official Llama-3.1-70B-Instruct model on several benchmarks.

Optimization trajectory of TSAN showing reward model score improvement across iterations for various base models.

As shown in the figure above, performance consistently improves as the number of iterations ($T$) increases from 1 to 5. This stable optimization trajectory is visible across different model scales, from Llama-3.1-8B to 70B. Furthermore, the method is remarkably cost-effective; a full optimization cycle costs approximately 0.016% of the resources required to train a Llama-3.1-70B DPO model.

Conclusion and Future Work

The Textual Self-Attention Network (TSAN) provides a powerful, training-free alternative for LLM alignment. By decomposing the refinement task into analysis and synthesis, it avoids the pitfalls of scalar reward signals and enables the creation of responses superior to any single initial candidate. While the method increases inference latency due to multiple LLM calls, its plug-and-play nature and high efficiency make it a compelling solution for dynamic preference optimization. Future research will focus on reducing the number of iterations required and exploring more complex textual architectures beyond self-attention.

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