用代码属性图提升机器学习代码异味检测覆盖率
SpecDetect4ML: Detecting Non-Local ML Code Smells with Code Property Graphs
- 基于代码属性图(CPG)实现跨文件、跨控制流的非局部代码异味检测
- 在890个系统中召回率从68.62%提升至88.14%,精度保持90.32%
- 适合关注ML代码可维护性与质量的开发者和团队
机器学习流水线中的代码异味虽不立即引发错误,却会影响可复现性、鲁棒性、效率与可维护性。这些异味常涉及跨函数、导入、控制流和数据流的非局部关系,难以通过传统AST分析发现。我们提出SpecDetect4ML,一种基于代码属性图(CPG)的静态分析工具,以项目级粒度解析22种ML代码异味。在包含超过2000万行代码的890个Python ML系统上评估,相比仅使用抽象语法树(AST)的分析,其召回率从68.62%提升至88.14%,精度保持在90.32%。结果表明,项目级静态推理能显著扩展非局部异味的检测范围,而配置依赖或运行时才显现的异常仍超出源码静态分析范畴。
原文摘要 · Abstract (English)
Machine Learning (ML) pipelines encode quality-relevant decisions across data preparation, training, evaluation, and configuration code. Some recurring source-level quality problems in these pipelines, known as ML code smells, may not cause immediate failures but can harm reproducibility, robustness, efficiency, or maintainability. Detecting ML code smell occurrences is challenging because the decisive evidence is often non-local, spanning helper functions, wrappers, imports, control-flow, and data-flow relations. We present SpecDetect4ML, a static analyser that operationalises 22 ML code smells using CPG views with project-level resolution. We evaluate it on 890 Python ML-based systems comprising more than 20M LOC and a system-level recall benchmark over the complete ML-relevant source subset of 10 selected systems. Under identical ML code smell specifications, CPG-based reasoning raises recall from 68.62\% to 88.14% compared with AST-only analysis, while keeping CPG precision comparable at 90.32%. These results show that project-level static reasoning expands the detectable portion of non-local ML code smell occurrences, while configuration-dependent and runtime-only occurrences remain outside our source-only static claims.
Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。