arXivDaily arXiv每日学术速递 周一至周五更新
arXiv周末暂无论文更新,休息一下吧,周末愉快~~
arXiv 2606.14530cs.LG
收藏

LLM隐藏状态中的代码正确性信号:生成前探测与修复几何

Code Correctness Is Linearly Decodable from LLM Hidden States Before Generation

Independent researcher(独立研究员)

Carlo Di Cicco

AI总结:

本文通过残差化方法,发现Qwen3-4B-Instruct模型在生成前隐藏状态可线性解码代码正确性(AUC 0.931),但修复成功的方向性信号在控制上下文协变量后消失,揭示了方法学上的正负结果。

摘要:

大型语言模型在其隐藏状态中编码丰富信息。本文研究在Qwen3-4B-Instruct-2507生成之前以及修复失败尝试时,代码正确性是否可从隐藏状态中解读,基于444个LiveCodeBench任务。报告两个发现,通过单一混杂控制工具——残差化联系起来。首先,模型首次尝试代码的正确性可从提示最终隐藏状态线性解码,在50个外部分割上无泄漏的留出AUC为0.931±0.008。从每个隐藏状态维度去除提示长度的线性效应后,探针仍达到0.911±0.010,远高于提示长度基线0.754±0.014。其次,在236个清理后的案例中,模型尝试修复失败的首次尝试,从失败尝试到修复的隐藏状态偏移携带统计上可检测的对比方向,在幅度和分割半测试中均显著高于标签打乱的零假设。该方向在对修复上下文协变量(成功与失败修复间不同)进行条件残差化后不再存在,表明它是修复成功的相关因素,由修复上下文驱动,而非孤立的修复理解特征。探针层通过嵌套交叉验证选择,同样的残差化方法支持了生成前正确性结果,却推翻了修复方向解释。贡献既是方法论上的也是实证上的:一个足够诚实的诊断,同时报告了负面结果和正面结果。

英文摘要:

Large language models encode rich information in their hidden states. This work asks whether the correctness of code that Qwen3-4B-Instruct-2507 has not yet generated is already legible in its hidden states, evaluated on a set of 444 tasks from LiveCodeBench. The correctness of the model's first-attempt code is linearly decodable from the hidden state at the final prompt token, captured before any output token is generated, with a leakage-free held-out AUC of 0.881 +/- 0.008 across 50 outer splits. To assess whether this signal is explained by prompt length, each hidden state dimension is residualized with respect to its linear effect. The probe still achieves an AUC of 0.842 +/- 0.010, substantially above a logistic prompt-length baseline of 0.657 +/- 0.014, and none of the nonlinear models tested improves upon it. A companion question about whether self-repair leaves a geometric signature in the model's hidden states could not be answered, because successful repairs following a failed first attempt are too rare in this setting to support the analysis. The contribution is both empirical and methodological, providing evidence that pre-generation hidden states contain a robust signal of eventual code correctness, together with a confound-control diagnostic that quantifies how much of that signal survives adjustment for prompt length.

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

↑