Artificial Intelligence (AI) and Machine Learning (ML) are pervasive in the current computer science landscape. Yet, there still exists a lack of software engineering experience and best practices in this field. One such best practice, static code analysis, can be used to find code smells, i.e., (potential) defects in the source code, refactoring opportunities, and violations of common coding standards. Our research set out to discover the most prevalent code smells in ML projects. We gathered a dataset of 74 open-source ML projects, installed their dependencies and ran Pylint on them. This resulted in a top 20 of all detected code smells, per category. Manual analysis of these smells mainly showed that code duplication is widespread and that the PEP8 convention for identifier naming style may not always be applicable to ML code due to its resemblance with mathematical notation. More interestingly, however, we found several major obstructions to the maintainability and reproducibility of ML projects, primarily related to the dependency management of Python projects. We also found that Pylint cannot reliably check for correct usage of imported dependencies, including prominent ML libraries such as PyTorch.
翻译:目前在计算机科学领域,人工智能(AI)和机器学习(ML)十分普遍,然而,这方面仍然缺乏软件工程经验和最佳做法。这方面的一种最佳做法,即静态代码分析,可以用来寻找代码气味,即源代码(潜在)缺陷、重构机会和违反共同编码标准。我们的研究旨在发现ML项目中最普遍的代码气味。我们收集了74个开放源代码ML项目数据集,安装了它们的依赖性,并在这些项目上建立了Pylint。这导致每类所有检测到的代码气味达到前20位。对这些气味的手工分析主要表明,代码重复现象十分普遍,而且由于源代码代码与数学符号的相似,PEP8标识命名风格公约可能并非总适用于ML代码。但更有趣的是,我们发现ML项目在维护和可复制性方面存在若干重大障碍,主要与Python项目的依赖性管理有关。我们还发现,Pylint无法可靠地检查进口可靠性的使用情况,包括著名的ML图书馆。