Large Language Models excel at code generation but struggle with code quality analysis, where best practices evolve and cannot be fully captured by static training data. We introduce MetaLint, a training framework that treats code quality analysis as detecting best practice violations from high-level specifications over semantic code fragments (code idioms). Instead of training on a fixed set of rules, MetaLint reorganizes supervision around dynamically specified best practices using synthetic linter-derived labels, integrated with instruction-following and preference optimization. This encourages extrapolation to more complex, unseen best practices at test time, consistent with easy-to-hard generalization without retraining. To evaluate MetaLint, we create a new benchmark of hard-to-detect best practices inspired by Python Enhancement Proposals. Across this benchmark, MetaLint improves generalization to unseen best practices. Qwen3-4B achieves a 2.7x detection F-score gain (25.9% -> 70.4%), the highest recall, and a 26.7% localization F-score, matching larger models such as o3-mini. These gains generalize across programming languages, model families, scales, reasoning settings, and linter sources.


翻译:大型语言模型在代码生成方面表现出色,但在代码质量分析方面存在困难,因为最佳实践不断演变且无法完全由静态训练数据捕获。我们提出了MetaLint,这是一个将代码质量分析视为从语义代码片段(代码惯用法)的高级规范中检测最佳实践违规的训练框架。MetaLint并非基于固定规则集进行训练,而是通过合成代码检查器生成的标签,围绕动态指定的最佳实践重组监督信号,并将其与指令遵循和偏好优化相结合。这鼓励模型在测试时对更复杂、未见的最佳实践进行外推,符合无需重新训练的由易到难泛化原则。为评估MetaLint,我们创建了一个受Python增强提案启发、包含难以检测最佳实践的新基准。在该基准测试中,MetaLint显著提升了对未见最佳实践的泛化能力。Qwen3-4B模型实现了2.7倍的检测F值提升(25.9% → 70.4%),达到最高召回率及26.7%的定位F值,其性能与o3-mini等更大模型相当。这些性能提升在不同编程语言、模型家族、模型规模、推理设置和代码检查器来源中均具有泛化性。

0
下载
关闭预览

相关内容

代码(Code)是专知网的一个重要知识资料文档板块,旨在整理收录论文源代码、复现代码,经典工程代码等,便于用户查阅下载使用。
【NeurIPS2024】训练计算最优的蛋白质语言模型
专知会员服务
9+阅读 · 2024年11月8日
TextInfoExp:自然语言处理相关实验(基于sougou数据集)
全球人工智能
12+阅读 · 2017年11月12日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
国家自然科学基金
3+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
国家自然科学基金
1+阅读 · 2014年12月31日
VIP会员
相关VIP内容
【NeurIPS2024】训练计算最优的蛋白质语言模型
专知会员服务
9+阅读 · 2024年11月8日
相关基金
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
1+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2015年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
国家自然科学基金
3+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
国家自然科学基金
0+阅读 · 2014年12月31日
国家自然科学基金
1+阅读 · 2014年12月31日
Top
微信扫码咨询专知VIP会员