Transformer-based language models (LMs) are known to capture factual knowledge in their parameters. While previous work looked into where factual associations are stored, only little is known about how they are retrieved internally during inference. We investigate this question through the lens of information flow. Given a subject-relation query, we study how the model aggregates information about the subject and relation to predict the correct attribute. With interventions on attention edges, we first identify two critical points where information propagates to the prediction: one from the relation positions followed by another from the subject positions. Next, by analyzing the information at these points, we unveil a three-step internal mechanism for attribute extraction. First, the representation at the last-subject position goes through an enrichment process, driven by the early MLP sublayers, to encode many subject-related attributes. Second, information from the relation propagates to the prediction. Third, the prediction representation "queries" the enriched subject to extract the attribute. Perhaps surprisingly, this extraction is typically done via attention heads, which often encode subject-attribute mappings in their parameters. Overall, our findings introduce a comprehensive view of how factual associations are stored and extracted internally in LMs, facilitating future research on knowledge localization and editing.
翻译:基于Transformer的语言模型已知能够在其参数中捕获事实知识。尽管先前研究关注了事实关联的存储位置,但关于推理过程中这些关联如何在模型内部被检索的认知仍十分有限。我们通过信息流的视角探究这一问题。针对给定的主体-关系查询,我们研究模型如何整合关于主体和关系的信息以预测正确的属性。通过注意力边界的干预实验,我们首先识别出信息传播至预测结果的两个关键节点:一个来自关系位置,随后来自主体位置。接着,通过分析这些节点处的信息,我们揭示了属性提取的三步内部机制:首先,最后一个主体位置的表征通过早期MLP子层的驱动经历富集过程,编码多个与主体相关的属性;其次,关系信息传播至预测结果;最后,预测结果表征通过"查询"富集后的主体表征来提取属性。令人惊讶的是,这种提取通常通过注意力头完成,这些注意力头的参数中往往编码了主体-属性的映射关系。总体而言,我们的发现提出了事实关联在语言模型内部存储与提取机制的综合视角,为知识定位与编辑的未来研究提供了新方向。