[论文解读] A Closer Look into Transformer-Based Code Intelligence Through Code Transformation: Challenges and Opportunities
本文研究了基于Transformer的代码智能模型在语义保持的代码变换下的鲁棒性。在Java和Python中实施了24–27种变换策略,发现插入/删除和标识符变换对性能的损害最为严重,而基于AST的Transformer模型相比仅基于序列的模型展现出更强的鲁棒性。
Transformer-based models have demonstrated state-of-the-art performance in many intelligent coding tasks such as code comment generation and code completion. Previous studies show that deep learning models are sensitive to the input variations, but few studies have systematically studied the robustness of Transformer under perturbed input code. In this work, we empirically study the effect of semantic-preserving code transformation on the performance of Transformer. Specifically, 24 and 27 code transformation strategies are implemented for two popular programming languages, Java and Python, respectively. For facilitating analysis, the strategies are grouped into five categories: block transformation, insertion/deletion transformation, grammatical statement transformation, grammatical token transformation, and identifier transformation. Experiments on three popular code intelligence tasks, including code completion, code summarization and code search, demonstrate insertion/deletion transformation and identifier transformation show the greatest impact on the performance of Transformer. Our results also suggest that Transformer based on abstract syntax trees (ASTs) shows more robust performance than the model based on only code sequence under most code transformations. Besides, the design of positional encoding can impact the robustness of Transformer under code transformation. Based on our findings, we distill some insights about the challenges and opportunities for Transformer-based code intelligence.
研究动机与目标
- 研究基于Transformer的代码智能模型在语义保持的代码变换下的鲁棒性。
- 识别出对模型性能影响最显著的代码变换策略。
- 比较在代码扰动下基于序列与基于AST的Transformer模型的鲁棒性。
- 分析位置编码设计对模型在代码变换下鲁棒性的影响。
提出的方法
- 为Python设计并实现了27种语义保持的代码变换策略,为Java设计并实现了24种。
- 将变换分为五类:块变换、插入/删除变换、语法语句变换、语法标记变换和标识符变换。
- 在三种代码智能任务上评估模型性能:代码补全、代码摘要和代码搜索。
- 比较两种Transformer架构:一种使用原始代码序列作为输入,另一种使用抽象语法树(AST)作为输入表示。
- 分析不同位置编码设计对模型在代码变换下鲁棒性的影响。
- 使用标准指标(如BLEU、F1、Recall@K)量化在变换输入下的性能退化。
实验结果
研究问题
- RQ1不同类型的语义保持代码变换如何影响基于Transformer的代码智能模型的性能?
- RQ2哪些变换策略对Transformer性能造成最显著的退化?
- RQ3与仅使用原始代码序列相比,使用抽象语法树(AST)作为输入是否能提升Transformer的鲁棒性?
- RQ4位置编码的设计如何影响Transformer在代码变换下的鲁棒性?
主要发现
- 插入/删除变换和标识符重命名对代码补全、摘要和搜索任务中Transformer性能的影响最为显著。
- 基于抽象语法树(AST)的Transformer模型在大多数变换类型下表现出比仅依赖代码序列的模型更强的鲁棒性。
- 位置编码的设计显著影响模型鲁棒性,某些配置在代码扰动下能更好地保持性能。
- 性能退化在代码摘要和代码搜索任务中最明显,极端标识符重命名下BLEU分数最高下降30%。
- 即使通过常见重构模式生成的语义等价代码变体,也会导致模型预测结果截然不同,表明其泛化能力差。
- 本研究揭示,当前最先进的代码智能模型对保留语义的语法变化极为脆弱,凸显了其在鲁棒性方面存在的关键缺陷。
更好的研究,从现在开始
从阅读论文到最终审阅,大幅缩短您的研究时间。
无需绑定信用卡
本解读由 AI 生成,并经人工编辑审核。