Text Classification
setfit
Safetensors
sentence-transformers
bert
generated_from_setfit_trainer
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
Push model using huggingface_hub.
Browse files- README.md +101 -2
- model.safetensors +1 -1
- model_head.pkl +1 -1
README.md
CHANGED
|
@@ -4,12 +4,47 @@ tags:
|
|
| 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
|
|
@@ -39,6 +74,21 @@ The model has been trained using an efficient few-shot learning technique that i
|
|
| 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
|
|
@@ -57,7 +107,10 @@ from setfit import SetFitModel
|
|
| 57 |
# Download from the 🤗 Hub
|
| 58 |
model = SetFitModel.from_pretrained("setfit_model_id")
|
| 59 |
# Run inference
|
| 60 |
-
preds = model("
|
|
|
|
|
|
|
|
|
|
| 61 |
```
|
| 62 |
|
| 63 |
<!--
|
|
@@ -86,6 +139,52 @@ preds = model("I loved the spiderman movie!")
|
|
| 86 |
|
| 87 |
## Training Details
|
| 88 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
### Framework Versions
|
| 90 |
- Python: 3.12.12
|
| 91 |
- SetFit: 1.1.3
|
|
|
|
| 4 |
- sentence-transformers
|
| 5 |
- text-classification
|
| 6 |
- generated_from_setfit_trainer
|
| 7 |
+
widget:
|
| 8 |
+
- text: "class TestAuth(unittest.TestCase):\n def setUp(self):\n webhook_secret\
|
| 9 |
+
\ = \"test_abcdef1234567890\""
|
| 10 |
+
- text: "Analyze this vulnerable_pattern: function solveSum(obj) {\n\tif (\"answer\"\
|
| 11 |
+
\ in obj) {\n\t\tdocument.getElementById(\"answer\").innerHTML = obj['answer'];\n\
|
| 12 |
+
\t}\n}"
|
| 13 |
+
- text: "def handle_request(request):\n sql = f\"DELETE FROM sessions WHERE token='{token}'\"\
|
| 14 |
+
\n return result"
|
| 15 |
+
- text: 'Analyze this vulnerable_pattern: }
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
$create_tb = "CREATE TABLE users (user_id int(6),first_name varchar(15),last_name
|
| 19 |
+
varchar(15), user varchar(15), password varchar(32),avatar varchar(70), last_login
|
| 20 |
+
TIMESTAMP, failed_login INT(3), PRIMARY KEY (user_id));";
|
| 21 |
+
|
| 22 |
+
if( !mysqli_query($GLOBALS["___mysqli_ston"],'
|
| 23 |
+
- text: 'Analyze this clean_code: from __future__ import annotations
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
import importlib.util
|
| 27 |
+
|
| 28 |
+
import os'
|
| 29 |
metrics:
|
| 30 |
- accuracy
|
| 31 |
pipeline_tag: text-classification
|
| 32 |
library_name: setfit
|
| 33 |
inference: true
|
| 34 |
+
model-index:
|
| 35 |
+
- name: SetFit
|
| 36 |
+
results:
|
| 37 |
+
- task:
|
| 38 |
+
type: text-classification
|
| 39 |
+
name: Text Classification
|
| 40 |
+
dataset:
|
| 41 |
+
name: Unknown
|
| 42 |
+
type: unknown
|
| 43 |
+
split: test
|
| 44 |
+
metrics:
|
| 45 |
+
- type: accuracy
|
| 46 |
+
value: 0.9746192893401016
|
| 47 |
+
name: Accuracy
|
| 48 |
---
|
| 49 |
|
| 50 |
# SetFit
|
|
|
|
| 74 |
- **Paper:** [Efficient Few-Shot Learning Without Prompts](https://arxiv.org/abs/2209.11055)
|
| 75 |
- **Blogpost:** [SetFit: Efficient Few-Shot Learning Without Prompts](https://huggingface.co/blog/setfit)
|
| 76 |
|
| 77 |
+
### Model Labels
|
| 78 |
+
| Label | Examples |
|
| 79 |
+
|:-----------------|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 80 |
+
| TEST_MOCK | <ul><li>"client_secret: str = 'abc123'"</li><li>'# conftest.py\njwt_secret = "MY_API_KEY"'</li><li>"private_key: str = 'yyy'"</li></ul> |
|
| 81 |
+
| REAL_SECRET | <ul><li>'Analyze this hardcoded_secret: aws_access_key_id: AKIAI44QH8DHBEXAMPLE'</li><li>"Analyze this hardcoded_secret: // data: {\n // format: 'json',\n // method: 'flickr.interestingness.getList',\n // api_key: '7617adae70159d09ba78cfec73c13be3'\n // },\n\t // dataType: 'jsonp',\n // jsonp: 'json"</li><li>'Analyze this hardcoded_secret: name: "Blake2b with \'Hello, World!\'",\n\t\t\thasher: NewBlake2B(),\n\t\t\tinput: []byte("Hello, World!"),\n\t\t\texpectedHex: "511bc81dde11180838c562c82bb35f3223f46061ebde4a955c27b3f489cf1e03",\n\t\t},\n\t\t{\n\t\t\tname: "Blake2b input at max size",'</li></ul> |
|
| 82 |
+
| VULNERABLE_LOGIC | <ul><li>'Analyze this vulnerable_pattern: }\n\n$create_db = "CREATE DATABASE {$_DVWA[ \'db_database\' ]};";\nif( !@mysqli_query($GLOBALS["___mysqli_ston"], $create_db ) ) {\n\tdvwaMessagePush( "Could not create database<br />SQL: " . ((is_object($GLOBALS["___mysqli_ston"])) ? mysqli_error($GLOBALS["___mysqli_ston"]) : (($___mysqli_res = mysqli_connect_error()) ? $___mysqli_res : false)) );\n\tdvwaPageReload();\n}'</li><li>'Analyze this vulnerable_pattern: $user = stripslashes( $user );\n\t$user = mysqli_real_escape_string($GLOBALS["___mysqli_ston"], $user);\n\n\t$pass = $_POST[ \'password\' ];\n\t$pass = stripslashes( $pass );\n\t$pass = mysqli_real_escape_string($GLOBALS["___mysqli_ston"], $pass);\n\t$pass = md5( $pass );'</li><li>'Analyze this vulnerable_pattern: case MYSQL:\n\t\t\t// Check database\n\t\t\t$query = "SELECT first_name, last_name FROM users WHERE user_id = \'$id\' LIMIT 1;";\n\t\t\t$result = mysqli_query($GLOBALS["___mysqli_ston"], $query ) or die( \'<pre>Something went wrong.</pre>\' );\n\n\t\t\t// Get results\n\t\t\twhile( $row = mysqli_fetch_assoc( $result ) ) {'</li></ul> |
|
| 83 |
+
| SAFE_CODE | <ul><li>"Analyze this clean_code: [\n 500,\n {\n 'content-type' => content_type,\n 'content-length' => body.bytesize.to_s\n },\n [body]"</li><li>"Analyze this clean_code: it 'should allow switching on the include_subdomains option' do\n mock_app do\n use Rack::Protection::StrictTransport, include_subdomains: true\n run DummyApp\n end"</li><li>"Analyze this clean_code: check(@foo, Rack::Lock, @bar)\n end\n\n it 'works as middleware behind Rack::Lock, with lock disabled' do\n @foo.disable :lock\n check(Rack::Lock, @foo, @bar)\n end"</li></ul> |
|
| 84 |
+
|
| 85 |
+
## Evaluation
|
| 86 |
+
|
| 87 |
+
### Metrics
|
| 88 |
+
| Label | Accuracy |
|
| 89 |
+
|:--------|:---------|
|
| 90 |
+
| **all** | 0.9746 |
|
| 91 |
+
|
| 92 |
## Uses
|
| 93 |
|
| 94 |
### Direct Use for Inference
|
|
|
|
| 107 |
# Download from the 🤗 Hub
|
| 108 |
model = SetFitModel.from_pretrained("setfit_model_id")
|
| 109 |
# Run inference
|
| 110 |
+
preds = model("Analyze this clean_code: from __future__ import annotations
|
| 111 |
+
|
| 112 |
+
import importlib.util
|
| 113 |
+
import os")
|
| 114 |
```
|
| 115 |
|
| 116 |
<!--
|
|
|
|
| 139 |
|
| 140 |
## Training Details
|
| 141 |
|
| 142 |
+
### Training Set Metrics
|
| 143 |
+
| Training set | Min | Median | Max |
|
| 144 |
+
|:-------------|:----|:--------|:----|
|
| 145 |
+
| Word count | 1 | 27.6734 | 157 |
|
| 146 |
+
|
| 147 |
+
| Label | Training Sample Count |
|
| 148 |
+
|:-----------------|:----------------------|
|
| 149 |
+
| REAL_SECRET | 67 |
|
| 150 |
+
| VULNERABLE_LOGIC | 240 |
|
| 151 |
+
| TEST_MOCK | 240 |
|
| 152 |
+
| SAFE_CODE | 240 |
|
| 153 |
+
|
| 154 |
+
### Training Hyperparameters
|
| 155 |
+
- batch_size: (16, 16)
|
| 156 |
+
- num_epochs: (1, 1)
|
| 157 |
+
- max_steps: -1
|
| 158 |
+
- sampling_strategy: oversampling
|
| 159 |
+
- num_iterations: 5
|
| 160 |
+
- body_learning_rate: (2e-05, 1e-05)
|
| 161 |
+
- head_learning_rate: 0.01
|
| 162 |
+
- loss: CosineSimilarityLoss
|
| 163 |
+
- distance_metric: cosine_distance
|
| 164 |
+
- margin: 0.25
|
| 165 |
+
- end_to_end: False
|
| 166 |
+
- use_amp: False
|
| 167 |
+
- warmup_proportion: 0.1
|
| 168 |
+
- l2_weight: 0.01
|
| 169 |
+
- seed: 42
|
| 170 |
+
- eval_max_steps: -1
|
| 171 |
+
- load_best_model_at_end: True
|
| 172 |
+
|
| 173 |
+
### Training Results
|
| 174 |
+
| Epoch | Step | Training Loss | Validation Loss |
|
| 175 |
+
|:------:|:----:|:-------------:|:---------------:|
|
| 176 |
+
| 0.0020 | 1 | 0.0639 | - |
|
| 177 |
+
| 0.1016 | 50 | 0.0831 | - |
|
| 178 |
+
| 0.2033 | 100 | 0.0272 | - |
|
| 179 |
+
| 0.3049 | 150 | 0.0108 | - |
|
| 180 |
+
| 0.4065 | 200 | 0.0124 | - |
|
| 181 |
+
| 0.5081 | 250 | 0.0125 | - |
|
| 182 |
+
| 0.6098 | 300 | 0.0069 | - |
|
| 183 |
+
| 0.7114 | 350 | 0.0047 | - |
|
| 184 |
+
| 0.8130 | 400 | 0.0048 | - |
|
| 185 |
+
| 0.9146 | 450 | 0.0096 | - |
|
| 186 |
+
| 1.0 | 492 | - | 0.0246 |
|
| 187 |
+
|
| 188 |
### Framework Versions
|
| 189 |
- Python: 3.12.12
|
| 190 |
- SetFit: 1.1.3
|
model.safetensors
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
size 90864192
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:07f14a301e379e2bec9340847b50bb389d2d197df126ee6baa1052364a996c02
|
| 3 |
size 90864192
|
model_head.pkl
CHANGED
|
@@ -1,3 +1,3 @@
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
-
oid sha256:
|
| 3 |
size 13191
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9405abda38afa737bd06c713716d4f43881c6914f53a12cad272d1dbccfc734a
|
| 3 |
size 13191
|