[论文解读] Demystifying Code Summarization Models.
本文提出了HouYi,一种通过分析训练数据中语法和词汇特征的依赖性来解释代码摘要模型的方法。研究发现,Code2Vec、Code2Seq和Sequence GNN等模型严重依赖于表面程序结构,而对语义理解极少,暴露出当前模型可解释性中的一个关键局限。
The last decade has witnessed a rapid advance in machine learning models. While the black-box nature of these systems allows powerful predictions, it cannot be directly explained, posing a threat to the continuing democratization of machine learning technology. Tackling the challenge of model explainability, research has made significant progress in demystifying the image classification models. In the same spirit of these works, this paper studies code summarization models, particularly, given an input program for which a model makes a prediction, our goal is to reveal the key features that the model uses for predicting the label of the program. We realize our approach in HouYi, which we use to evaluate four prominent code summarization models: extreme summarizer, code2vec, code2seq, and sequence GNN. Results show that all models base their predictions on syntactic and lexical properties with little to none semantic implication. Based on this finding, we present a novel approach to explaining the predictions of code summarization models through the lens of training data. Our work opens up this exciting, new direction of studying what models have learned from source code.
研究动机与目标
- 研究代码摘要模型在预测程序摘要时依赖哪些特征。
- 解决代码摘要模型可解释性不足的问题,该问题阻碍了机器学习在软件工程中的信任与普及。
- 开发一种通过训练数据模式视角解释模型预测的方法。
- 评估模型是否学习了语义表征,还是仅利用了语法和词汇线索。
- 开启理解模型真正从源代码中学到了什么的新研究方向。
提出的方法
- HouYi旨在分析单个训练样本对模型预测的贡献。
- 该方法识别并排序对模型输出影响最大的输入标记和结构元素。
- 它利用激活分析和注意力机制,追踪模型各层中特征重要性。
- 该方法评估了四种最先进模型:Extreme Summarizer、Code2Vec、Code2Seq和Sequence GNN。
- HouYi对训练数据执行消融研究,以分离语法、词汇和语义的贡献。
- 该方法通过比较不同程序结构下的模型行为,评估其对特征的依赖程度。
实验结果
研究问题
- RQ1代码摘要模型在预测时主要依赖哪些类型的特征(语法、词汇、语义)?
- RQ2模型在多大程度上使用语义理解,而非源代码的表面模式?
- RQ3不同模型架构(如基于序列的与基于图的)在特征利用上有什么差异?
- RQ4是否能通过分析训练数据模式可靠地解释模型预测?
- RQ5模型的行为揭示了其从源代码中学习过程的哪些信息?
主要发现
- 所有评估的代码摘要模型——Extreme Summarizer、Code2Vec、Code2Seq和Sequence GNN——在预测中主要依赖语法和词汇特征。
- 这些模型表现出极少甚至没有语义理解的证据,表明它们利用的是表面模式而非程序语义。
- HouYi成功识别出主导模型注意力的特定标记和结构模式,证实了预测中的特征偏差。
- 分析表明,模型性能并非由深层代码理解驱动,而是由对语法模板和常见代码短语的记忆所推动。
- 研究结果表明,由于依赖表面特征,当前模型在未见代码结构上的泛化能力较差。
- 本工作为未来模型可解释性研究以及代码模型语义理解能力的评估奠定了基础。
更好的研究,从现在开始
从阅读论文到最终审阅,大幅缩短您的研究时间。
无需绑定信用卡
本解读由 AI 生成,并经人工编辑审核。