DAPE V2: Process Attention Score as Feature Map for Length Extrapolation

Chuanyang Zheng, Yihang Gao, Han Shi, Jing Xiong, Jiankai Sun, Jingyao Li, Minbin Huang, Xiaozhe Ren, Michael Ng, Xin Jiang, Zhenguo Li, Yu Li

Introduction

Large Language Models (LLMs) face a significant challenge in length extrapolation: performance typically degrades rapidly when processing sequences longer than those encountered during training. While various Positional Encodings (PE) such as RoPE and ALiBi have been developed to mitigate this, they often rely on fixed biases that do not adapt to input content. This paper introduces Convolutional Data-Adaptive Position Encoding (CDAPE), a novel paradigm that treats Transformer attention scores as "feature maps." By applying convolutional operations to these scores, CDAPE enables models to maintain high performance on sequences many times longer than their training context.

Methodology: Attention as a Feature Map

The core innovation of CDAPE lies in conceptualizing the attention score matrix—a 4D tensor of dimensions [Batch, Heads, Query-length, Key-length]—as an image-like feature map.

From MLPs to Convolutions

Building upon the previous Data-Adaptive Position Encoding (DAPE) framework, which utilized Multi-Layer Perceptrons (MLPs), CDAPE employs 1D or 2D convolutions (specifically $1 \times k$ kernels). This shift allows neighboring attention scores across different heads to interact, mimicking the spatial relationship processing found in Computer Vision.

Local Contextualization and Data Adaptivity

By using small convolution kernels (e.g., $1 \times 3$), the model dynamically adjusts pre-softmax attention scores based on local context. Unlike static positional encodings, CDAPE is data-adaptive, modifying attention weights according to the specific input content. Furthermore, the use of zero-padding in convolutions provides implicit positional information, allowing models to function effectively even without explicit positional embeddings (NoPE).

Experimental Results

The researchers evaluated CDAPE across several benchmarks, including the arXiv scientific dataset, Books3, and the FineWeb-Edu corpus.

Length Extrapolation Performance

CDAPE demonstrates remarkable stability in extreme extrapolation scenarios. As shown in Figure 1, when trained on a sequence length of 512, CDAPE variants maintain significantly lower validation perplexity compared to standard RoPE or NoPE baselines as the evaluation length increases to 8,192.

Figure 1: Validation perplexity on the Arxiv dataset for models trained on length 512 and evaluated up to 8,192. CDAPE variants show superior stability.

Synergy with Existing PE Methods

A key strength of CDAPE is its ability to enhance existing positional encoding methods. Figure 5 illustrates the effect of adding CDAPE to ALiBi, Kerple, and FIRE. In the most challenging case—training on a length of 128 and evaluating on 8,192—CDAPE-Kerple achieved a perplexity of 4.60 on arXiv, a dramatic improvement over the baseline Kerple's 12.59.

Figure 5: Comparison of various PE methods (ALiBi, Kerple, FIRE) with and without CDAPE enhancement across different training lengths.

Algorithmic Reasoning and Scaling

On the CHE Benchmark for associative recall, CDAPE improved accuracy on the "Missing Duplicate" task from 87.57% (DAPE) to 99.65%. Scaling experiments on models up to 6.7B parameters indicate that the relative computational overhead of the convolutional layers decreases as model size grows, suggesting high scalability for large-scale production.

Discussion and Limitations

While CDAPE offers significant gains in context handling, it introduces some computational overhead during training and inference. The choice of kernel size is critical; while larger kernels offer more expressiveness, $1 \times 3$ kernels often provide the best balance of performance and stability. Future work may explore more complex kernel geometries, such as square kernels convolving across both Query and Key dimensions, to further enhance the spatial processing of attention scores.

Conclusion

CDAPE represents a shift in how attention mechanisms are designed, moving from simple dot products to spatially-aware feature processing. By treating attention scores as images, CDAPE provides a robust, data-adaptive solution for the long-standing problem of length extrapolation in Transformers.

Summary updated

BibTeX
@inproceedings{zheng2025dape,
  author = {Chuanyang Zheng and Yihang Gao and Han Shi and Jing Xiong and Jiankai Sun and Jingyao Li and Minbin Huang and Xiaozhe Ren and Michael Ng and Xin Jiang and Zhenguo Li and Yu Li},
  title = {{DAPE V2: Process Attention Score as Feature Map for Length Extrapolation}},
  booktitle = {Annual Meeting of the Association for Computational Linguistics},
  year = {2025},
}
Figure