[论文解读] A Context-based Automated Approach for Method Name Consistency Checking and Suggestion
本文提出 DeepName,一种上下文感知的深度学习方法,通过利用调用者、被调用者、兄弟方法及封闭类之间的交互,提升方法名一致性检查与建议的性能。通过使用基于 RNN 的子词符序列编码与新颖的复制/非复制机制,DeepName 在包含超过 1400 万个方法的大规模数据集上,将方法名建议的精确率、召回率和 F1 分数提升最高达 38.2%,一致性检查的提升达 19.6%。
Misleading method names in software projects can confuse developers, which may lead to software defects and affect code understandability. In this paper, we present DeepName, a context-based, deep learning approach to detect method name inconsistencies and suggest a proper name for a method. The key departure point is the philosophy of "Show Me Your Friends, I'll Tell You Who You Are". Unlike the state-of-the-art approaches, in addition to the method's body, we also consider the interactions of the current method under study with the other ones including the caller and callee methods, and the sibling methods in the same enclosing class. The sequences of sub-tokens in the program entities' names in the contexts are extracted and used as the input for an RNN-based encoder-decoder to produce the representations for the current method. We modify that RNN model to integrate the copy mechanism and our newly developed component, called the non-copy mechanism, to emphasize on the possibility of a certain sub-token not to be copied to follow the current sub-token in the currently generated method name. We conducted several experiments to evaluate DeepName on large datasets with +14M methods. For consistency checking, DeepName improves the state-of-the-art approach by 2.1%, 19.6%, and 11.9% relatively in recall, precision, and F-score, respectively. For name suggestion, DeepName improves relatively over the state-of-the-art approaches in precision (1.8%--30.5%), recall (8.8%--46.1%), and F-score (5.2%--38.2%). To assess DeepName's usefulness, we detected inconsistent methods and suggested new method names in active projects. Among 50 pull requests, 12 were merged into the main branch. In total, in 30/50 cases, the team members agree that our suggested method names are more meaningful than the current names.
研究动机与目标
- 解决因方法名不一致或具有误导性而影响代码可读性并导致软件缺陷的问题。
- 在不完全依赖方法体的基础上,通过引入调用者、被调用者、兄弟方法及封闭类的上下文信息,改进方法名建议。
- 开发一种深度学习模型,能够生成训练数据中未出现过的全新、有意义的方法名,克服基于检索方法的局限性。
- 通过集成到实际开发工作流中,评估建议名称在真实世界软件项目中的实用性。
提出的方法
- DeepName 从四种上下文中的程序实体提取子词符序列:内部方法体、调用者/被调用者、兄弟方法及封闭类。
- 采用基于 RNN 的编码器-解码器架构,将上下文表征融合为表示目标方法的统一向量。
- 模型引入复制机制以保留上下文中的相关子词符,同时采用新颖的非复制机制在生成名称时抑制无关子词符。
- 使用方法名、参数和返回类型中的子词符作为输入特征,而非 AST 或 PDG 结构,基于先前研究中其表现更优。
- 在最终表征上应用卷积层,以判断给定方法名是否与上下文一致。
- 该方法在包含 1400 万个以上方法的大规模数据集上进行端到端训练,并对一致性检查与名称建议任务进行微调。
实验结果
研究问题
- RQ1在仅依赖方法体之外,结合调用者、被调用者、兄弟方法及封闭类的上下文信息,是否能提升方法名一致性检查的性能?
- RQ2具有子词符级别注意力与复制/非复制机制的深度学习模型,在生成有意义且新颖的方法名方面效果如何?
- RQ3DeepName 在方法名建议与不一致检测任务中,相比现有 SOTA 方法,在精确率、召回率与 F1 分数上的表现提升程度如何?
- RQ4在真实世界软件开发环境中,由人类开发者评估,建议的方法名实际使用价值如何?
主要发现
- 在方法名一致性检查任务中,DeepName 相较于 SOTA 方法,召回率相对提升 2.1%,精确率提升 19.6%,F1 分数提升 11.9%。
- 在方法名建议任务中,DeepName 相较于现有方法,精确率相对提升 1.8% 至 30.5%,召回率提升 8.8% 至 46.1%,F1 分数提升 5.2% 至 38.2%。
- 在真实世界评估中,50 个建议的方法名中有 30 个被团队成员判断为比原始名称更具意义,其中 12 个拉取请求已成功合并至主分支。
- 模型展现出强大的泛化能力,能够生成训练数据中未见过的方法名,表明其在训练数据之外具备有效的零样本泛化能力。
- 非复制机制显著提升了名称质量,降低了生成过程中复制无关子词符的可能性。
- 与基于信息检索的方法相比,DeepName 能生成新颖且上下文恰当的名称,且不受训练集中已有名称的限制。
更好的研究,从现在开始
从阅读论文到最终审阅,大幅缩短您的研究时间。
无需绑定信用卡
本解读由 AI 生成,并经人工编辑审核。