Code Compliance Assessment as a Learning Problem
Authors:
- 1 May 2023
- conference paper
- Published by Institute of Electrical and Electronics Engineers (IEEE)
- p. 445-454
Abstract
Manual code reviews and static code analyzers are the traditional mechanisms to verify if source code complies with coding policies. However, they are hard to scale. We formulate code compliance assessment as a machine learning (ML) problem, to take as input a natural language policy and code, and generate a prediction on the code’s compliance, non-compliance, or irrelevance. Our intention for ML-based automation is to scale the development of Amazon CodeGuru, a commercial code analyzer. We explore key research questions on model formulation, training data, and evaluation setup. We obtain a joint code-text representation space (embeddings) which preserves compliance relationships via the vector distance of code and policy embeddings. As there is no task-specific data, we re-interpret and filter commonly available software datasets with additional pre-training and pre-finetuning tasks that reduce the semantic gap. We benchmarked our approach on two listings of coding policies (CWE and CBP). This is a zero-shot evaluation as none of the policies occur in the training set. On CWE and CBP respectively, our tool Policy2Code achieves classification accuracies of (59%, 71%) and search MRR of (0.05, 0.21) compared to CodeBERT with classification accuracies of (37%, 54%) and MRR of (0.02, 0.02). In a user study, 24% Policy2Code detections were accepted compared to 7% for CodeBERT. Policy2Code is considered a useful ML-based aid to supplement manual efforts.Keywords
All Related Versions
This publication has 30 references indexed in Scilit:
- DeepBugs: a learning approach to name-based bug detectionProceedings of the ACM on Programming Languages, 2018
- Retrieval on source code: a neural code search2018
- Deep code search2018
- Conditional Similarity Networks2017
- Beyond Triplet Loss: A Deep Quadruplet Network for Person Re-identification2017
- SWIM2016
- CodeHow: Effective Code Search Based on API Understanding and Extended Boolean Model (E)2015
- PortfolioACM Transactions on Software Engineering and Methodology, 2013
- Sourcerer: mining and searching internet-scale software repositoriesData Mining and Knowledge Discovery, 2008
- Beyond basic faceted search2008