[论文解读] SCELMo: Source Code Embeddings from Language Models
SCELMo 在 JavaScript 代码上训练 ELMo 风格的上下文化嵌入,并使用它们来提升 DeepBugs 的缺陷检测性能,超越静态嵌入和非上下文基线。它还分析 OOV 处理和对外部项目的泛化。
Continuous embeddings of tokens in computer programs have been used to support a variety of software development tools, including readability, code search, and program repair. Contextual embeddings are common in natural language processing but have not been previously applied in software engineering. We introduce a new set of deep contextualized word representations for computer programs based on language models. We train a set of embeddings using the ELMo (embeddings from language models) framework of Peters et al (2018). We investigate whether these embeddings are effective when fine-tuned for the downstream task of bug detection. We show that even a low-dimensional embedding trained on a relatively small corpus of programs can improve a state-of-the-art machine learning system for bug detection.
研究动机与目标
- 激发学习源代码的丰富、上下文化表示,以提升软件工程任务。
- 将 ELMo 框架应用于源代码,以创建上下文感知的标记嵌入。
- 评估上下文化的代码嵴是否能在缺陷检测性能上优于静态嵌入。
- 评估对未见项目的泛化能力以及 OOV 令牌的影响。
提出的方法
- 在 JavaScript 代码语料库上训练 ELMo(150k 个文件;筛选为 64,750 个训练文件和 33,229 个验证文件)。
- 使用 esprima 对代码进行分词并应用重复过滤以降低膨胀。
- 每个前向/后向 LSTM 使用 100 维嵌入(每层 200),并以等权重合并层表示(s_j = 1/(L+1), γ = 1)。
- 将 SCELMo 表示整合到 DeepBugs 漏洞检测器中,作为三种错误类型的上下文特征。
- 与 random、Word2Vec、FastText 和 No-Context ELMo 基线进行比较,以评估增益。
- 探讨两种查询变体:固定上下文的 No-Context ELMo 基线,以及针对特定代码结构的完整 SCELMo 上下文嵌入。
实验结果
研究问题
- RQ1SCELMo 上下文嵌入是否能够在 DeepBugs 中提升相对于静态嵌入的缺陷检测准确性?
- RQ2与非上下文方法相比,SCELMo 如何处理 OOV 令牌以及复杂/嵌套表达式?
- RQ3SCELMo 是否对超出训练语料的未见项目具有泛化能力?
- RQ4在真实缺陷挖掘场景中使用上下文嵌入的影响以及实际的误报率?
主要发现
| 错误类型 | Random | Word2Vec | FastText | No-Context ELMo | SCELMo |
|---|---|---|---|---|---|
| 参数交换 | 86.18% | 87.38% | 89.55% | 90.02% | 92.11% |
| 错误二元运算符 | 90.47% | 91.05% | 91.11% | 92.47% | 100.00% |
| 错误二元操作数 | 75.56% | 77.06% | 79.74% | 81.71% | 84.23% |
- SCELMo 在简单表达式和复杂表达式的缺陷检测上显著优于所有静态基线。
- 在包含单名表达式的验证集上,SCELMo 在 Swapped Arguments 上达到 92.11% 对比 86.18% random 与 89.55% Word2Vec;在 Wrong Binary Operator 上 100.00% 对比 90.47% random;在 Wrong Binary Operand 上 84.23% 对比 75.56% random。
- 包括复杂表达式时,SCELMo 仍领先所有基线,在 Swapped Arguments 上 92.27% 对比 86.37% random,在 Wrong Binary Operator 上 100.00% 对比 91.12% random,在 Wrong Binary Operand 上 87.10% 对比 72.73% random。
- 在一个外部测试集(500 个 JavaScript 项目)上,SCELMo 相较静态嵌入有显著提升(例如 Swapped Arguments 84.25% 对 75.79%,Wrong Binary Operator 99.99% 对 82.95%,Wrong Binary Operand 83.59% 对 67.46%)。
- 非上下文的 ELMo 已经超过静态基线,表明预训练和子词处理的价值;SCELMo 能带来最大改进,尤其是对 OOV 令牌和复杂表达式。
- OOV 分析显示基线组件中存在大量 OOV 令牌,凸显 SCELMo 在处理未见标识符和操作数方面的优势。
更好的研究,从现在开始
从论文设计到论文写作,大幅缩短您的研究时间。
无需绑定信用卡
本解读由 AI 生成,并经人工编辑审核。