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

语义冲突的机制视角:使用激活修补来理解大语言模型行为

A Mechanistic Lens on Semantic Conflicts: Using Activation Patching to Understand LLM Behavior

Saarland Informatics Campus, Saarland University(萨尔兰信息学院,萨尔兰大学)

Youssef Abdelsalam, Norman Peitek, Anna-Maria Maurer, Marvin Wyrich, Sven Apel

AI总结:

研究大语言模型在语义冲突下的行为,构建Python代码片段三元组,用行为性能度量和残差流激活修补评估四个LLMs在输出预测和单元测试生成任务中的表现,发现语义冲突影响任务且相关信息集中,展示分析LLMs整合代码信息的框架。

摘要:

大语言模型(LLMs)越来越多地用于软件工程任务,处理可执行代码和非可执行语义线索(如注释或标识符)。当语义线索暗示的程序行为与代码本身不同时,这两个来源可能会冲突。目前尚不清楚这种语义冲突如何影响LLM行为以及哪个来源主导其输出。我们首次对语义冲突下的LLM行为进行了可控的机制研究。为此,我们构建了45个Python代码片段三元组,通过改变语义线索或实现来隔离冲突,同时保持令牌对齐对进行因果干预。我们使用行为性能度量和残差流激活修补来评估四个开放权重的LLMs在两个任务(输出预测和单元测试生成)上的表现,以识别对对齐和冲突输入之间行为差异有因果贡献的令牌层状态。我们的结果表明,语义冲突在两个任务中都显著降低了基于执行的正确性,并且所有测试的LLMs经常遵循误导性的语义线索。残差流激活修补揭示了最终输出预测的一致模式:在输出读出附近聚合之前,变化的线索/代码区域和一小部分中间令牌携带了大部分可恢复的因果信号。对于单元测试生成,这种模式超出了提示范围,表明在生成预期值之前,在生成站点可以恢复与冲突相关的信息。总体而言,我们的发现表明语义冲突会影响程序理解和下游任务,相关信息集中在少数因果活跃的残差流状态中,并展示了一个框架,用于在可控语义变化下机械地分析LLMs如何整合与代码相关的信息。

英文摘要:

Large language models (LLMs) are increasingly used in software-engineering tasks processing executable code and non-executable semantic cues such as comments or identifiers. These two sources can conflict when semantic cues suggest different program behavior than the code itself. It remains unclear how such semantic conflicts affect LLM behavior and which source dominates their outputs. We present the first controlled, mechanistic study of LLM behavior under semantic conflicts. To this end, we construct 45 Python snippet triplets that isolate conflicts by varying either semantic cues or implementation while keeping token-aligned pairs for causal intervention. We evaluate four open-weight LLMs on two tasks (output prediction and unit-test generation) using behavioral performance measures and residual-stream activation patching to identify token-layer states that causally contribute to behavioral differences between aligned and conflicting inputs. Our results show that semantic conflicts significantly reduce execution-grounded correctness in both tasks and that all tested LLMs often follow misleading semantic cues. Residual-stream activation patching reveals a consistent pattern for final-output prediction: The changed cue/code region and a small set of intermediate tokens carry most of the recoverable causal signal before aggregation near the output readout. For unit-test generation, this pattern extends beyond the prompt, showing that conflict-related information is recoverable at generated sites before producing expected values. Overall, our findings show that semantic conflicts affect program comprehension and downstream tasks, with relevant information concentrated in a small number of causally active residual-stream states, and demonstrate a framework for mechanistically analyzing how LLMs integrate code-related information under controlled semantic variations.

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

↑