CoolFace
Modelpublic

azherali/CodeGenDetect-CodeBert

sourceHugging Faceupdated 9mo agoView on Hugging Face
0likes145downloads
Model Card

CodeGenDetect-CodeBERT

Model Name: azherali/CodeGenDetect-CodeBert Task: Code Generation Detection (Human vs Machine Generated Code) Languages Supported: C++, Java, Python Base Model: CodeBERT Author: Azher Ali


๐Ÿ“Œ Model Overview

CodeGenDetect-CodeBert is a transformer-based classification model designed to distinguish human-written code from machine-generated code produced by Large Language Models (LLMs). The model is fine-tuned on multilingual source code data spanning C++, Java, and Python, making it suitable for real-world, cross-language code analysis tasks.

Built on top of CodeBERT, the model leverages contextual and structural representations of source code to capture subtle stylistic, syntactic, and semantic patterns that differentiate human-authored code from AI-generated code.


๐ŸŽฏ Intended Use Cases

This model is well-suited for:

  • โ€”Academic integrity & plagiarism detection
  • โ€”LLM-generated code identification
  • โ€”Code authenticity verification
  • โ€”Research on AI-generated programming artifacts
  • โ€”Code forensics and auditing pipelines

๐Ÿง  Model Details

  • โ€”Architecture: Transformer-based (CodeBERT)
  • โ€”Task Type: Binary Sequence Classification
  • โ€”Labels:
  • โ€”0 โ†’ Human-generated code
  • โ€”1 โ†’ Machine-generated (LLM) code
  • โ€”Input: Source code as plain text
  • โ€”Output: Class probabilities and predicted label

๐ŸŒ Supported Programming Languages

The model has been trained and evaluated on code written in:

  • โ€”C++
  • โ€”Java
  • โ€”Python

It generalizes across these languages by learning language-agnostic code patterns while still capturing language-specific constructs.


๐Ÿ‹๏ธ Training Summary

  • โ€”Training Objective: Binary cross-entropy loss for classification
  • โ€”Tokenization: CodeBERT tokenizer with fixed-length padding and truncation
  • โ€”Optimization: Fine-tuned using modern deep learning best practices
  • โ€”Evaluation Metrics: Accuracy, Precision, Recall, F1-score

The training data includes both human-written code and code generated by modern LLMs to ensure realistic detection performance.


๐Ÿš€ Example Usage

python
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch

model_name = "azherali/CodeGenDetect-CodeBert"

tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name)

code_snippet = """
def add(a, b):
    return a + b
"""

inputs = tokenizer(code_snippet, return_tensors="pt", truncation=True, padding=True)
outputs = model(**inputs)

prediction = torch.argmax(outputs.logits, dim=1).item()
label = "Machine-generated" if prediction == 1 else "Human-written"

print(label)