Feature Extraction
Transformers
PyTorch
vulfixminer_classifier
code
security
vulnerability-fix-detection
commit-classification
custom_code
Instructions to use andstor/VulFixMiner-classifier with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use andstor/VulFixMiner-classifier with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("feature-extraction", model="andstor/VulFixMiner-classifier", trust_remote_code=True)# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("andstor/VulFixMiner-classifier", trust_remote_code=True, device_map="auto") - Notebooks
- Google Colab
- Kaggle
|
Download README.md from andstor/VulFixMiner-classifier: direct link, hf CLI and curl.
- Browser
- Download file 3.16 kB
-
https://huggingface.co/andstor/VulFixMiner-classifier/resolve/main/README.md
- Command line
-
hf download hf://andstor/VulFixMiner-classifier/README.md
-
curl -L -o README.md https://huggingface.co/andstor/VulFixMiner-classifier/resolve/main/README.md
3.16 kB
| library_name: transformers | |
| datasets: | |
| - andstor/cvevc_commits | |
| tags: | |
| - code | |
| - security | |
| - vulnerability-fix-detection | |
| - commit-classification | |
| - custom_code | |
| # VulFixMiner Classifier | |
| A binary classifier for commit embeddings. | |
| ## Overview | |
| This package contains the final binary classifier used after a commit-diff embedding has been generated. It accepts a 768-dimensional feature vector and produces a probabilistic decision for the target class. | |
| ## Model details | |
| - Input dimension: 768 | |
| - Hidden dimension: 768 | |
| - Output classes: 2 | |
| - Output: two class logits; apply softmax to obtain probabilities | |
| ## Training data | |
| Trained on commit embeddings from [andstor/cvevc_commits](https://huggingface.co/datasets/andstor/cvevc_commits). Each commit is represented by the mean of its file embeddings from the paired VulFixMiner encoder. | |
| ## End-to-end example | |
| Encode the changed files of one commit, average their embeddings, and classify | |
| the resulting commit representation. This example starts with added and deleted | |
| code already extracted from each file diff, with comments and empty changes removed. | |
| ```python | |
| import torch | |
| from transformers import AutoModel, AutoTokenizer | |
| encoder_id = "andstor/vulfixminer-encoder" | |
| tokenizer = AutoTokenizer.from_pretrained(encoder_id, trust_remote_code=True) | |
| encoder = AutoModel.from_pretrained(encoder_id, trust_remote_code=True).eval() | |
| classifier = AutoModel.from_pretrained( | |
| "andstor/vulfixminer-classifier", trust_remote_code=True | |
| ).eval() | |
| # Two changed files in the same commit; matching indices refer to the same file. | |
| added_code = [ | |
| "validate_input();\nfixed_call();", # File 1 | |
| "free(buffer);\nbuffer = NULL;", # File 2 | |
| ] | |
| deleted_code = [ | |
| "old_call();", # File 1 | |
| "free(buffer);", # File 2 | |
| ] | |
| file_inputs = [ | |
| added + tokenizer.sep_token + deleted | |
| for added, deleted in zip(added_code, deleted_code) | |
| ] | |
| inputs = tokenizer( | |
| file_inputs, return_tensors="pt", truncation=True, | |
| padding="max_length", max_length=256, | |
| ) | |
| with torch.inference_mode(): | |
| file_embeddings = encoder(**inputs).last_hidden_state[:, 0, :] # [2, 768] | |
| # Average the two file embeddings into one commit embedding. | |
| commit_embedding = file_embeddings.mean(dim=0, keepdim=True) # [1, 768] | |
| logits = classifier(commit_embedding)["logits"] # [1, 2] | |
| probability = logits.softmax(dim=-1)[0, 1].item() | |
| print("File embeddings:", file_embeddings.shape) # [2, 768] | |
| print("Commit embedding:", commit_embedding.shape) # [1, 768] | |
| print("Security-patch probability:", probability) | |
| ``` | |
| Replace `added_code` and `deleted_code` with your commit's preprocessed changes. | |
| Keep the lists aligned by file, using an empty string when a file has no added or | |
| deleted code. Do not pass raw unified diffs directly. | |
| `trust_remote_code=True` loads the custom model implementations. Review the code | |
| before enabling it and pin reviewed Hub revisions for reproducible use. | |
| ## Notes | |
| This model accepts commit representations from [andstor/vulfixminer-encoder](https://huggingface.co/andstor/vulfixminer-encoder). It is not a raw patch-to-label model by itself. | |