神经变量名修复:学习为可读性重命名标识符
Neural Variable Name Repair: Learning to Rename Identifiers for Readability
AI总结:
本文提出神经变量名修复方法,通过微调和重排技术提升代码可读性,实验显示其在精确匹配和部分相似度评分上显著优于基线模型。
摘要:
开发人员经常处理变量名通用或误导性的源文件,并且在团队快速移动时,许多函数被遗弃未记录。这会减慢理解速度,增加微妙bug的风险,并使人类和大型语言模型(LLMs)难以推理代码。我们研究了变量名修复:给定一个真实的C++函数,其中所有局部或参数名的出现已被替换为占位符(例如ID 1),目标是生成一个自然、描述性的替代名称。我们自动从BigCode的The Stack的C++部分构建此任务,通过Tree-sitter解析函数,屏蔽单个标识符,并将原始名称作为监督。在Llama 3.1-8B之上,我们构建了包含(i)更稳定的微调的预热和丢弃计划,(ii)用于标识符修复的LoRA适配器,以及(iii)在top-k生成候选者上的双编码重排器的流程。我们通过精确匹配、Top-5命中和基于嵌入的部分相似度分数(0-100)进行评估,后者为近义词和格式变体(例如jsonValue vs. json)提供信用。在200个C++函数的预留集上,零样本Llama 3.1基线达到6.1%的精确匹配。我们最好的LoRA微调模型(带有预热和丢弃)达到43.1%的精确匹配,50.2%的Top-5命中,以及82.03分的部分匹配分数。双编码重排器进一步提高选择质量而不修改底层生成器,表明任务特定微调加重排是实用标识符修复工具的有希望的方法。
英文摘要:
Developers routinely work with source files whose variable names are generic or misleading, and with teams moving quickly, many functions are left undocumented. This slows comprehension, increases the risk of subtle bugs, and makes it harder for both humans and large language models (LLMs) to reason about code. We study variable name repair: given a real C++ function where all occurrences of one local or parameter name have been replaced by a placeholder (e.g. ID 1), the goal is to generate a natural, descriptive replacement name. We automatically construct this task from the C++ portion of BigCode's The Stack by parsing functions with Tree-sitter, masking a single identifier, and treating the original name as supervision. On top of Llama 3.1-8B, we build a pipeline with (i) warmup and dropout schedules for more stable fine-tuning, (ii) LoRA adapters for efficient specialization on identifier repair, and (iii) a dual-encoder reranker over top-k generator candidates. We evaluate using exact match, Top-5 Hit, and an embedding-based partial similarity score (0-100) that gives credit for near synonyms and format variants (e.g., jsonValue vs. json). On a held-out set of 200 C++ functions, a zero-shot Llama 3.1 baseline reaches 6.1 percent exact match. Our best LoRA-tuned model (with warmup and dropout) achieves 43.1 percent exact match, 50.2 percent Top-5 Hit, and an 82.03 partial-match score. A dual encoder reranker further improves selection quality without modifying the underlying generator, suggesting that task-specific fine-tuning plus reranking is a promising approach for practical identifier repair tools.
机构、总结、中文摘要均由AI分析而来,可能存在错误,请以论文正文为准。