Sumeetgpt commited on
Commit
a39d161
·
verified ·
1 Parent(s): 4893b77

Add model card with description, usage examples, and training data details

Browse files
Files changed (1) hide show
  1. README.md +97 -91
README.md CHANGED
@@ -1,130 +1,136 @@
1
  ---
 
 
2
  tags:
3
- - setfit
4
- - sentence-transformers
5
- - text-classification
6
- - generated_from_setfit_trainer
7
- widget: []
8
- metrics:
9
- - accuracy
 
10
  pipeline_tag: text-classification
11
  library_name: setfit
12
- inference: true
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  ---
14
 
15
- # SetFit
16
 
17
- This is a [SetFit](https://github.com/huggingface/setfit) model that can be used for Text Classification. A [LogisticRegression](https://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegression.html) instance is used for classification.
18
 
19
- The model has been trained using an efficient few-shot learning technique that involves:
20
 
21
- 1. Fine-tuning a [Sentence Transformer](https://www.sbert.net) with contrastive learning.
22
- 2. Training a classification head with features from the fine-tuned Sentence Transformer.
23
 
24
- ## Model Details
 
 
 
 
 
25
 
26
- ### Model Description
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
- ### Model Sources
 
 
 
 
 
37
 
38
- - **Repository:** [SetFit on GitHub](https://github.com/huggingface/setfit)
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
- ## Uses
 
43
 
44
- ### Direct Use for Inference
45
 
46
- First install the SetFit library:
 
 
 
 
 
47
 
48
- ```bash
49
- pip install setfit
50
  ```
51
 
52
- Then you can load this model and run inference.
53
 
54
- ```python
55
- from setfit import SetFitModel
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
- ### Downstream Use
65
 
66
- *List how someone could finetune this model on their own dataset.*
67
- -->
68
 
69
- <!--
70
- ### Out-of-Scope Use
71
 
72
- *List how the model may foreseeably be misused and address what users ought not to do with the model.*
73
- -->
74
 
75
- <!--
76
- ## Bias, Risks and Limitations
 
 
 
77
 
78
- *What are the known or foreseeable issues stemming from this model? You could also flag here known failure cases or weaknesses of the model.*
79
- -->
 
 
80
 
81
- <!--
82
- ### Recommendations
 
 
83
 
84
- *What are recommendations with respect to the foreseeable issues? For example, filtering explicit content.*
85
- -->
86
 
87
- ## Training Details
 
 
 
88
 
89
- ### Framework Versions
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
- ## Citation
99
 
100
- ### BibTeX
101
- ```bibtex
102
- @article{https://doi.org/10.48550/arxiv.2209.11055,
103
- doi = {10.48550/ARXIV.2209.11055},
104
- url = {https://arxiv.org/abs/2209.11055},
105
- author = {Tunstall, Lewis and Reimers, Nils and Jo, Unso Eun Seo and Bates, Luke and Korat, Daniel and Wasserblat, Moshe and Pereg, Oren},
106
- keywords = {Computation and Language (cs.CL), FOS: Computer and information sciences, FOS: Computer and information sciences},
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
- *Clearly define terms in order to be accessible across audiences.*
118
- -->
119
 
120
- <!--
121
- ## Model Card Authors
122
 
123
- *Lists the people who create the model card, providing recognition and accountability for the detailed work that goes into its construction.*
124
- -->
125
 
126
- <!--
127
- ## Model Card Contact
128
 
129
- *Provides a way for people who have updates to the Model Card, suggestions, or questions, to contact the Model Card authors.*
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