Whodunit: Classifying Code as Human Authored or GPT-4 Generated - A case study on CodeChef problems
Authors/Creators
Description
Artificial intelligence (AI) assistants such as GitHub Copilot and ChatGPT, built on large language models like GPT-4, are revolutionizing how programming tasks are performed, raising questions about whether code is authored by generative AI models. Such questions are of particular interest to educators, who worry that these tools enable a new form of academic dishonesty, in which students submit AI generated code as their own work. Our research explores the viability of using code stylometry and machine learning to distinguish between GPT-4 generated and human-authored code. Our dataset comprises human-authored solutions from CodeChef and AI-authored solutions generated by GPT-4. Our classifier outperforms baselines, with an F1-score and AUC-ROC score of 0.91. A variant of our classifier that excludes gameable features (e.g., empty lines, whitespace) still performs well with an F1-score and AUC-ROC score of 0.89. We also evaluated our classifier with respect to the difficulty of the programming problem and found that there was almost no difference between easier and intermediate problems, and the classifier performed only slightly worse on harder problems. Our study shows that code stylometry is a promising approach for distinguishing between GPT-4 generated code and human-authored code.
# Whodunit: CodeChef AI & Human Solutions Dataset - Replication Package
This repository contains the data for the [CodeChef](https://www.codechef.com/) problems and the code used to collect, extract code-style and code complexity features from it, as well as the code to build and evaluate the classifiers for the paper `Whodunit: Classifying Code as Human Authored or GPT-4 Generated - A case study on CodeChef problems`. It also contains the modified baseline code.
## Data Collection
## Feature Extraction
Before extracting features, comments and multi-line strings must be removed using:
- **`remove_all_comments.ipynb`**: Accepts the `source_directory`, `destination_directory` and `output_file_path` which are the paths to the directory containing the files, the directory to store the files with comments removed and the path to a file that logs information about the file and removal process.
This contains the feature extraction notebooks. Three extraction notebooks generate different feature sets:
-**`extract_main_features.ipynb`**: Generates `rq1_main_features.csv`, `rq3_correct_solutions_features.csv`, `rq3_sampled_solutions_features.csv`, `rq4_easy/medium/hard_problems_features.csv`
- **`extract_with_halstead_features.ipynb`**: Generates `rq1_with_halstead_features.csv`
- **`extract_non_gameable_features.ipynb`**: Generates `rq2_non_gameable_features.csv`
### Features
- `rq1_main_features.csv`: Contains the main classifier's features (`RQ1`).
- `rq1_with_halstead_features.csv`: Contains the halstead features (`RQ1`).
- `rq2_non_gameable_features.csv`: Contains the non-gameable features (`RQ2`).
- `rq3_correct_solutions_features.csv`: Contains the features for solutions that passed the public test cases (`RQ3`).
- `rq3_sampled_solutions_features.csv`: Contains the features for solutions sampled from the unverified set (`RQ3`).
- `rq4_easy_problems_features.csv`: Contains the features for solutions to the easy problems (`RQ4`).
- `rq4_medium_problems_features.csv`: Contains the features for solutions to the intermediate problems (`RQ4`).
- `rq4_hard_problems_features.csv`: Contains the features for solutions to the hard problems (`RQ4`).
## Classification
## For more information, please refer to the `README.md file`
Files
_01_datasets.zip
Files
(28.1 MB)
| Name | Size | Download all |
|---|---|---|
|
md5:9d48858d99d63b4f47e1fec103377ae8
|
27.2 MB | Preview Download |
|
md5:34d13fe2129ad1c8d5e153b8a3040dca
|
14.8 kB | Preview Download |
|
md5:ae4cae0460b58863304048432261109e
|
18.0 kB | Preview Download |
|
md5:a49f7d675923930f90a4c0da8d4c79ae
|
704.4 kB | Preview Download |
|
md5:cfdd2b5a30ee70858c22dca72edd71eb
|
21.3 kB | Preview Download |
|
md5:35e9950abc889e4ec44344aac7a53643
|
15.3 kB | Preview Download |
|
md5:07acdf01b64a50a1f22e37baaec2a776
|
118.0 kB | Preview Download |
|
md5:9cae58de01545478b6fe80dcffdc724b
|
19.1 kB | Preview Download |
|
md5:ba96a176d3f904853c30234b95ca0b4f
|
242 Bytes | Preview Download |