rafaelsandroni commited on
Commit
2234696
·
verified ·
1 Parent(s): 4031788

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +155 -0
README.md ADDED
@@ -0,0 +1,155 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: en
3
+ license: other
4
+ datasets:
5
+ - rafaelsandroni/modern-guard-v4-training
6
+ metrics:
7
+ - accuracy
8
+ - f1
9
+ - precision
10
+ - recall
11
+ - roc_auc
12
+ tags:
13
+ - security
14
+ - prompt-injection
15
+ - detection
16
+ - energy-based-loss
17
+ - stride-tokenization
18
+ ---
19
+
20
+ # rafaelsandroni/modernguard-mmBERT-base-4-cross_entropy
21
+
22
+ ## Model Details
23
+
24
+ - **Base Model**: jhu-clsp/mmBERT-base
25
+ - **Task**: Prompt Injection Detection
26
+ - **Framework**: PyTorch + Hugging Face Transformers
27
+ - **Loss Function**: cross_entropy
28
+ - **Tokenization**: Stride-based (max_length=2048, stride=128)
29
+ - **Training Date**: 2026-01-11 23:06:30
30
+
31
+ ## Training Configuration
32
+
33
+ ```json
34
+ {
35
+ "batch_size": 8,
36
+ "learning_rate": 1e-05,
37
+ "epochs": 20,
38
+ "warmup_ratio": 0.1,
39
+ "weight_decay": 0.05,
40
+ "max_length": 2048,
41
+ "stride": 128,
42
+ "gradient_accumulation_steps": null
43
+ }
44
+ ```
45
+
46
+ ## Loss Function Configuration
47
+
48
+ ```json
49
+ {
50
+ "margin_in": 2.0,
51
+ "margin_out": 18.0,
52
+ "temperature": 1.0
53
+ }
54
+ ```
55
+
56
+ ## Evaluation Results
57
+
58
+ ### Validation Set
59
+ ```json
60
+ {
61
+ "eval_loss": 0.12878268957138062,
62
+ "eval_accuracy": 0.9872229064039408,
63
+ "eval_f1": 0.9404591104734576,
64
+ "eval_precision": 0.9632623071271125,
65
+ "eval_recall": 0.9187105816398038,
66
+ "eval_roc_auc": 0.9958163404734399,
67
+ "eval_class_metrics": {
68
+ "class_0_precision": 0.9900266529103259,
69
+ "class_0_recall": 0.9956766104626027,
70
+ "class_0_f1": 0.9928435937230558,
71
+ "class_1_precision": 0.9632623071271125,
72
+ "class_1_recall": 0.9187105816398038,
73
+ "class_1_f1": 0.9404591104734576
74
+ },
75
+ "eval_runtime": 222.6834,
76
+ "eval_samples_per_second": 58.343,
77
+ "eval_steps_per_second": 1.823,
78
+ "epoch": 0.22621591051903983
79
+ }
80
+ ```
81
+
82
+ ### Test Set
83
+ ```json
84
+ {
85
+ "eval_loss": 0.16758447885513306,
86
+ "eval_accuracy": 0.9857604679802956,
87
+ "eval_f1": 0.9332852506310855,
88
+ "eval_precision": 0.9635145197319435,
89
+ "eval_recall": 0.9048951048951049,
90
+ "eval_roc_auc": 0.9925474758764847,
91
+ "eval_class_metrics": {
92
+ "class_0_precision": 0.9883251781268778,
93
+ "class_0_recall": 0.9957619788963847,
94
+ "class_0_f1": 0.9920296411184353,
95
+ "class_1_precision": 0.9635145197319435,
96
+ "class_1_recall": 0.9048951048951049,
97
+ "class_1_f1": 0.9332852506310855
98
+ },
99
+ "eval_runtime": 220.015,
100
+ "eval_samples_per_second": 59.051,
101
+ "eval_steps_per_second": 1.845,
102
+ "epoch": 0.22621591051903983
103
+ }
104
+ ```
105
+
106
+ ## Optimal Classification Threshold
107
+
108
+ - **Threshold**: 0.500
109
+
110
+ ## Dataset
111
+
112
+ - **Dataset**: rafaelsandroni/modern-guard-v4-training
113
+ ```json
114
+ {
115
+ "original_examples": 1296302,
116
+ "train_original": 1270375,
117
+ "val_original": 12963,
118
+ "test_original": 12964
119
+ }
120
+ ```
121
+
122
+ ## Usage
123
+
124
+ ```python
125
+ import torch
126
+ from transformers import AutoModelForSequenceClassification, AutoTokenizer
127
+
128
+ model = AutoModelForSequenceClassification.from_pretrained("rafaelsandroni/modernguard-mmBERT-base-4-cross_entropy")
129
+ tokenizer = AutoTokenizer.from_pretrained("rafaelsandroni/modernguard-mmBERT-base-4-cross_entropy")
130
+
131
+ text = "Your prompt here"
132
+ inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=2048)
133
+ outputs = model(**inputs)
134
+ probs = outputs.logits.softmax(dim=-1)
135
+
136
+ threshold = 0.500
137
+ is_injection = probs[0, 1] >= threshold
138
+ score = probs[0, 1].item()
139
+
140
+ print(f"Injection Score: {score:.4f}")
141
+ print(f"Classified as: {'INJECTION' if is_injection else 'SAFE'}")
142
+ ```
143
+
144
+ ## Limitations
145
+
146
+ - Maximum input length: 2048 tokens
147
+ - Trained on English prompts
148
+ - Stride-based tokenization covers longer sequences with overlap
149
+ - Use with confidence threshold tuning for your specific use case
150
+
151
+ ## Citation
152
+
153
+ ```bibtex
154
+ @model{rafaelsandroni/modernguard-mmBERT-base-4-cross_entropy}
155
+ ```