双三角注意:无需位置嵌入的有效双向注意
Dual Triangle Attention: Effective Bidirectional Attention Without Positional Embeddings
AI总结:
本文提出双三角注意机制,通过分离每个注意力头的查询-键子空间为两个互补的三角掩码,实现双向上下文处理,同时保持位置隐含偏置。在合成argmax任务和MLM实验中表现优异。
摘要:
双向变换器是许多序列建模任务的基础,但它们在没有显式位置嵌入的情况下是排列不变的。相比之下,单向注意通过三角掩码隐含编码位置信息,使模型无需位置嵌入。本文提出双三角注意,将每个注意力头的查询-键子空间分为两个互补的三角掩码:一个关注过去和自身位置,另一个关注未来和自身位置。此设计在双向上下文中保持因果掩码的隐含位置归纳偏置。使用PyTorch的flex_attention,双三角注意作为单个编译内核调用实现,无需额外参数。在三个设置中评估:(1) 合成argmax位置探针,(2) 自然语言的掩码语言建模(MLM),(3) 蛋白质序列的MLM。在argmax任务中,双三角注意和因果注意在无显式位置嵌入的情况下学习位置信息,而标准双向注意无法做到。在MLM实验中,双三角注意结合旋转位置嵌入(RoPE)在上下文扩展性能和整体表现上最佳。这些发现表明,双三角注意是双向变换器的有效注意机制,无论是否使用位置嵌入。
英文摘要:
Bidirectional transformers are the foundation of many sequence modeling tasks across natural, biological, and chemical language domains, but they are permutation-invariant without explicit positional embeddings. In contrast, unidirectional attention inherently encodes positional information through its triangular mask, enabling models to operate without positional embeddings altogether. Here, we introduce Dual Triangle Attention, a novel bidirectional attention mechanism that separates the query-key subspace of each attention head into two complementary triangular masks: one that attends to past-and-self positions and one that attends to future-and-self positions. This design provides bidirectional context while maintaining the causal mask's implicit positional inductive bias in both directions. Using PyTorch's flex_attention, Dual Triangle Attention is implemented as a single compiled kernel call with no additional parameters beyond standard multi-head attention. We evaluated Dual Triangle Attention across three settings: (1) a synthetic argmax position probe, (2) masked language modeling (MLM) on natural language, and (3) MLM on protein sequences. In the argmax task, both Dual Triangle Attention and causal attention learn positional information without explicit positional embeddings, whereas standard bidirectional attention cannot. In the MLM experiments, Dual Triangle Attention with Rotary Positional Embeddings (RoPE) achieved the best context extension performance and strong performance across the board. These findings suggest that Dual Triangle Attention is a viable attention mechanism for bidirectional transformers, with or without positional embeddings.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。