TLDR: A new static code analysis tool, MLpylint, has been developed to automatically identify and evaluate machine learning (ML)-specific code smells in Python applications. The tool was rigorously tested on 160 open-source ML projects, demonstrating its efficiency in processing large codebases and its high precision in detecting common ML code issues like uncontrolled randomness. Feedback from ML professionals confirmed MLpylint’s usefulness in improving software quality and reducing the effort required to identify and address these unique technical debts in ML development.
In the rapidly evolving world of machine learning (ML), ensuring the quality and maintainability of software applications is paramount. While traditional software development has long grappled with ‘code smells’ – patterns in code that suggest deeper problems – the unique complexities of ML applications introduce their own set of challenges, often leading to hidden technical debt.
A recent research paper, titled Automatic Identification of Machine Learning-Specific Code Smells, addresses this critical gap. Authored by Peter Hamfelt, Ricardo Britto, Lincoln Rocha, and Camilo Almendra, the study introduces MLpylint, a novel static code analysis tool designed specifically to detect ML-specific code smells in Python-based applications.
The Challenge of ML Code Quality
Traditional static analysis tools, while effective for general software, often fall short when it comes to the nuances of machine learning code. ML applications frequently involve complex data pipelines, external libraries like TensorFlow and PyTorch, and unique development practices that can introduce subtle yet significant code quality issues. These issues, if left unaddressed, can lead to decreased maintainability, reproducibility, and overall software quality.
Introducing MLpylint: A Tailored Solution
MLpylint was developed using a rigorous Design Science Methodology, involving extensive literature reviews to identify ML-specific code smells and consultations with experts from the Python Code Quality Authority (PyCQA). The tool leverages Astroid, a Python library for abstract syntax tree (AST) parsing, to analyze Python code without execution, making it a static analysis solution.
The researchers categorized detected issues into two types:
- Code Smells: These are clear, unambiguous patterns directly identifiable in the code, such as not explicitly setting required keywords in a function call.
- Code Smell Advice: These are broader, potential issues that hint at problems but require a developer’s deeper analysis to confirm, like potential memory leakage.
Out of 22 ML-specific code smells previously cataloged by Zhang et al., MLpylint was designed to detect 20, classifying 14 as direct code smells and 6 as advice.
Evaluating MLpylint’s Performance and Usefulness
To assess its effectiveness, MLpylint was put to the test on 160 open-source ML application projects from GitHub. This extensive dataset comprised over 10 million lines of Python code. The tool demonstrated impressive efficiency, processing all projects in just under 36 minutes and identifying a total of 5,380 code smells.
The evaluation revealed a high precision rate: 100% for direct Code Smells and 73.6% for Code Smell Advice, resulting in an overall precision of 87.9%. The most frequently detected issues included ‘Randomness Uncontrolled’ (CS14), highlighting a common challenge in ensuring reproducibility in ML projects, and ‘Memory Not Freed’ (CSA12) and ‘Data Leakage’ (CSA21) as common areas for advice.
Beyond technical performance, the researchers gathered feedback from 15 experienced ML professionals at Ericsson. The survey results were overwhelmingly positive, with participants finding MLpylint user-friendly, effective in identifying ML-specific code smells, and reliable. Crucially, a significant majority agreed that the tool helps reduce the time and effort required to identify these issues, confirming its practical value in real-world development workflows.
Also Read:
- AI Agents Reshaping Software Development
- Meta-RAG: A New AI Approach for Pinpointing Bugs in Massive Codebases
Future Directions
The study concludes that MLpylint successfully contributes to reducing technical debt and enhancing the maintainability of ML software. The authors acknowledge areas for future improvement, such as broadening its analytical scope, increasing support for more ML libraries, and refining its accuracy, particularly for code smell advice. There’s also an ongoing initiative to integrate MLpylint as a plugin for Pylint, a widely used Python linter, to further extend its reach and impact within the ML development community.


