arXivDaily arXiv每日学术速递 周一至周五更新
arXiv 2303.02333cs.PLcs.AI
收藏

揭秘代码摘要模型学到了什么

Demystifying What Code Summarization Models Learned

Nanjing University(南京大学);Visa Research(Visa研究院)

Yu Wang, Ke Wang

摘要:

研究模型学习到的模式一直是模式识别研究的热点。解释从训练数据中发现了什么模式,以及如何将模式推广到看不见的数据,有助于理解和推进模式识别方法。不幸的是,绝大多数应用领域处理连续数据(即统计性质),从中提取的模式不能正式定义。例如,在图像分类中,不存在用于猫或狗的标签的原则定义。即使在自然语言中,单词的含义也会随着它所处的上下文而变化。与前面提到的数据格式不同,程序是一种独特的数据结构,具有定义良好的语法和语义,这为模型从源代码中学习到的内容提供了一个黄金机会。本文提出了第一个形式化的定义模式发现的代码摘要模型(即模型,预测的名称,一个方法的身体),并给出了一个合理的算法来推断一个上下文无关文法(CFG),正式描述学习的模式。我们实现了我们的方法在PATIC产生CFGs总结模式发现的代码摘要模型。特别是,我们选择了两个突出的实例code2vec和code2seq来评估PATIC。PATIC表明,每个模型提取的模式都严重限制于局部和语法代码结构,几乎没有语义含义。基于这些发现,我们提出了两个例子使用的模式的正式定义:一种新的方法来评估的鲁棒性和一种新的技术,用于提高代码摘要模型的准确性。我们的工作开辟了这个令人兴奋的新方向,研究模型从源代码中学到了什么。

英文摘要:

Study patterns that models have learned has long been a focus of pattern recognition research. Explaining what patterns are discovered from training data, and how patterns are generalized to unseen data are instrumental to understanding and advancing the pattern recognition methods. Unfortunately, the vast majority of the application domains deal with continuous data (i.e. statistical in nature) out of which extracted patterns can not be formally defined. For example, in image classification, there does not exist a principle definition for a label of cat or dog. Even in natural language, the meaning of a word can vary with the context it is surrounded by. Unlike the aforementioned data format, programs are a unique data structure with a well-defined syntax and semantics, which creates a golden opportunity to formalize what models have learned from source code. This paper presents the first formal definition of patterns discovered by code summarization models (i.e. models that predict the name of a method given its body), and gives a sound algorithm to infer a context-free grammar (CFG) that formally describes the learned patterns. We realize our approach in PATIC which produces CFGs for summarizing the patterns discovered by code summarization models. In particular, we pick two prominent instances, code2vec and code2seq, to evaluate PATIC. PATIC shows that the patterns extracted by each model are heavily restricted to local, and syntactic code structures with little to none semantic implication. Based on these findings, we present two example uses of the formal definition of patterns: a new method for evaluating the robustness and a new technique for improving the accuracy of code summarization models. Our work opens up this exciting, new direction of studying what models have learned from source code.

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

↑