arXiv:2512.21956cs.CL2025-12被引 3

通过向量相似性揭示BERT注意力机制如何关注文本语义。

Self-attention vector output similarities reveal how machines pay attention

  • 用注意力头间向量相似度量化信息处理过程。
  • 后期层注意力聚焦句间分隔符,支持语义分段。
  • 不同注意力头专注不同语言特征,如重复词或上下文共现。

自注意力机制显著推动了自然语言处理的发展,但其内部学习机制及量化表征仍不明确。本研究提出新方法,基于BERT-12架构分析自注意力头中向量空间的相似性。结果显示,最终层注意力集中于句子分隔符,暗示一种基于语义特征的文本分割策略。通过计算注意力头内词元向量间的标量积,构建上下文相似性矩阵,发现各头在不同层次对特定语言特征具有专属性:有的关注重复词,有的识别高频词及其上下文。初始层呈现长距离相似性,随层数加深,相似性转为短程,最终偏好同句内强相似性。进一步分析表明,每头均聚焦文本中一个独特高频词,并围绕其建立相似对。

原文摘要 · Abstract (English)

The self-attention mechanism has significantly advanced the field of natural language processing, facilitating the development of advanced language-learning machines. Although its utility is widely acknowledged, the precise mechanisms of self-attention underlying its advanced learning and the quantitative characterization of this learning process remains an open research question. This study introduces a new approach for quantifying information processing within the self-attention mechanism. The analysis conducted on the BERT-12 architecture reveals that, in the final layers, the attention map focuses on sentence separator tokens, suggesting a practical approach to text segmentation based on semantic features. Based on the vector space emerging from the self-attention heads, a context similarity matrix, measuring the scalar product between two token vectors was derived, revealing distinct similarities between different token vector pairs within each head and layer. The findings demonstrated that different attention heads within an attention block focused on different linguistic characteristics, such as identifying token repetitions in a given text or recognizing a token of common appearance in the text and its surrounding context. This specialization is also reflected in the distribution of distances between token vectors with high similarity as the architecture progresses. The initial attention layers exhibit substantially long-range similarities; however, as the layers progress, a more short-range similarity develops, culminating in a preference for attention heads to create strong similarities within the same sentence. Finally, the behavior of individual heads was analyzed by examining the uniqueness of their most common tokens in their high similarity elements. Each head tends to focus on a unique token from the text and builds similarity pairs centered around it.

自注意力BERT语义分析

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。