| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
Authors: Timothy Paek, Chilukuri Mohan (Syracuse University)
This repository contains the code for the research paper "Detection of LLM-Generated Java Code Using Discretized Nested Bigrams." We address the authorship attribution problem for source code, focusing on distinguishing between human-written and LLM-generated Java code fragments. Our approach introduces novel Discretized Nested Bigram Frequency (EWD-NB-F) features, which significantly outperform existing methods by effectively representing sparse Abstract Syntax Tree (AST) information in dense membership bins.
Large Language Models (LLMs) are currently used extensively to generate code by professionals and students, motivating the development of tools to detect LLM-generated code for applications such as academic integrity and cybersecurity. We address this authorship attribution problem as a binary classification task along with feature identification and extraction. We propose new Discretized Nested Bigram Frequency features on source code groups of various sizes. Compared to prior work, improvements are obtained by representing sparse information in dense membership bins. Experimental evaluation demonstrated that our approach significantly outperformed a commonly used GPT code-detection API and baseline features, with accuracy exceeding 96% compared to 72% and 79% respectively in detecting GPT-rewritten Java code fragments for 976 files with GPT 3.5 and GPT 4 using 12 features. We also outperformed three prior works on code author identification in a 40-author dataset. Our approach scales well to larger data sets, and we achieved 99% accuracy and 0.999 AUC for 76,089 files and over 1,000 authors with GPT 4o using 227 features.
Our approach involves two main stages:
Feature Extraction:
Figure 1 from Paper: Feature Extraction Flowchart
[Dataset Directory] -> [Dictionary Creation] -> [Dataset Creation] -> [Normalization] -> [Output Dataset]
Classification:
Two primary datasets were created and used in this research. They are publicly available:
GPT Dataset:
GPT GCJ Dataset:
Additionally, a 40-author dataset from [Yang et al., 2017] was used for comparison in code author identification tasks.
Prerequisites:
Clone the Repository:
git clone <repository-url>
cd <repository-directory>Set up a Virtual Environment (Recommended):
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activateInstall Dependencies: A requirements.txt file can be generated from the imports in the scripts. Key dependencies include:
numpy pandas scikit-learn javalang torch transformers lightgbm xgboost catboost scipy chardet pyclustering kmedoids kneed # For specific experimental scripts: # tensorflow # For ffNN experiments # pyswarms # For PSO experiments # pyod # For kNN anomaly detection experiments # comet_ml # For experiment logging # openai # For MakeGCJDataset.py
Install them using:
pip install numpy pandas scikit-learn javalang torch transformers lightgbm xgboost catboost scipy chardet pyclustering kmedoids kneed
# Optional: pip install tensorflow pyswarms pyod comet_ml openaiAPI Keys (Optional):
# config.py
OPENAI_API_KEY = "your_openai_api_key"The following steps outline how to reproduce the main results from the paper.
The primary script for feature extraction is Testing/MakeDataset.py, which utilizes functions from Code/FeatureExtractionCleaned.py.
Configure Testing/MakeDataset.py:
Run the script:
python Testing/MakeDataset.pyThis will generate CSV files (e.g., GCJ-GPT.EWD.NB.G30.3000.csv) containing the extracted features. These CSVs will be saved in the same directory as the script or a specified output path.
The primary script for training the ensemble models and evaluating them is Testing/Testing.py.
Configure Testing/Testing.py:
Run the script:
python Testing/Testing.pyThe script will output performance metrics (AUC, F1-score, Accuracy, Precision) for each ensemble model and configuration.
Our approach achieves state-of-the-art results:
GPT Dataset (976 files, GPT-3.5/4):
40-Author Dataset (3,021 files, author identification):
GPT GCJ Dataset (76,089 files, GPT-4o, 1k+ authors):
The repository contains additional scripts for various experiments explored during the research:
To run these, inspect the individual scripts for their specific data input requirements and configurations.
If you use this code or our datasets in your research, please cite our paper:
@article{PaekMohan2025LLMJava,
title = {Detection of LLM-Generated {Java} Code Using Discretized Nested Bigrams},
author = {Timothy Paek and Chilukuri Mohan},
year = {2025},
journal = {arXiv preprint arXiv:2502.15740},
eprint = {2502.15740},
archivePrefix = {arXiv},
primaryClass = {cs.SE}
}The first author gratefully acknowledges support from ICCAE and the Renee Crown Honors program at Syracuse University and the Information Technology Services who provided a GPU in April 2024 for the final experiments whose results are reported.
This project is licensed under the MIT License - see the LICENSE.md file for details (assuming MIT, please create this file or choose another license).
| Back | FazBrowse Home | New Git URL |