[Paper Review] CGEMs: A Metric Model for Automatic Code Generation using GPT-3
This paper proposes CGEMs, a metric model that evaluates GPT-3-generated code using a combination of compilation checks, natural language to logic conversion, edit count, static code metrics, and NLP-based features. A neural network classifier trained on these metrics achieves 76.92% accuracy and 55.56% F1 score in distinguishing acceptable from unacceptable code, with interpretability enhanced via XAI techniques.
Today, AI technology is showing its strengths in almost every industry and walks of life. From text generation, text summarization, chatbots, NLP is being used widely. One such paradigm is automatic code generation. An AI could be generating anything; hence the output space is unconstrained. A self-driving car is driven for 100 million miles to validate its safety, but tests cannot be written to monitor and cover an unconstrained space. One of the solutions to validate AI-generated content is to constrain the problem and convert it from abstract to realistic, and this can be accomplished by either validating the unconstrained algorithm using theoretical proofs or by using Monte-Carlo simulation methods. In this case, we use the latter approach to test/validate a statistically significant number of samples. This hypothesis of validating the AI-generated code is the main motive of this work and to know if AI-generated code is reliable, a metric model CGEMs is proposed. This is an extremely challenging task as programs can have different logic with different naming conventions, but the metrics must capture the structure and logic of the program. This is similar to the importance grammar carries in AI-based text generation, Q&A, translations, etc. The various metrics that are garnered in this work to support the evaluation of generated code are as follows: Compilation, NL description to logic conversion, number of edits needed, some of the commonly used static-code metrics and NLP metrics. These metrics are applied to 80 codes generated using OpenAI's GPT-3. Post which a Neural network is designed for binary classification (acceptable/not acceptable quality of the generated code). The inputs to this network are the values of the features obtained from the metrics. The model achieves a classification accuracy of 76.92% and an F1 score of 55.56%. XAI is augmented for model interpretability.
Motivation & Objective
- To address the challenge of validating AI-generated code in an unconstrained output space.
- To develop a reliable, automated metric-based evaluation framework for code generated by large language models like GPT-3.
- To identify and quantify key features—such as compilation success, logic fidelity, edit count, and code structure—that reflect code quality.
- To design a binary classification model that predicts whether GPT-3-generated code is acceptable or not based on measurable metrics.
- To enhance model interpretability using Explainable AI (XAI) techniques for transparency in code quality assessment.
Proposed method
- The framework collects 80 GPT-3-generated code samples and applies a suite of evaluation metrics: compilation success, natural language to logic conversion accuracy, number of edits required, standard static code metrics (e.g., cyclomatic complexity), and NLP-based metrics.
- Each code sample is scored across these metrics, forming a feature vector for model input.
- A feedforward neural network is trained for binary classification (acceptable vs. not acceptable code) using the metric-derived features.
- The model is optimized for classification performance, with evaluation metrics including accuracy and F1 score.
- XAI techniques are applied to interpret the model’s predictions and identify which features most influence the classification outcome.
Experimental results
Research questions
- RQ1Can a hybrid set of compilation, static code, and NLP metrics effectively assess the quality of GPT-3-generated code?
- RQ2How well can a neural network classifier distinguish between acceptable and unacceptable code based on these metrics?
- RQ3Which individual metrics contribute most significantly to the classification of code quality?
- RQ4To what extent can XAI techniques improve the interpretability of the code quality assessment model?
- RQ5Is the proposed metric model robust enough to handle variations in logic and naming conventions across generated code?
Key findings
- The CGEMs model achieved a classification accuracy of 76.92% on the test set of 80 GPT-3-generated code samples.
- The F1 score for the binary classification task was 55.56%, indicating moderate balance between precision and recall.
- Compilation success and edit count emerged as strong indicators of code quality, reflecting functional correctness and maintainability.
- NLP-based metrics, particularly those measuring alignment between natural language prompts and code logic, contributed meaningfully to the model’s predictive power.
- XAI analysis revealed that logic fidelity and code structure metrics were among the most influential features in the model’s decision-making process.
- The results demonstrate that a metric-driven, data-driven approach can provide a statistically valid and interpretable method for evaluating AI-generated code.
Read this paper
Open the full text in the Nubint reader and ask about any passage as you read.
Read this paper on NubintThis review was generated by AI from the original paper. Please check the paper before citing it.