File size: 1,938 Bytes
aa7f273
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
---
language:
- code
license: mit
base_model: microsoft/codebert-base
tags:
- code
- python
- ai-generated-code-detection
- codebert
- binary-classification
pipeline_tag: text-classification
datasets:
- AggressiveBag/VKR_Dataset
metrics:
- accuracy
- precision
- recall
- f1
---

# VKR Model

Binary classifier for detecting whether Python code is human-written or AI-generated.

The model was fine-tuned from `microsoft/codebert-base` on the `AggressiveBag/VKR_Dataset` dataset.

## Labels

- `0`: human-written Python code
- `1`: AI-generated Python code

## Training Setup

- Base model: `microsoft/codebert-base`
- Maximum sequence length: 512
- Epochs: 3
- Batch size: 8
- Learning rate: `2e-5`
- Weight decay: `0.01`
- Warmup ratio: `0.06`
- Seed: 42
- Encoder frozen: yes

## Validation Metrics

| Metric | Value |
|---|---:|
| Loss | 0.4192 |
| Accuracy | 0.7836 |
| Precision, AI class | 0.7142 |
| Recall, AI class | 0.9456 |
| F1, AI class | 0.8138 |

## Usage

```python
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch

model_id = "AggressiveBag/VKR_Model"

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

code = "print('hello world')"
inputs = tokenizer(code, return_tensors="pt", truncation=True, max_length=512)

with torch.no_grad():
    logits = model(**inputs).logits
    probs = torch.softmax(logits, dim=-1)[0]

print({"human": float(probs[0]), "ai": float(probs[1])})
```

## Intended Use

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.

## Dataset

The training data is based on human solutions from APPS and locally generated AI solutions. See `AggressiveBag/VKR_Dataset` for dataset details.