Federated Learning for Software Engineering: A Case Study of Code Clone Detection and Defect Prediction

Authors:
raw_author_name: Yanming Yang
raw_affiliation_string: Department of Computer Science and Technology, Zhejiang University, Ningbo, China
raw_author_name: Xing Hu
raw_affiliation_string: School of Software Technology, Zhejiang University, Ningbo, China
raw_author_name: Zhipeng Gao
raw_affiliation_string: Shanghai Institute for Advanced Study, Zhejiang University, Hangzhou, China
raw_author_name: Jinfu Chen
raw_affiliation_string: School of Computer Science, Wuhan University, Wuhan, China
raw_author_name: Chao Ni
raw_affiliation_string: School of Software Technology, Zhejiang University, Ningbo, China
raw_author_name: Xin Xia
raw_affiliation_string: Software Engineering Application Technology Lab, Huawei, Hangzhou, China
raw_author_name: David Lo
raw_affiliation_string: School of Computing and Information Systems, Singapore Management University, Singapore

Abstract: In various research domains, artificial intelligence (AI) has gained significant prominence, leading to the development of numerous learning-based models in research laboratories, which are evaluated using benchmark datasets. While the models proposed in previous studies may demonstrate satisfactory performance on benchmark datasets, translating academic findings into practical applications for industry practitioners presents challenges. This can entail either the direct adoption of trained academic models into industrial applications, leading to a performance decrease, or retraining models with industrial data, a task often hindered by insufficient data instances or skewed data distributions. Real-world industrial data is typically significantly more intricate than benchmark datasets, frequently exhibiting data-skewing issues, such as label distribution skews and quantity skews. Furthermore, accessing industrial data, particularly source code, can prove challenging for Software Engineering (SE) researchers due to privacy policies. This limitation hinders SE researchers’ ability to gain insights into industry developers’ concerns and subsequently enhance their proposed models. To bridge the divide between academic models and industrial applications, we introduce a federated learning (FL)-based framework called A <sc xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xlink="http://www.w3.org/1999/xlink">lmity</small> . Our aim is to simplify the process of implementing research findings into practical use for both SE researchers and industry developers. A <sc xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xlink="http://www.w3.org/1999/xlink">lmity</small> enhances model performance on sensitive skewed data distributions while ensuring data privacy and security. It introduces an innovative aggregation strategy that takes into account three key attributes: data scale, data balance, and minority class learnability. This strategy is employed to refine model parameters, thereby enhancing model performance on sensitive skewed datasets. <p xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:xlink="http://www.w3.org/1999/xlink">In our evaluation, we employ two well-established SE tasks, i.e., code clone detection and defect prediction, as evaluation tasks. We compare the performance of A<small>lmity</small> on both machine learning (ML) and deep learning (DL) models against two mainstream training methods, specifically the Centralized Training Method (CTM) and Vanilla Federated Learning (VFL), to validate the effectiveness and generalizability of A<small>lmity</small>. Our experimental results demonstrate that our framework is not only feasible but also practical in real-world scenarios. A<small>lmity</small> consistently enhances the performance of learning-based models, outperforming baseline training methods across all types of data distributions.