File size: 1,949 Bytes
ff18c0b
 
 
 
 
 
 
 
 
 
 
 
 
8102a83
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---
library_name: transformers
pipeline_tag: feature-extraction
datasets:
    - andstor/cvevc_commits
tags:
    - code
    - codebert
    - security
    - commit-embeddings
    - custom_code
---

# VulFixMiner Encoder

A CodeBERT-based encoder for commit-diff embeddings.

## Overview

This package provides a CodeBERT-based embedding model for code change snippets. It is designed to convert a diff or patch fragment into a dense semantic representation suitable for downstream security classification.

## Model details

- Base model: CodeBERT
- Output representation: 768-dimensional embedding
- Use case: feature extraction for commit-level security classification

## Training data

Fine-tuned on [andstor/cvevc_commits](https://huggingface.co/datasets/andstor/cvevc_commits).
The encoder learns from individual file changes extracted from these commits.

## Example

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

model_name = "andstor/vulfixminer-encoder"

tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
model = AutoModel.from_pretrained(model_name, trust_remote_code=True)
model.eval()

patch = """
@@ -1,3 +1,4 @@
- old_call()
+ fixed_call()
+ validate_input()
"""

inputs = tokenizer(patch, return_tensors="pt", truncation=True, max_length=256)
with torch.no_grad():
    outputs = model(**inputs)
    embedding = outputs.last_hidden_state[:, 0, :]
    print(embedding.shape)
```

## Notes

- **Commit inputs:** Remove comments and empty changes, then encode each file as added code + `tokenizer.sep_token` + deleted code. The raw-diff example above demonstrates the API, not this preprocessing.
- **Commit embeddings:** Tokenize files separately with truncation and padding to 256 tokens. Average their first-token embeddings with `mean(dim=0, keepdim=True)` to obtain a `[1, 768]` vector for [andstor/vulfixminer-classifier](https://huggingface.co/andstor/vulfixminer-classifier).