TL;DR
Direct Preference Optimization (DPO) typically treats every token in a model's response as equally important, failing to capture fine-grained credit assignment. This paper introduces AttentionPO, a content-aware method that leverages an LLM's intrinsic attention mechanism to dynamically weigh tokens during alignment. By focusing gradient updates on the tokens that actually drive preference judgments, AttentionPO significantly outperforms standard DPO and other token-level baselines without requiring an external reward model.
What Problem Does This Paper Address?
When aligning Large Language Models (LLMs) with human preferences, standard algorithms like DPO treat all tokens uniformly when calculating losses. However, language is inherently non-uniform: a single critical word (such as "not" or a factual error) can completely dictate a response's quality, while filler words matter very little.
Existing token-level preference optimization methods try to address this but suffer from major drawbacks. They either rely on rigid, position-based heuristics (e.g., assuming earlier tokens always matter more) or require training expensive auxiliary models to predict token importance. The authors of this paper tackle a compelling question: Can we extract precise, content-aware token weights directly from the model itself without incurring extra training costs?
Methods
The authors propose Token-weighted DPO (TwDPO), a mathematically grounded framework that integrates token-level weights into the DPO objective. They instantiate this via AttentionPO, which extracts token weights using the model's own internal attention maps through a three-step workflow:
- Attention Extraction: The reference LLM ($\pi_{ref}$) is prompted to act as a pairwise judge, comparing a preferred response ($y_w$) and a dispreferred response ($y_l$). The authors extract the attention weights from the final verdict token ($y_{verdict}$, e.g., "A" or "B") back to all tokens in both responses. To eliminate positional bias, they run this in two rounds with the response order swapped and average the weights.
- Post-Processing: Because LLMs suffer from "attention sinks" (disproportionately attending to the very first token), the weight of the first token is reset to the sequence average ($1/|y|$). The remaining weights are then normalized to form a proper probability distribution.
- Token-weighted Training: The model is trained using the TwDPO loss function, where the log-probability ratio of each token is scaled by its processed attention weight.
Datasets
- Training: The authors utilized the UltraFeedback binarized dataset (61,135 examples) for the
LLaMA-3-8B-Base-SFTmodel, and a filtered UltraFeedback variant (59,876 examples) scored by PairRM for theLLaMA-3-8B-Instructmodel. - Evaluation: Models were evaluated across three standard instruction-following benchmarks: AlpacaEval (win rate against GPT-4-1106-preview), MT-Bench (LLM-judged quality score), and Arena-Hard (win rate against GPT-4-0314).
Key Insights and Ideas
- The LLM Knows What Matters: When acting as a judge, the model's internal attention mechanism naturally highlights key semantic tokens (such as "True", "Yes", or negation words like "doesn't") rather than arbitrary positions.
- Fixing the Attention Sink is Crucial: Raw attention maps are heavily distorted by attention sinks on initial tokens. Manually correcting the first token's weight to the baseline average prevents the optimization from wasting updates on introductory filler phrases.
- Layer Selection Matters: The authors found that attention weights extracted from the last layer yield the best alignment performance, followed closely by the first layer, while middle layers perform poorly. This aligns with the intuition that the final layer consolidates high-level decision-making features.
- Locally Adaptive Trust Regions: Mathematically, weighting the KL penalty means the model is granted more freedom to deviate from the reference policy on low-importance tokens, while being strictly constrained on high-importance ones to prevent reward hacking.
Key Results
AttentionPO consistently outperformed standard DPO and strong baselines like SimPO across multiple models (LLaMA-3-8B and Mistral-7B variants).
- LLaMA-3-8B-Instruct: AttentionPO achieved a length-controlled win rate of 60.77% on AlpacaEval (vs. 49.02% for DPO) and an MT-Bench score of 7.19 (vs. 6.73 for DPO).
- LLaMA-3-8B-Base-SFT: On Arena-Hard, it achieved a 49.72% win rate, vastly outperforming standard DPO (38.54%).
- No Verbosity Bias: Crucially, analysis showed that the performance boost did not come from making responses longer; AttentionPO's response lengths were comparable to or shorter than baseline methods.
Limitations and Future Work
- Scale: Due to computational constraints, the method was only evaluated on models up to 8B parameters. Testing on larger models (70B+) remains future work.
- Domain Specificity: The evaluation focused strictly on general instruction-following tasks. Its efficacy in specialized domains like mathematical reasoning or code generation needs further exploration.
- Attention Head Selection: The current implementation simply averages attention weights across all heads. Investigating whether specific heads or groups of heads capture better importance metrics is an open research question.
Summary updated