Bidirectional attention $\unicode{x2013}$ composed of self-attention with positional encodings and the masked language model (MLM) objective $\unicode{x2013}$ has emerged as a key component of modern large language models (LLMs). Despite its empirical success, few studies have examined its statistical underpinnings: What statistical model is bidirectional attention implicitly fitting? What sets it apart from its non-attention predecessors? We explore these questions in this paper. The key observation is that fitting a single-layer single-head bidirectional attention, upon reparameterization, is equivalent to fitting a continuous bag of words (CBOW) model with mixture-of-experts (MoE) weights. Further, bidirectional attention with multiple heads and multiple layers is equivalent to stacked MoEs and a mixture of MoEs, respectively. This statistical viewpoint reveals the distinct use of MoE in bidirectional attention, which aligns with its practical effectiveness in handling heterogeneous data. It also suggests an immediate extension to categorical tabular data, if we view each word location in a sentence as a tabular feature. Across empirical studies, we find that this extension outperforms existing tabular extensions of transformers in out-of-distribution (OOD) generalization. Finally, this statistical perspective of bidirectional attention enables us to theoretically characterize when linear word analogies are present in its word embeddings. These analyses show that bidirectional attention can require much stronger assumptions to exhibit linear word analogies than its non-attention predecessors.
翻译:双向注意力——由带有位置编码的自注意力与掩码语言模型(MLM)目标构成——已成为现代大型语言模型(LLMs)的核心组成部分。尽管其在经验上取得了成功,但鲜有研究探讨其统计基础:双向注意力隐式拟合的是何种统计模型?它与非注意力前身模型有何区别?本文旨在探究这些问题。关键观察在于,通过重参数化,拟合单层单头双向注意力等价于拟合具有混合专家(MoE)权重的连续词袋(CBOW)模型。进一步地,多头多层双向注意力分别等价于堆叠式MoE与混合MoE。这一统计视角揭示了双向注意力中MoE的独特应用方式,与其在处理异质性数据时的实际有效性相吻合。该视角还暗示了向分类表格数据的直接扩展——若将句子中的每个词位置视为表格特征。实证研究发现,该扩展在分布外(OOD)泛化上优于现有的Transformer表格扩展方法。最后,基于双向注意力的统计视角,我们得以从理论上刻画其词嵌入中出现线性词类比的条件。分析表明,与非注意力前身模型相比,双向注意力需要更强的假设才能展现线性词类比现象。