[论文解读] Evaluating Semantic Representations of Source Code
本文提出了IdBench,一个基于500名开发人员评分的基准,用于评估源代码标识符的语义表示。研究发现,尽管顶级嵌入模型在捕捉语义相关性方面表现尚可,但没有一种模型能充分表示语义相似性,常常将语义相反的标识符误判为相似,这可能在下游工具中引发错误。
Learned representations of source code enable various software developer tools, e.g., to detect bugs or to predict program properties. At the core of code representations often are word embeddings of identifier names in source code, because identifiers account for the majority of source code vocabulary and convey important semantic information. Unfortunately, there currently is no generally accepted way of evaluating the quality of word embeddings of identifiers, and current evaluations are biased toward specific downstream tasks. This paper presents IdBench, the first benchmark for evaluating to what extent word embeddings of identifiers represent semantic relatedness and similarity. The benchmark is based on thousands of ratings gathered by surveying 500 software developers. We use IdBench to evaluate state-of-the-art embedding techniques proposed for natural language, an embedding technique specifically designed for source code, and lexical string distance functions, as these are often used in current developer tools. Our results show that the effectiveness of embeddings varies significantly across different embedding techniques and that the best available embeddings successfully represent semantic relatedness. On the downside, no existing embedding provides a satisfactory representation of semantic similarities, e.g., because embeddings consider identifiers with opposing meanings as similar, which may lead to fatal mistakes in downstream developer tools. IdBench provides a gold standard to guide the development of novel embeddings that address the current limitations.
研究动机与目标
- 解决代码标识符嵌入缺乏标准化、无偏见评估框架的问题。
- 衡量现有嵌入技术在源代码中表示语义相关性和相似性的能力。
- 识别当前嵌入模型的局限性,特别是其将语义相反的标识符视为相似的倾向。
- 提供一个金标准基准,以指导未来更优代码嵌入的开发。
提出的方法
- 从500名软件开发人员处收集数千对标识符在语义相关性和相似性方面的评分。
- 设计IdBench作为大规模、人工标注的基准,用于评估代码嵌入。
- 在该基准上评估最先进的自然语言嵌入、专用代码嵌入以及词法字符串距离函数。
- 使用基于相关性的度量方法,将嵌入相似性得分与人工标注的评分进行比较。
- 分析嵌入输出与人工判断之间的差异,以识别系统性失败。
实验结果
研究问题
- RQ1现有代码标识符嵌入在人类开发人员判断下,对语义相关性的表示能力如何?
- RQ2嵌入技术在区分语义相反标识符方面失败的程度有多大?
- RQ3专用代码嵌入与通用自然语言嵌入相比,在捕捉代码语义方面表现如何?
- RQ4词法字符串距离函数在表示语义相似性方面,与学习得到的嵌入相比表现如何?
主要发现
- 表现最佳的嵌入模型在语义相关性上与人工判断达到中等程度的相关性,但在相似性任务上均未达到高准确率。
- 许多嵌入模型错误地将语义相反的标识符视为语义相似,可能对下游工具造成风险。
- 专用代码嵌入在捕捉代码语义方面优于通用自然语言嵌入,但仍存在显著局限性。
- 与学习得到的嵌入相比,词法字符串距离函数表现较差,尤其在语义相似性任务上。
- 该基准揭示了当前嵌入模型中的系统性偏差,特别是在处理语义相反情况时。
更好的研究,从现在开始
从阅读论文到最终审阅,大幅缩短您的研究时间。
无需绑定信用卡
本解读由 AI 生成,并经人工编辑审核。