---
title: Textual Self-Attention Network (TSAN)
url: https://www.emergentmind.com/topics/textual-self-attention-network-tsan
type: topic
---

# Textual Self-Attention Network (TSAN)

The Textual Self-Attention Network (TSAN) is a test-time preference optimization framework for language model alignment that operates entirely in the natural-language domain and requires no parameter updates. By recasting the evaluation and synthesis of candidate completions as a self-attention problem—implemented through language model prompting—TSAN systematically analyzes, weighs, and integrates the strengths of multiple model outputs, achieving interpretable iterative optimization. Empirical results demonstrate that TSAN significantly outperforms both standard supervised fine-tuning and previous test-time methods, including single-candidate revision, across a broad range of benchmarks [2511.06682].

## 1. Architectural Paradigm and Test-Time Pipeline

TSAN departs from conventional alignment mechanisms such as Reinforcement Learning from Human Feedback (RLHF) and Direct Preference Optimization (DPO), which require compute-intensive weight updates during training. Instead, TSAN performs all preference optimization at inference, keeping the base policy model πθ frozen. It leverages a multi-candidate, self-attention-inspired approach rather than single-candidate "critique+revise" loops.

Key steps in the TSAN inference loop:

- **Candidate Generation:** Sample $N$ diverse responses $\{y_1,\ldots, y_N\}$ from the frozen policy πθ.
- **External Scoring:** Use a reward model (RM) to select the top-$k$ candidates.
- **Textual QKV Construction:** Initialize $Q_\text{text}$ as the prompt $x$, and $K_\text{text}$ and $V_\text{text}$ as the concatenated top-$k$ responses paired with their RM scores.
- **Textual Attention Scoring:** Use a Prompted Attention Scorer LLM (PAS_model) with prompt $P_{att}$ to generate $AS_\text{text}$—an explicit, natural language analysis assigning relative weights and rationale (e.g., “Candidate 1 is very clear and accurate (50% weight)…”).
- **Aggregation & Synthesis:** Pass $(Q_\text{text}, AS_\text{text}, V_\text{text})$ to a Prompted Aggregation Updater LLM (PAU_model) to synthesize $y_{agg}$, a new response integrating the best aspects of all candidates in accordance with the attention analysis.
- **Iterative Refinement:** Optionally, iterate the process for $T$ steps, each time re-evaluating, reselecting, and further refining the response set via "textual gradient descent."
- **Output Selection:** Return the highest-scoring response (per RM) from all iterations.

TSAN’s key innovation is in reframing the candidate solution set as a Query–Key–Value attention operation, but executed in natural-language space at each step [2511.06682].

## 2. Mechanized Textual Self-Attention: QKV Encoding and Attention Analysis

TSAN draws an explicit analogy to transformer self-attention mechanisms. In a standard transformer, the operation is:

- $\alpha_i = \text{softmax}(Q \cdot K_i / \sqrt{d})$
- $\text{output} = \sum_{i} \alpha_i V_i$

TSAN implements this entirely in text as follows:

**Textual Encoding:**

- $Q_\text{text} = x$ (raw prompt)
- $K_\text{text}, V_\text{text}$ = concatenated top-$k$ candidate responses, each paired with RM scores.

**Attention Score Generation:**

- PAS_model receives $Q_\text{text}, K_\text{text}$ and produces $AS_\text{text}$: an interpretive breakdown of each candidate’s strengths/weaknesses and a summary that enables extraction of an equivalent to attention weights $\alpha = [\alpha_1 \ldots \alpha_k]$ from the narrative.

**Aggregation Update:**

- PAU_model, supplied with $Q_\text{text}, AS_\text{text}, V_\text{text}$, produces $y_{agg}$—a synthesized response composed to reflect the proportional strengths as captured in $AS_\text{text}$:

$$
y_{agg} \approx \sum_{i} \alpha_i V_i
$$

However, this process is performed via prompt-engineered natural language instructions, rather than learned numeric matrices.

## 3. Iterative Textual Gradient Descent and Inference Pseudocode

TSAN expands the single-pass synthesis into an iterative optimization, structured around natural-language “gradients.” Each iteration $i$ involves:

- Computation of $AS_\text{text}^{(i)} = \text{PAS_model}(Q_\text{text}, K_\text{text}^{(i)})$.
- Synthesis of $y_{agg}^{(i)} = \text{PAU_model}(Q_\text{text}, AS_\text{text}^{(i)}, V_\text{text}^{(i)})$.
- Critique of $y_{agg}^{(i)}$ by a dedicated LLM_L using prompt $P_l$, producing $L_\text{text}$ containing structured feedback and “natural-language gradients” (e.g., $\nabla_{y_{agg}}, \nabla_{P_{att}}, \nabla_{P_{agg}}$).
- Translation of these gradients into actionable update instructions $\delta y_{agg}$ using another LLM with $P_{grad}$.
- Production of $M$ parallel, refined “attention-head” candidates $\{y_{agg}^{(i),j}\}_{j=1}^M$ using $P_{update}$ and $\delta y_{agg}$.
- Rescoring the expanded candidate set with RM, reselection of top-$k$ for the next iteration, and repetition until $T$ is reached or rewards plateau.

**Algorithm 1 Pseudocode:**

```python
Input: x, policy πθ, reward model RM, max iters T
Y_cand ← πθ.sample(N)                # N initial candidates
Score and select top‐k → K_text^(0), V_text^(0)
Q_text = x

for i in 0...T–1:
    AS_text^(i) = PAS_model(Q_text, K_text^(i))
    y_agg   = PAU_model(Q_text, AS_text^(i), V_text^(i))
    L_text  = LLM_L(P_l, x, y_agg)   # critique & textual gradient
    δ = LLM(P_grad, L_text)          # gradient instruction
    new_y   = LLM(P_update, δ)       # M parallel “heads”
    Y_cand  += y_agg + new_y
    re‐score Y_cand via RM, pick top‐k → K_text^(i+1), V_text^(i+1)
end

y_final = argmax_{y∈Y_cand} RM(y); return y_final
```

## 4. Weighted Synthesis and Natural-Language Aggregation

Upon obtaining $AS_\text{text}$, TSAN’s aggregation step operationalizes guidance such as “focus proportionally more on the aspects highlighted as strengths in the attention scores.” Thus, the synthesized response merges clarity from one candidate, factuality from another, tone from a third, etc. This enables structured, interpretable, and preference-aligned output construction, closely mirroring a weighted Key–Value merge:

$$
y_{agg} \approx \sum_{i} \alpha_i V_i
$$

but rendered in human-interpretable text rather than as a numeric tensor.

## 5. Illustrative Case Studies: Multi-Aspect Synthesis

The framework's efficacy is demonstrated through detailed case studies:

- **Mathematical Reasoning:** For the alternating sum $1-2+3-4+\dots+99-100$, multiple candidates paired terms in various (sometimes flawed) ways. Attention analysis by PAS_model correctly identified which candidates applied the right grouping, and the PAU_model synthesized an explanation—“Group into 50 pairs yielding –1 each, so sum = 50×(–1)= –50. Thus boxed answer = –50.”—that was more explicit and accurate than any single candidate.

- **Instruction Following and Tone:** Given an instruction to “channel pure love” in a dialogue about consciousness and biology, candidates varied in warmth and depth. TSAN attention analysis integrated emotional intelligence from one and specificity from another, allowing the aggregation to combine an open-hearted tone with precise scientific inquiry (e.g., “love is not just an emotion…” alongside “How does neuroscience explain the reward circuits of love?”).

These examples illustrate TSAN’s core advantage in systematically harvesting complementary strengths from diverse outputs [2511.06682].

## 6. Empirical Performance, Ablations, and Computational Overhead

TSAN was benchmarked against base SFT models, the state-of-the-art TPO method, and commercially aligned models (e.g., Llama-3.1-Instruct, Qwen-3-Plus), across instruction following, open-ended preference, safety, and math tasks.

Performance improvements with $k=4$ (candidates), $M=4$ heads, $T=3$ iterations:

| Benchmark                       | SFT Base | TSAN          | TPO           |
|----------------------------------|----------|---------------|---------------|
| AlpacaEval 2 LC                  | 3.01%    | 18.57%        | 17.95%        |
| Raw win-rate WR                  | 4.91%    | 17.05%        | 20.18%        |
| Arena-Hard                       | 5.5%     | 8.5%          | 6.0%          |
| HH-RLHF avg reward               | –6.65    | –2.88         | –2.96         |
| XSTest safety                    | 75.2%    | 78.8%         | 76.6%         |
| MATH-500                         | 22.0%    | 28.2%         | 32.0%         |

Further summary: Aligned models (e.g., Llama-3.1-Instruct) also gain substantial accuracy when paired with TSAN (e.g., AlpacaEval 2 WR improves from 18.18% to 23.19%). Qwen-3-Plus+TSAN achieves an Arena-Hard score of 72.1%, compared to 47.3% without TSAN. In several metrics, gpt-oss 20B + TSAN matches or surpasses gpt-oss 120B [2511.06682].

Ablation studies reveal:

- Increasing $k$ (number of candidates) from 2 to 4 steadily increases reward scores.
- Increasing $M$ (parallel textual heads) yields richer multi-headed “gradient” signals, further boosting performance.

TSAN’s per-query computational cost is ≈11.78 PFLOPs—only ~0.016% of Llama-3.1-70B-DPO’s training cost (72,840 PFLOPs), and marginally higher than TPO’s 9.3 PFLOPs.

## 7. Significance and Novel Contributions

TSAN introduces a principled, interpretable workflow for combining the strengths of diverse language model outputs, reframing candidate aggregation as an attention problem in the natural language domain. It operates entirely at inference with no parameter updates, and its iterative, textual-gradient-based process is both structured and interpretable. TSAN systematically outperforms both prior test-time optimization strategies and strong training-time baselines in alignment tasks, with only marginal extra compute cost [2511.06682].

Source: https://www.emergentmind.com/topics/textual-self-attention-network-tsan