arXivDaily arXiv每日学术速递 周一至周五更新
感恩节,周五至周末无更新,大家顺遂。周一再来吧
arXiv 2310.04861cs.LGcs.AIstat.ML
收藏

揭示Transformer中通过解耦位置与上下文的隐藏几何结构

Uncovering hidden geometry in Transformers via disentangling position and context

Beijing Institute for General Artificial Intelligence (BIGAI)(北京通用人工智能研究院);University of Wisconsin–Madison(威斯康星大学麦迪逊分校)

Jiajun Song, Yiqiao Zhong

AI总结:

本文提出一种将Transformer隐藏状态分解为位置、上下文和残差组件的方法,发现位置向量呈低维螺旋结构、上下文向量呈聚类结构且两者近似正交,从而提升模型可解释性。

摘要:

Transformer被广泛用于从输入标记中提取语义信息,然而它们通常作为黑盒模型运行。在本文中,我们提出了一种简单而富有信息量的分解方法,将训练好的Transformer的隐藏状态(或嵌入)分解为可解释的组件。对于任意层,输入序列样本的嵌入向量由张量$\boldsymbol{h} \in \mathbb{R}^{C \times T \times d}$表示。给定在序列(或上下文)$c \le C$中位置$t \le T$处的嵌入向量$\boldsymbol{h}_{c,t} \in \mathbb{R}^d$,提取均值效应得到分解\\[ \boldsymbol{h}_{c,t} = \boldsymbolμ + \mathbf{pos}_t + \mathbf{ctx}_c + \mathbf{resid}_{c,t} \\]其中$\boldsymbolμ$是全局均值向量,$\mathbf{pos}_t$和$\mathbf{ctx}_c$分别是跨上下文和跨位置的均值向量,$\mathbf{resid}_{c,t}$是残差向量。对于流行的Transformer架构和多样的文本数据集,我们经验性地发现了普遍的数学结构:(1)$(\mathbf{pos}_t)_{t}$在层间形成低维、连续且通常呈螺旋形的形状,(2)$(\mathbf{ctx}_c)_c$展现出清晰的聚类结构,可归入上下文主题,(3)$(\mathbf{pos}_t)_{t}$和$(\mathbf{ctx}_c)_c$彼此近似正交。我们认为平滑性在语言训练的Transformer中是普遍且有益的,并且我们的分解提高了模型的可解释性。

英文摘要:

Transformers are widely used to extract semantic meanings from input tokens, yet they usually operate as black-box models. In this paper, we present a simple yet informative decomposition of hidden states (or embeddings) of trained transformers into interpretable components. For any layer, embedding vectors of input sequence samples are represented by a tensor $\boldsymbol{h} \in \mathbb{R}^{C \times T \times d}$. Given embedding vector $\boldsymbol{h}_{c,t} \in \mathbb{R}^d$ at sequence position $t \le T$ in a sequence (or context) $c \le C$, extracting the mean effects yields the decomposition \[ \boldsymbol{h}_{c,t} = \boldsymbolμ + \mathbf{pos}_t + \mathbf{ctx}_c + \mathbf{resid}_{c,t} \] where $\boldsymbolμ$ is the global mean vector, $\mathbf{pos}_t$ and $\mathbf{ctx}_c$ are the mean vectors across contexts and across positions respectively, and $\mathbf{resid}_{c,t}$ is the residual vector. For popular transformer architectures and diverse text datasets, empirically we find pervasive mathematical structure: (1) $(\mathbf{pos}_t)_{t}$ forms a low-dimensional, continuous, and often spiral shape across layers, (2) $(\mathbf{ctx}_c)_c$ shows clear cluster structure that falls into context topics, and (3) $(\mathbf{pos}_t)_{t}$ and $(\mathbf{ctx}_c)_c$ are mutually nearly orthogonal. We argue that smoothness is pervasive and beneficial to transformers trained on languages, and our decomposition leads to improved model interpretability.

机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。

↑