File size: 1,468 Bytes
5f7e3fc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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

---
language: en
tags:
- vulnerability-detection
- code-analysis
- autoencoder
- anomaly-detection
library_name: pytorch
metrics:
- mse
---

# CATastrophe - Code Vulnerability Detector

This model is an autoencoder-based vulnerability detector for Python code. It uses TF-IDF
vectorization and an autoencoder architecture to detect anomalies in code that may indicate
vulnerabilities.

## Model Details

- **Architecture**: Autoencoder (Input → 512 → 128 → 512 → Input)
- **Input Features**: 2000 (TF-IDF)
- **Training Loss**: 0.0005
- **Framework**: PyTorch

## Usage

```python
import torch
import pickle
from model import Autoencoder

# Load model
model = Autoencoder(input_dim=2000)
model.load_state_dict(torch.load('catastrophe_model.pth'))
model.eval()

# Load vectorizer
with open('vectorizer.pkl', 'rb') as f:
    vectorizer = pickle.load(f)

# Analyze code
code_text = "your code here"
features = vectorizer.transform([code_text]).toarray()
features_tensor = torch.tensor(features, dtype=torch.float32)

with torch.no_grad():
    reconstructed = model(features_tensor)
    anomaly_score = torch.mean((features_tensor - reconstructed) ** 2, dim=1)
```

## Training Configuration

- Batch Size: 256
- Epochs: 50
- Learning Rate: 0.001
- Optimizer: Adam

## Limitations

This model is trained on vulnerable commits only and uses reconstruction error as an
anomaly score. High scores indicate potential vulnerabilities, but manual review is
recommended.