Skip to main content
QUICK REVIEW

[论文解读] Emergent Representations of Program Semantics in Language Models Trained on Programs

Charles Jin, Martin Rinard|arXiv (Cornell University)|May 18, 2023
Software Engineering ResearchComputer Science被引用 9
一句话总结

论文表明仅在程序上进行下一个标记预测训练的语言模型能够发展出对程序语义的线性、有意义的表征,包括未来状态,且语义归因于模型状态而非探针。

ABSTRACT

We present evidence that language models (LMs) of code can learn to represent the formal semantics of programs, despite being trained only to perform next-token prediction. Specifically, we train a Transformer model on a synthetic corpus of programs written in a domain-specific language for navigating 2D grid world environments. Each program in the corpus is preceded by a (partial) specification in the form of several input-output grid world states. Despite providing no further inductive biases, we find that a probing classifier is able to extract increasingly accurate representations of the unobserved, intermediate grid world states from the LM hidden states over the course of training, suggesting the LM acquires an emergent ability to interpret programs in the formal sense. We also develop a novel interventional baseline that enables us to disambiguate what is represented by the LM as opposed to learned by the probe. We anticipate that this technique may be generally applicable to a broad range of semantic probing experiments. In summary, this paper does not propose any new techniques for training LMs of code, but develops an experimental framework for and provides insights into the acquisition and representation of formal semantics in statistical models of code. Our code is available at https://github.com/charlesjin/emergent-semantics.

研究动机与目标

  • 探索仅在程序合成设置下对下一个标记预测进行训练的语言模型是否会产生意义(meaning)。
  • 定义一个精确的语义框架(程序追踪和抽象解释)来测试语言模型表征中的语义编码。
  • 证明语言模型隐藏状态包含对语义状态和未来程序状态的线性编码,与综合准确性相关。
  • 区分语义是存在于模型状态中,还是通过干预实验由探针学习而来。

提出的方法

  • 在具有文本规格(输入-输出示例)的百万个 Karel 程序语料上训练一个 3.5 亿参数的 Transformer(CodeGen 架构)。
  • 通过对每个生成的标记,在部分执行后记录语言模型隐藏状态和相应的程序状态来构建追踪数据集。
  • 训练线性探针以从模型状态预测语义状态(如面向方向),并评估语义内容。
  • 通过另一种语义进行干预来区分模型状态是否编码了语义内容,还是仅仅编码了一个句法性转录。
  • 通过分析程序长度和困惑度,将生成的程序与训练分布进行比较。
  • 使用贪婪解码生成程序并在测试规格上评估生成准确性。
Figure 1 : An overview of the Karel domain. We construct training examples by sampling a random reference program, then sampling 5 random inputs and executing the program to obtain the corresponding 5 outputs. The LM is trained to perform next token prediction on a corpus of examples. At test time,
Figure 1 : An overview of the Karel domain. We construct training examples by sampling a random reference program, then sampling 5 random inputs and executing the program to obtain the corresponding 5 outputs. The LM is trained to perform next token prediction on a corpus of examples. At test time,

实验结果

研究问题

  • RQ1仅在下一个标记预测上训练的语言模型在以程序规格进行训练时能否学习语义?
  • RQ2语言模型隐藏状态是否包含对程序语义的线性、可迁移的表征,包括未来状态?
  • RQ3语义表征是在模型状态中还是由探针学习的?
  • RQ4即使达到高准确性,语言模型输出在语义上是否与训练分布不同?

主要发现

  • 语义内容在训练过程中出现并与生成准确性相关(R^2 = 0.968,p < 0.001)。
  • 探针能够从语言模型状态中提取抽象语义和未来程序状态,表明学习到的意义。
  • 一个干预测试表明语义归因于模型状态而非探针,从而拒绝句法转录假设。
  • 语言模型倾向于生成比训练集更短的正确程序,而训练集程序的困惑度仍然很高,表明与训练分布存在语义差异。
  • 未来状态中的语义内容可以从当前状态预测,与生成进展高度相关(向未来 1–2 步的 R^2 约为 0.9)。
  • 替代语义削弱探针恢复意义的能力,支持模型状态编码原始语义。
Figure 2 : Plotting generative accuracy (blue line) and semantic content (green line) over time. The dotted line at 25% plots the baseline semantic content for random guessing.
Figure 2 : Plotting generative accuracy (blue line) and semantic content (green line) over time. The dotted line at 25% plots the baseline semantic content for random guessing.

阅读本论文

在 Nubint 阅读器中打开原文,边读边就任意段落提问。

在 Nubint 中阅读本论文

本解读由 AI 根据论文原文生成,引用前请核对原文。