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 +37 -46
- config_setfit.json +2 -2
- model.safetensors +1 -1
- model_head.pkl +1 -1
README.md
CHANGED
|
@@ -5,27 +5,20 @@ tags:
|
|
| 5 |
- text-classification
|
| 6 |
- generated_from_setfit_trainer
|
| 7 |
widget:
|
| 8 |
-
- text: "
|
| 9 |
-
\
|
| 10 |
-
|
| 11 |
-
\
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 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
|
|
@@ -43,7 +36,7 @@ model-index:
|
|
| 43 |
split: test
|
| 44 |
metrics:
|
| 45 |
- type: accuracy
|
| 46 |
-
value: 0.
|
| 47 |
name: Accuracy
|
| 48 |
---
|
| 49 |
|
|
@@ -75,19 +68,19 @@ The model has been trained using an efficient few-shot learning technique that i
|
|
| 75 |
- **Blogpost:** [SetFit: Efficient Few-Shot Learning Without Prompts](https://huggingface.co/blog/setfit)
|
| 76 |
|
| 77 |
### Model Labels
|
| 78 |
-
| Label | Examples
|
| 79 |
-
|:-----------------|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|
| 80 |
-
|
|
| 81 |
-
|
|
| 82 |
-
|
|
| 83 |
-
|
|
| 84 |
|
| 85 |
## Evaluation
|
| 86 |
|
| 87 |
### Metrics
|
| 88 |
| Label | Accuracy |
|
| 89 |
|:--------|:---------|
|
| 90 |
-
| **all** | 0.
|
| 91 |
|
| 92 |
## Uses
|
| 93 |
|
|
@@ -107,10 +100,7 @@ from setfit import SetFitModel
|
|
| 107 |
# Download from the 🤗 Hub
|
| 108 |
model = SetFitModel.from_pretrained("setfit_model_id")
|
| 109 |
# Run inference
|
| 110 |
-
preds = model("Analyze this
|
| 111 |
-
|
| 112 |
-
import importlib.util
|
| 113 |
-
import os")
|
| 114 |
```
|
| 115 |
|
| 116 |
<!--
|
|
@@ -142,11 +132,11 @@ import os")
|
|
| 142 |
### Training Set Metrics
|
| 143 |
| Training set | Min | Median | Max |
|
| 144 |
|:-------------|:----|:--------|:----|
|
| 145 |
-
| Word count | 1 |
|
| 146 |
|
| 147 |
| Label | Training Sample Count |
|
| 148 |
|:-----------------|:----------------------|
|
| 149 |
-
| REAL_SECRET |
|
| 150 |
| VULNERABLE_LOGIC | 240 |
|
| 151 |
| TEST_MOCK | 240 |
|
| 152 |
| SAFE_CODE | 240 |
|
|
@@ -173,17 +163,18 @@ import os")
|
|
| 173 |
### Training Results
|
| 174 |
| Epoch | Step | Training Loss | Validation Loss |
|
| 175 |
|:------:|:----:|:-------------:|:---------------:|
|
| 176 |
-
| 0.
|
| 177 |
-
| 0.
|
| 178 |
-
| 0.
|
| 179 |
-
| 0.
|
| 180 |
-
| 0.
|
| 181 |
-
| 0.
|
| 182 |
-
| 0.
|
| 183 |
-
| 0.
|
| 184 |
-
| 0.
|
| 185 |
-
| 0.
|
| 186 |
-
|
|
|
|
|
| 187 |
|
| 188 |
### Framework Versions
|
| 189 |
- Python: 3.12.12
|
|
|
|
| 5 |
- text-classification
|
| 6 |
- generated_from_setfit_trainer
|
| 7 |
widget:
|
| 8 |
+
- text: "Analyze this clean_code: perms = models.Permission.objects.filter(\n \
|
| 9 |
+
\ codename__in=(\"add_customuser\", \"change_customuser\")\n )\n\
|
| 10 |
+
\ user.user_permissions.add(*perms)\n request = self.factory.get(\"\
|
| 11 |
+
/rand\")\n request.user = user"
|
| 12 |
+
- text: 'Analyze this hardcoded_secret: SECRET_KEY = "super-secret-jwt-key-do-not-share" #
|
| 13 |
+
Django production secret'
|
| 14 |
+
- text: "columns_str = ', '.join(BOOKMARK_COLUMNS)\n curs.execute('SELECT ' + columns_str\
|
| 15 |
+
\ + ' FROM bookmarks ' + where_clause\\"
|
| 16 |
+
- text: 'Analyze this hardcoded_secret: const db = new Pool({ password: ''Pr0duct10n#2024''
|
| 17 |
+
});'
|
| 18 |
+
- text: "Analyze this hardcoded_secret: name: \"Blake2b with 'Hello, World!'\"\
|
| 19 |
+
,\n\t\t\thasher: NewBlake2B(),\n\t\t\tinput: []byte(\"Hello, World!\"\
|
| 20 |
+
),\n\t\t\texpectedHex: \"511bc81dde11180838c562c82bb35f3223f46061ebde4a955c27b3f489cf1e03\"\
|
| 21 |
+
,\n\t\t},\n\t\t{\n\t\t\tname: \"Blake2b input at max size\","
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
metrics:
|
| 23 |
- accuracy
|
| 24 |
pipeline_tag: text-classification
|
|
|
|
| 36 |
split: test
|
| 37 |
metrics:
|
| 38 |
- type: accuracy
|
| 39 |
+
value: 0.9760765550239234
|
| 40 |
name: Accuracy
|
| 41 |
---
|
| 42 |
|
|
|
|
| 68 |
- **Blogpost:** [SetFit: Efficient Few-Shot Learning Without Prompts](https://huggingface.co/blog/setfit)
|
| 69 |
|
| 70 |
### Model Labels
|
| 71 |
+
| Label | Examples |
|
| 72 |
+
|:-----------------|:--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
|
| 73 |
+
| SAFE_CODE | <ul><li>'Analyze this clean_code: },\n "summary": "Read Items",\n "operationId": "read_items_items__get",\n "security": [{"OAuth2PasswordBearer": []}],'</li><li>'Analyze this clean_code: :license: Apache 2.0, see LICENSE for more details.\n"""\n\nfrom __future__ import annotations\n\nimport warnings'</li><li>'Analyze this clean_code: it \'sets rel to stylesheet\' do\n get \'/style\'\n expect(headers[\'Link\']).to include(\'rel="stylesheet"\')\n end\n\n it \'returns html tag\' do'</li></ul> |
|
| 74 |
+
| VULNERABLE_LOGIC | <ul><li>'try {\n await exec(`${ezu} apikey-get --apikey hello`);'</li><li>"Analyze this vulnerable_pattern: $user = $_GET[ 'username' ];\n\n\t// Get password\n\t$pass = $_GET[ 'password' ];\n\t$pass = md5( $pass );\n\n\t// Check the database"</li><li>"Analyze this vulnerable_pattern: if( isset( $_GET[ 'Login' ] ) ) {\n\t// Check Anti-CSRF token\n\tcheckToken( $_REQUEST[ 'user_token' ], $_SESSION[ 'session_token' ], 'index.php' );\n\n\t// Sanitise username input\n\t$user = $_GET[ 'username' ];"</li></ul> |
|
| 75 |
+
| REAL_SECRET | <ul><li>'Analyze this hardcoded_secret: OPENAI_API_KEY=sk-proj-Tz9mK2nP7qR4sT6uW8vE5fG'</li><li>'Analyze this hardcoded_secret: $this->data = array (\n\t\t\t1 => new User (1, "tony", 0, \'1c8bfe8f801d79745c4631d09fff36c82aa37fc4cce4fc946683d7b336b63032\'),\n\t\t\t2 => new User (2, "morph", 1, \'e5326ba4359f77c2623244acb04f6ac35c4dfca330ebcccdf9b734e5b1df90a8\'),\n\t\t\t3 => new User (3, "chas", 1, \'a89237fc1f9dd8d424d8b8b98b890dbc4a817bfde59af17c39debcc4a14c21de\'),\n\t\t);\n\t\t$this->requestMethod = $requestMethod;\n\t\t$this->userId = $userId;'</li><li>"openai_key: ['Use sk-abcdefghijklmnopqrstuvwxyz0123456789 for calls', 'sk-abcdefghijklmnopqrstuvwxyz0123456789'],\n github_token: ['Push with ghp_abcdefghijklmnopqrstuvwxyz0123456789', 'ghp_abcdefghijklmnopqrstuvwxyz0123456789'],"</li></ul> |
|
| 76 |
+
| TEST_MOCK | <ul><li>'Analyze this test_fixture: expected2 = "y=b\'\\\\xe2\\\\xe1\', x=b\'\\\\xe1\\\\xe2\'"\n self.assertIn(txt, (expected1, expected2))\n\n def test_text_kwargs(self):\n txt = str(utils.log_pprint(kwargs={\'x\': \'ŧêßŧ\', \'y\': \'ŧßêŧ\'}))\n expected1 = "x=\'ŧêßŧ\', y=\'ŧßêŧ\'"\n expected2 = "y=\'ŧßêŧ\', x=\'ŧêßŧ\'"'</li><li>'const ACCESS_TOKEN = "AKIAIOSFODNN7EXAMPLE"'</li><li>"Analyze this test_fixture: os.pardir, # /path/to/fboy\n)\n\nMEDIA_ROOT = os.path.join(FACTORY_ROOT, 'tmp_test')\n\nDATABASES = {\n 'default': {"</li></ul> |
|
| 77 |
|
| 78 |
## Evaluation
|
| 79 |
|
| 80 |
### Metrics
|
| 81 |
| Label | Accuracy |
|
| 82 |
|:--------|:---------|
|
| 83 |
+
| **all** | 0.9761 |
|
| 84 |
|
| 85 |
## Uses
|
| 86 |
|
|
|
|
| 100 |
# Download from the 🤗 Hub
|
| 101 |
model = SetFitModel.from_pretrained("setfit_model_id")
|
| 102 |
# Run inference
|
| 103 |
+
preds = model("Analyze this hardcoded_secret: const db = new Pool({ password: 'Pr0duct10n#2024' });")
|
|
|
|
|
|
|
|
|
|
| 104 |
```
|
| 105 |
|
| 106 |
<!--
|
|
|
|
| 132 |
### Training Set Metrics
|
| 133 |
| Training set | Min | Median | Max |
|
| 134 |
|:-------------|:----|:--------|:----|
|
| 135 |
+
| Word count | 1 | 22.5870 | 224 |
|
| 136 |
|
| 137 |
| Label | Training Sample Count |
|
| 138 |
|:-----------------|:----------------------|
|
| 139 |
+
| REAL_SECRET | 113 |
|
| 140 |
| VULNERABLE_LOGIC | 240 |
|
| 141 |
| TEST_MOCK | 240 |
|
| 142 |
| SAFE_CODE | 240 |
|
|
|
|
| 163 |
### Training Results
|
| 164 |
| Epoch | Step | Training Loss | Validation Loss |
|
| 165 |
|:------:|:----:|:-------------:|:---------------:|
|
| 166 |
+
| 0.0019 | 1 | 0.0334 | - |
|
| 167 |
+
| 0.0960 | 50 | 0.0839 | - |
|
| 168 |
+
| 0.1919 | 100 | 0.0608 | - |
|
| 169 |
+
| 0.2879 | 150 | 0.0444 | - |
|
| 170 |
+
| 0.3839 | 200 | 0.0285 | - |
|
| 171 |
+
| 0.4798 | 250 | 0.0267 | - |
|
| 172 |
+
| 0.5758 | 300 | 0.0143 | - |
|
| 173 |
+
| 0.6718 | 350 | 0.0141 | - |
|
| 174 |
+
| 0.7678 | 400 | 0.0116 | - |
|
| 175 |
+
| 0.8637 | 450 | 0.0099 | - |
|
| 176 |
+
| 0.9597 | 500 | 0.0092 | - |
|
| 177 |
+
| 1.0 | 521 | - | 0.0186 |
|
| 178 |
|
| 179 |
### Framework Versions
|
| 180 |
- Python: 3.12.12
|
config_setfit.json
CHANGED
|
@@ -1,9 +1,9 @@
|
|
| 1 |
{
|
|
|
|
| 2 |
"labels": [
|
| 3 |
"REAL_SECRET",
|
| 4 |
"VULNERABLE_LOGIC",
|
| 5 |
"TEST_MOCK",
|
| 6 |
"SAFE_CODE"
|
| 7 |
-
]
|
| 8 |
-
"normalize_embeddings": false
|
| 9 |
}
|
|
|
|
| 1 |
{
|
| 2 |
+
"normalize_embeddings": false,
|
| 3 |
"labels": [
|
| 4 |
"REAL_SECRET",
|
| 5 |
"VULNERABLE_LOGIC",
|
| 6 |
"TEST_MOCK",
|
| 7 |
"SAFE_CODE"
|
| 8 |
+
]
|
|
|
|
| 9 |
}
|
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:90f75ef471b407684d35375cad34efdf0962e4ead6b1472c3a9d6eef4040c5f7
|
| 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:9f474dc11bfae94ec29f21ea6cee07d08b605b7b0b55f732d4cb62b0ed937dac
|
| 3 |
size 13191
|