Kirill commited on
Commit ·
aa7f273
1
Parent(s): dd564a2
Add VKR CodeBERT detector model
Browse files- README.md +82 -0
- config.json +38 -0
- metrics.json +7 -0
- model.safetensors +3 -0
- tokenizer.json +0 -0
- tokenizer_config.json +17 -0
- training_args.json +18 -0
README.md
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language:
|
| 3 |
+
- code
|
| 4 |
+
license: mit
|
| 5 |
+
base_model: microsoft/codebert-base
|
| 6 |
+
tags:
|
| 7 |
+
- code
|
| 8 |
+
- python
|
| 9 |
+
- ai-generated-code-detection
|
| 10 |
+
- codebert
|
| 11 |
+
- binary-classification
|
| 12 |
+
pipeline_tag: text-classification
|
| 13 |
+
datasets:
|
| 14 |
+
- AggressiveBag/VKR_Dataset
|
| 15 |
+
metrics:
|
| 16 |
+
- accuracy
|
| 17 |
+
- precision
|
| 18 |
+
- recall
|
| 19 |
+
- f1
|
| 20 |
+
---
|
| 21 |
+
|
| 22 |
+
# VKR Model
|
| 23 |
+
|
| 24 |
+
Binary classifier for detecting whether Python code is human-written or AI-generated.
|
| 25 |
+
|
| 26 |
+
The model was fine-tuned from `microsoft/codebert-base` on the `AggressiveBag/VKR_Dataset` dataset.
|
| 27 |
+
|
| 28 |
+
## Labels
|
| 29 |
+
|
| 30 |
+
- `0`: human-written Python code
|
| 31 |
+
- `1`: AI-generated Python code
|
| 32 |
+
|
| 33 |
+
## Training Setup
|
| 34 |
+
|
| 35 |
+
- Base model: `microsoft/codebert-base`
|
| 36 |
+
- Maximum sequence length: 512
|
| 37 |
+
- Epochs: 3
|
| 38 |
+
- Batch size: 8
|
| 39 |
+
- Learning rate: `2e-5`
|
| 40 |
+
- Weight decay: `0.01`
|
| 41 |
+
- Warmup ratio: `0.06`
|
| 42 |
+
- Seed: 42
|
| 43 |
+
- Encoder frozen: yes
|
| 44 |
+
|
| 45 |
+
## Validation Metrics
|
| 46 |
+
|
| 47 |
+
| Metric | Value |
|
| 48 |
+
|---|---:|
|
| 49 |
+
| Loss | 0.4192 |
|
| 50 |
+
| Accuracy | 0.7836 |
|
| 51 |
+
| Precision, AI class | 0.7142 |
|
| 52 |
+
| Recall, AI class | 0.9456 |
|
| 53 |
+
| F1, AI class | 0.8138 |
|
| 54 |
+
|
| 55 |
+
## Usage
|
| 56 |
+
|
| 57 |
+
```python
|
| 58 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
| 59 |
+
import torch
|
| 60 |
+
|
| 61 |
+
model_id = "AggressiveBag/VKR_Model"
|
| 62 |
+
|
| 63 |
+
tokenizer = AutoTokenizer.from_pretrained(model_id)
|
| 64 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_id)
|
| 65 |
+
|
| 66 |
+
code = "print('hello world')"
|
| 67 |
+
inputs = tokenizer(code, return_tensors="pt", truncation=True, max_length=512)
|
| 68 |
+
|
| 69 |
+
with torch.no_grad():
|
| 70 |
+
logits = model(**inputs).logits
|
| 71 |
+
probs = torch.softmax(logits, dim=-1)[0]
|
| 72 |
+
|
| 73 |
+
print({"human": float(probs[0]), "ai": float(probs[1])})
|
| 74 |
+
```
|
| 75 |
+
|
| 76 |
+
## Intended Use
|
| 77 |
+
|
| 78 |
+
This model is intended for research and educational experiments related to AI-generated Python code detection. It should not be used as the sole evidence for high-stakes decisions, because AI-code detection can produce false positives and false negatives.
|
| 79 |
+
|
| 80 |
+
## Dataset
|
| 81 |
+
|
| 82 |
+
The training data is based on human solutions from APPS and locally generated AI solutions. See `AggressiveBag/VKR_Dataset` for dataset details.
|
config.json
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"add_cross_attention": false,
|
| 3 |
+
"architectures": [
|
| 4 |
+
"RobertaForSequenceClassification"
|
| 5 |
+
],
|
| 6 |
+
"attention_probs_dropout_prob": 0.1,
|
| 7 |
+
"bos_token_id": 0,
|
| 8 |
+
"classifier_dropout": null,
|
| 9 |
+
"dtype": "float32",
|
| 10 |
+
"eos_token_id": 2,
|
| 11 |
+
"hidden_act": "gelu",
|
| 12 |
+
"hidden_dropout_prob": 0.1,
|
| 13 |
+
"hidden_size": 768,
|
| 14 |
+
"id2label": {
|
| 15 |
+
"0": "human",
|
| 16 |
+
"1": "ai"
|
| 17 |
+
},
|
| 18 |
+
"initializer_range": 0.02,
|
| 19 |
+
"intermediate_size": 3072,
|
| 20 |
+
"is_decoder": false,
|
| 21 |
+
"label2id": {
|
| 22 |
+
"ai": 1,
|
| 23 |
+
"human": 0
|
| 24 |
+
},
|
| 25 |
+
"layer_norm_eps": 1e-05,
|
| 26 |
+
"max_position_embeddings": 514,
|
| 27 |
+
"model_type": "roberta",
|
| 28 |
+
"num_attention_heads": 12,
|
| 29 |
+
"num_hidden_layers": 12,
|
| 30 |
+
"output_past": true,
|
| 31 |
+
"pad_token_id": 1,
|
| 32 |
+
"problem_type": "single_label_classification",
|
| 33 |
+
"tie_word_embeddings": true,
|
| 34 |
+
"transformers_version": "5.8.1",
|
| 35 |
+
"type_vocab_size": 1,
|
| 36 |
+
"use_cache": true,
|
| 37 |
+
"vocab_size": 50265
|
| 38 |
+
}
|
metrics.json
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"loss": 0.419158761295219,
|
| 3 |
+
"accuracy": 0.7836395233366436,
|
| 4 |
+
"precision_ai": 0.7142321395087193,
|
| 5 |
+
"recall_ai": 0.9456305858987091,
|
| 6 |
+
"f1_ai": 0.8138019442367269
|
| 7 |
+
}
|
model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:da991d429826fe2e45d6c9c26437163ad97bfe8aab05e7135b1b2377b1cd18c6
|
| 3 |
+
size 498612824
|
tokenizer.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"add_prefix_space": false,
|
| 3 |
+
"backend": "tokenizers",
|
| 4 |
+
"bos_token": "<s>",
|
| 5 |
+
"cls_token": "<s>",
|
| 6 |
+
"eos_token": "</s>",
|
| 7 |
+
"errors": "replace",
|
| 8 |
+
"is_local": false,
|
| 9 |
+
"local_files_only": false,
|
| 10 |
+
"mask_token": "<mask>",
|
| 11 |
+
"model_max_length": 512,
|
| 12 |
+
"pad_token": "<pad>",
|
| 13 |
+
"sep_token": "</s>",
|
| 14 |
+
"tokenizer_class": "RobertaTokenizer",
|
| 15 |
+
"trim_offsets": true,
|
| 16 |
+
"unk_token": "<unk>"
|
| 17 |
+
}
|
training_args.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"train": "data\\splits\\train.jsonl",
|
| 3 |
+
"val": "data\\splits\\val.jsonl",
|
| 4 |
+
"output_dir": "runs\\codebert-ai-detector",
|
| 5 |
+
"model_name": "microsoft/codebert-base",
|
| 6 |
+
"max_length": 512,
|
| 7 |
+
"epochs": 3,
|
| 8 |
+
"batch_size": 8,
|
| 9 |
+
"gradient_accumulation_steps": 1,
|
| 10 |
+
"learning_rate": 2e-05,
|
| 11 |
+
"weight_decay": 0.01,
|
| 12 |
+
"warmup_ratio": 0.06,
|
| 13 |
+
"seed": 42,
|
| 14 |
+
"freeze_encoder": true,
|
| 15 |
+
"limit_train": null,
|
| 16 |
+
"limit_val": null,
|
| 17 |
+
"num_workers": 0
|
| 18 |
+
}
|