Skip to main content

AI Code Detection Tool

Reason this release was yanked:

Superseded by v0.1.1 which removes unnecessary dependencies

Project description

Aegis: AI Python Code Detection Model

Overview

Aegis is a fine-tuned CodeBERT model that classifies AI-generated and human code. CodeBERT has 125 million parameters, but using LoRA (Low-Rank Adaptation), Aegis was efficiently trained locally with only a subset of the original parameters being updated. This project sprouted out of my curiosity of classifying AI and human code off semantic differences. Hence, the dataset (20K samples: 10K AI + 10K Human) was aggressively cleaned to ensure standard formatting and the removal of comments and docstrings. The threshold was set to 0.7 to suggest that were is enough evidence to "pass" the code sample as AI-generated. Predictions by Aegis are not perfect: it's not an end all be all judge. Additionally, tasks where semantic convergence between humans and AI is observed (think LeetCode) are inherently hard to classify.

Installation

pip install aegis-detect

CLI Usage

Supported commands:

# Predicting using a file
aegis --file path/to/code.py

# Predicting using text
aegis --text "def add(a, b):\n    return a + b"

# JSON output
aegis --file path/to/code.py --json > result.json

# Setting a threshold for AI classification 
aegis --file path/to/code.py --threshold 0.7

# Help
aegis --help

Notes:

  • On first run, the model adapter is downloaded from the Hugging Face repo anthonyq7/aegis and cached under ~/.aegis/models.
  • Internet access is required on the first run; subsequent runs use local cache.
  • The CLI prints the predicted label and probabilities for human and AI.

Key Results

Model Performance

  • Accuracy: 85.10%
  • Precision: 83.37%
  • Recall: 87.70%
  • F1-Score: 85.48%

Confusion Matrix

Alt text

Attention Heatmap

Alt text

Contact

Email: a.j.qin@wustl.edu

License

This project is licensed under the MIT License.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

aegis_detect-0.1.0.tar.gz (5.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aegis_detect-0.1.0-py3-none-any.whl (5.9 kB view details)

Uploaded Python 3

File details

Details for the file aegis_detect-0.1.0.tar.gz.

File metadata

  • Download URL: aegis_detect-0.1.0.tar.gz
  • Upload date:
  • Size: 5.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.24

File hashes

Hashes for aegis_detect-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a1db16b74ecc840b4755294992599e4f0b5474dcde73dfa71235a746ba909331
MD5 8ce9cab7c288bc9fe6e0bad3306fce4a
BLAKE2b-256 f33556544438ae536e0a7a2678fa90a49bf7154d06f8a4333dfb8c9d510d8885

See more details on using hashes here.

File details

Details for the file aegis_detect-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for aegis_detect-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5fd1fb977cc34f48fe218d2f10cef4c4a4f3b86bf40ec5b183a7c59f94979899
MD5 b520ccbae318b47e342919e1417bd9ad
BLAKE2b-256 196dbe0a8a66675e841b486f3321478a1c911bed2f7225612ed7853932838f87

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page