Text Classification
setfit
Safetensors
sentence-transformers
English
bert
code-security
dlp
secret-detection
vulnerability-detection
Eval Results (legacy)
text-embeddings-inference
Instructions to use spidercob/code-risk-classifier with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- setfit
How to use spidercob/code-risk-classifier with setfit:
from setfit import SetFitModel model = SetFitModel.from_pretrained("spidercob/code-risk-classifier") - sentence-transformers
How to use spidercob/code-risk-classifier with sentence-transformers:
from sentence_transformers import SentenceTransformer model = SentenceTransformer("spidercob/code-risk-classifier") sentences = [ "The weather is lovely today.", "It's so sunny outside!", "He drove to the stadium." ] embeddings = model.encode(sentences) similarities = model.similarity(embeddings, embeddings) print(similarities.shape) # [3, 3] - Notebooks
- Google Colab
- Kaggle
Add model card with description, usage examples, and training data details
Browse files
README.md
CHANGED
|
@@ -1,130 +1,136 @@
|
|
| 1 |
---
|
|
|
|
|
|
|
| 2 |
tags:
|
| 3 |
-
- setfit
|
| 4 |
-
-
|
| 5 |
-
-
|
| 6 |
-
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
-
|
|
|
|
| 10 |
pipeline_tag: text-classification
|
| 11 |
library_name: setfit
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
---
|
| 14 |
|
| 15 |
-
#
|
| 16 |
|
| 17 |
-
|
| 18 |
|
| 19 |
-
The
|
| 20 |
|
| 21 |
-
|
| 22 |
-
2. Training a classification head with features from the fine-tuned Sentence Transformer.
|
| 23 |
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
-
##
|
| 27 |
-
- **Model Type:** SetFit
|
| 28 |
-
<!-- - **Sentence Transformer:** [Unknown](https://huggingface.co/unknown) -->
|
| 29 |
-
- **Classification head:** a [LogisticRegression](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegression.html) instance
|
| 30 |
-
- **Maximum Sequence Length:** 256 tokens
|
| 31 |
-
- **Number of Classes:** 4 classes
|
| 32 |
-
<!-- - **Training Dataset:** [Unknown](https://huggingface.co/datasets/unknown) -->
|
| 33 |
-
<!-- - **Language:** Unknown -->
|
| 34 |
-
<!-- - **License:** Unknown -->
|
| 35 |
|
| 36 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 37 |
|
| 38 |
-
|
| 39 |
-
- **Paper:** [Efficient Few-Shot Learning Without Prompts](https://arxiv.org/abs/2209.11055)
|
| 40 |
-
- **Blogpost:** [SetFit: Efficient Few-Shot Learning Without Prompts](https://huggingface.co/blog/setfit)
|
| 41 |
|
| 42 |
-
|
|
|
|
| 43 |
|
| 44 |
-
|
| 45 |
|
| 46 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
|
| 48 |
-
|
| 49 |
-
|
| 50 |
```
|
| 51 |
|
| 52 |
-
|
| 53 |
|
| 54 |
-
```
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
# Download from the 🤗 Hub
|
| 58 |
-
model = SetFitModel.from_pretrained("setfit_model_id")
|
| 59 |
-
# Run inference
|
| 60 |
-
preds = model("I loved the spiderman movie!")
|
| 61 |
```
|
| 62 |
|
| 63 |
-
|
| 64 |
-
|
| 65 |
|
| 66 |
-
|
| 67 |
-
-->
|
| 68 |
|
| 69 |
-
|
| 70 |
-
|
| 71 |
|
| 72 |
-
|
| 73 |
-
-->
|
| 74 |
|
| 75 |
-
|
| 76 |
-
|
|
|
|
|
|
|
|
|
|
| 77 |
|
| 78 |
-
|
| 79 |
-
|
|
|
|
|
|
|
| 80 |
|
| 81 |
-
|
| 82 |
-
|
|
|
|
|
|
|
| 83 |
|
| 84 |
-
|
| 85 |
-
-->
|
| 86 |
|
| 87 |
-
|
|
|
|
|
|
|
|
|
|
| 88 |
|
| 89 |
-
##
|
| 90 |
-
- Python: 3.12.12
|
| 91 |
-
- SetFit: 1.1.3
|
| 92 |
-
- Sentence Transformers: 5.2.2
|
| 93 |
-
- Transformers: 4.57.6
|
| 94 |
-
- PyTorch: 2.10.0
|
| 95 |
-
- Datasets: 5.0.0
|
| 96 |
-
- Tokenizers: 0.22.2
|
| 97 |
|
| 98 |
-
|
| 99 |
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
title = {Efficient Few-Shot Learning Without Prompts},
|
| 108 |
-
publisher = {arXiv},
|
| 109 |
-
year = {2022},
|
| 110 |
-
copyright = {Creative Commons Attribution 4.0 International}
|
| 111 |
-
}
|
| 112 |
-
```
|
| 113 |
|
| 114 |
-
|
| 115 |
-
## Glossary
|
| 116 |
|
| 117 |
-
|
| 118 |
-
-->
|
| 119 |
|
| 120 |
-
|
| 121 |
-
## Model Card Authors
|
| 122 |
|
| 123 |
-
|
| 124 |
-
-->
|
| 125 |
|
| 126 |
-
|
| 127 |
-
## Model Card Contact
|
| 128 |
|
| 129 |
-
|
| 130 |
-
-->
|
|
|
|
| 1 |
---
|
| 2 |
+
language: en
|
| 3 |
+
license: apache-2.0
|
| 4 |
tags:
|
| 5 |
+
- setfit
|
| 6 |
+
- text-classification
|
| 7 |
+
- code-security
|
| 8 |
+
- secret-detection
|
| 9 |
+
- vulnerability-detection
|
| 10 |
+
- false-positive-reduction
|
| 11 |
+
- sast
|
| 12 |
+
- dlp
|
| 13 |
pipeline_tag: text-classification
|
| 14 |
library_name: setfit
|
| 15 |
+
metrics:
|
| 16 |
+
- accuracy
|
| 17 |
+
model-index:
|
| 18 |
+
- name: spidercob/code-risk-classifier
|
| 19 |
+
results:
|
| 20 |
+
- task:
|
| 21 |
+
type: text-classification
|
| 22 |
+
name: Text Classification
|
| 23 |
+
dataset:
|
| 24 |
+
name: Public repos (WebGoat, DVWA, factory_boy, Django, FastAPI, truffleHog)
|
| 25 |
+
type: mixed
|
| 26 |
+
split: test
|
| 27 |
+
metrics:
|
| 28 |
+
- type: accuracy
|
| 29 |
+
value: 0.9942
|
| 30 |
+
name: Accuracy
|
| 31 |
---
|
| 32 |
|
| 33 |
+
# spidercob/code-risk-classifier
|
| 34 |
|
| 35 |
+
A [SetFit](https://github.com/huggingface/setfit) model that classifies **code security findings** — distinguishing real secrets and vulnerabilities from test fixtures and safe code.
|
| 36 |
|
| 37 |
+
## The Problem
|
| 38 |
|
| 39 |
+
Static analysis tools (SAST, secret scanners) generate high false-positive rates:
|
|
|
|
| 40 |
|
| 41 |
+
- A `SECRET_KEY = 'testing.'` in Django's test suite is not a real secret
|
| 42 |
+
- A `$_GET['id']` in DVWA is an intentional vulnerability example, not production code
|
| 43 |
+
- `factory_boy` password fields are test fixtures, not real credentials
|
| 44 |
+
- A `bcrypt.hashpw()` call is safe, not a credential leak
|
| 45 |
+
|
| 46 |
+
This model reads the code context and decides whether a finding is actionable.
|
| 47 |
|
| 48 |
+
## Labels
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
+
| Label | Description | Action |
|
| 51 |
+
|---|---|---|
|
| 52 |
+
| `REAL_SECRET` | Genuine hardcoded credential, API key, or private key | BLOCK |
|
| 53 |
+
| `VULNERABLE_LOGIC` | Exploitable code pattern (SQLi, RCE, XSS, etc.) | BLOCK |
|
| 54 |
+
| `TEST_MOCK` | Test fixture, dummy value, or mock data | ALLOW |
|
| 55 |
+
| `SAFE_CODE` | Clean production code or secure implementation | ALLOW |
|
| 56 |
|
| 57 |
+
## Quick Start
|
|
|
|
|
|
|
| 58 |
|
| 59 |
+
```python
|
| 60 |
+
from setfit import SetFitModel
|
| 61 |
|
| 62 |
+
model = SetFitModel.from_pretrained("spidercob/code-risk-classifier")
|
| 63 |
|
| 64 |
+
examples = [
|
| 65 |
+
"Analyze this hardcoded_secret: AWS_ACCESS_KEY_ID=AKIA4REALKEY123ABC committed to main branch .env file",
|
| 66 |
+
"Analyze this vulnerable_pattern: $query = 'SELECT * FROM users WHERE id=' . $_GET['id'];",
|
| 67 |
+
"Analyze this test_fixture: factory_boy default: user.password = 'testpass123' for pytest fixtures",
|
| 68 |
+
"Analyze this clean_code: def get_user(db, user_id): return db.query(User).filter(User.id == user_id).first()",
|
| 69 |
+
]
|
| 70 |
|
| 71 |
+
predictions = model.predict(examples)
|
| 72 |
+
# ['REAL_SECRET', 'VULNERABLE_LOGIC', 'TEST_MOCK', 'SAFE_CODE']
|
| 73 |
```
|
| 74 |
|
| 75 |
+
## Input Format
|
| 76 |
|
| 77 |
+
```
|
| 78 |
+
Analyze this {issue_type}: {code_snippet}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
```
|
| 80 |
|
| 81 |
+
- `issue_type`: the scanner finding type — e.g. `hardcoded_secret`, `vulnerable_pattern`, `sql_injection`, `test_fixture`, `clean_code`
|
| 82 |
+
- `code_snippet`: the code context around the finding, up to ~400 characters
|
| 83 |
|
| 84 |
+
## Integration Pattern
|
|
|
|
| 85 |
|
| 86 |
+
```python
|
| 87 |
+
from setfit import SetFitModel
|
| 88 |
|
| 89 |
+
model = SetFitModel.from_pretrained("spidercob/code-risk-classifier")
|
|
|
|
| 90 |
|
| 91 |
+
def assess_finding(issue_type: str, code_snippet: str) -> dict:
|
| 92 |
+
text = f"Analyze this {issue_type}: {code_snippet}"
|
| 93 |
+
label = model.predict([text])[0]
|
| 94 |
+
probs = model.predict_proba([text])[0]
|
| 95 |
+
conf = max(probs)
|
| 96 |
|
| 97 |
+
if label in ("REAL_SECRET", "VULNERABLE_LOGIC"):
|
| 98 |
+
return {"action": "BLOCK", "label": label, "confidence": conf}
|
| 99 |
+
else:
|
| 100 |
+
return {"action": "ALLOW", "label": label, "confidence": conf}
|
| 101 |
|
| 102 |
+
# Example
|
| 103 |
+
result = assess_finding("hardcoded_secret", "SECRET_KEY = '0123456789ABCDEF' in production settings.py")
|
| 104 |
+
# {"action": "BLOCK", "label": "REAL_SECRET", "confidence": 0.83}
|
| 105 |
+
```
|
| 106 |
|
| 107 |
+
## Model Details
|
|
|
|
| 108 |
|
| 109 |
+
- **Base model**: `sentence-transformers/all-MiniLM-L6-v2`
|
| 110 |
+
- **Method**: SetFit — contrastive fine-tuning + logistic regression head
|
| 111 |
+
- **Test accuracy**: **99.4%**
|
| 112 |
+
- **Classes**: 4 (REAL_SECRET, VULNERABLE_LOGIC, TEST_MOCK, SAFE_CODE)
|
| 113 |
|
| 114 |
+
## Training Data
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
|
| 116 |
+
~860 examples from 15 public repos (capped at 300 per class):
|
| 117 |
|
| 118 |
+
| Source | Label | Why |
|
| 119 |
+
|---|---|---|
|
| 120 |
+
| OWASP WebGoat, DVWA, NodeGoat | `VULNERABLE_LOGIC` | Intentionally vulnerable apps |
|
| 121 |
+
| vulhub, DVGA | `VULNERABLE_LOGIC` | CVE docker environments |
|
| 122 |
+
| truffleHog test corpus | `REAL_SECRET` | Confirmed leaked secrets |
|
| 123 |
+
| factory_boy, Faker, pytest, model_bakery | `TEST_MOCK` | Test fixture libraries |
|
| 124 |
+
| Django, FastAPI, Flask, requests, httpx | `SAFE_CODE` | Clean production frameworks |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 125 |
|
| 126 |
+
## Related Model
|
|
|
|
| 127 |
|
| 128 |
+
For DLP regex false-positive reduction (SSNs, credit cards, emails, API keys in content), see [spidercob/dlp-intent-classifier](https://huggingface.co/spidercob/dlp-intent-classifier).
|
|
|
|
| 129 |
|
| 130 |
+
## About
|
|
|
|
| 131 |
|
| 132 |
+
Built by [Spidercob](https://spidercob.com) — enterprise DLP SaaS. This model powers the false-positive reduction layer in Spidercob's code security scanner.
|
|
|
|
| 133 |
|
| 134 |
+
## License
|
|
|
|
| 135 |
|
| 136 |
+
Apache 2.0
|
|
|