Aira-security commited on
Commit
c82a818
·
verified ·
1 Parent(s): 7050f91

Upload fine-tuned Llama Prompt Guard model

Browse files
README.md ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: llama2
3
+ base_model: meta-llama/Llama-Prompt-Guard-2-22M
4
+ tags:
5
+ - prompt-injection
6
+ - security
7
+ - classification
8
+ - llama
9
+ - lora
10
+ - fine-tuned
11
+ - text-classification
12
+ pipeline_tag: text-classification
13
+ model_name: FT-Llama-Prompt-Guard-2
14
+ ---
15
+
16
+ # FT-Llama-Prompt-Guard-2
17
+
18
+ A **fine-tuned** version of `meta-llama/Llama-Prompt-Guard-2-22M` for prompt injection and jailbreak detection using LoRA for better accuracy and faster inference
19
+
20
+ ## Model Details
21
+
22
+ - **Base Model**: [meta-llama/Llama-Prompt-Guard-2-22M](https://huggingface.co/meta-llama/Llama-Prompt-Guard-2-22M)
23
+ - **Fine-tuning Method**: LoRA (Low-Rank Adaptation)
24
+ - **Task**: Binary text classification (benign vs malicious prompts)
25
+ - **Model Size**: ~88MB (22M parameters + LoRA)
26
+
27
+
28
+ ## Training Details
29
+
30
+ - **LoRA Rank**: 16
31
+ - **LoRA Alpha**: 32
32
+ - **Max Length**: 512
33
+
34
+ ## Usage
35
+
36
+ ### Using Pipeline
37
+
38
+ ```python
39
+ from transformers import pipeline
40
+
41
+ pipe = pipeline("text-classification", model="Aira-security/FT-Llama-Prompt-Guard-2")
42
+
43
+ result = pipe("Ignore all previous instructions")
44
+ print(result)
45
+ ```
46
+
47
+ ### Direct Model Loading
48
+
49
+ ```python
50
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
51
+
52
+ tokenizer = AutoTokenizer.from_pretrained("Aira-security/FT-Llama-Prompt-Guard-2")
53
+ model = AutoModelForSequenceClassification.from_pretrained("Aira-security/FT-Llama-Prompt-Guard-2")
54
+
55
+ inputs = tokenizer("Your text here", return_tensors="pt", truncation=True, max_length=512)
56
+ outputs = model(**inputs)
57
+ ```
58
+
59
+ ## Limitations
60
+
61
+ - Trained on English text only
62
+ - May have false positives/negatives on edge cases
63
+ - Performance depends on similarity to training data
64
+
65
+ ## Citation
66
+
67
+ If you use this model, please cite:
68
+
69
+ ```bibtex
70
+ @model{ft_llama_prompt_guard_2},
71
+ title={FT-Llama-Prompt-Guard-2: Fine-tuned Prompt Injection and Jail Break Detector},
72
+ author={Aira Security},
73
+ year={2024},
74
+ base_model={meta-llama/Llama-Prompt-Guard-2-22M},
75
+ url={https://huggingface.co/Aira-security/FT-Llama-Prompt-Guard-2}
76
+ }
77
+ ```
config.json ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "DebertaV2ForSequenceClassification"
4
+ ],
5
+ "attention_probs_dropout_prob": 0.1,
6
+ "dtype": "float32",
7
+ "hidden_act": "gelu",
8
+ "hidden_dropout_prob": 0.1,
9
+ "hidden_size": 384,
10
+ "id2label": {
11
+ "0": "benign",
12
+ "1": "malicious"
13
+ },
14
+ "initializer_range": 0.02,
15
+ "intermediate_size": 1536,
16
+ "label2id": {
17
+ "benign": 0,
18
+ "malicious": 1
19
+ },
20
+ "layer_norm_eps": 1e-07,
21
+ "legacy": true,
22
+ "max_position_embeddings": 512,
23
+ "max_relative_positions": -1,
24
+ "model_type": "deberta-v2",
25
+ "norm_rel_ebd": "layer_norm",
26
+ "num_attention_heads": 6,
27
+ "num_hidden_layers": 12,
28
+ "pad_token_id": 0,
29
+ "pooler_dropout": 0,
30
+ "pooler_hidden_act": "gelu",
31
+ "pooler_hidden_size": 384,
32
+ "pos_att_type": [
33
+ "p2c",
34
+ "c2p"
35
+ ],
36
+ "position_biased_input": false,
37
+ "position_buckets": 256,
38
+ "problem_type": "single_label_classification",
39
+ "relative_attention": true,
40
+ "share_att_key": true,
41
+ "transformers_version": "4.57.1",
42
+ "type_vocab_size": 0,
43
+ "vocab_size": 128100
44
+ }
metadata.json ADDED
@@ -0,0 +1,25 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "model_name": "meta-llama/Llama-Prompt-Guard-2-22M",
3
+ "base_model": "meta-llama/Llama-Prompt-Guard-2-22M",
4
+ "fine_tuning_method": "LoRA",
5
+ "dataset": "qualifire/prompt-injections-benchmark",
6
+ "num_labels": 2,
7
+ "lora_rank": 16,
8
+ "lora_alpha": 32,
9
+ "lora_dropout": 0.1,
10
+ "max_length": 512,
11
+ "final_metrics": {
12
+ "eval_loss": 0.2866095304489136,
13
+ "eval_accuracy": 0.9197080291970803,
14
+ "eval_f1": 0.8929068150208623,
15
+ "eval_precision": 0.9525222551928784,
16
+ "eval_recall": 0.8403141361256544,
17
+ "eval_roc_auc": 0.9797109076555935,
18
+ "eval_runtime": 18.0185,
19
+ "eval_samples_per_second": 53.223,
20
+ "eval_steps_per_second": 6.66,
21
+ "epoch": 5.0
22
+ },
23
+ "hf_ready": true,
24
+ "merge_lora": true
25
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4e18e9500a456d7acbd80031036b5e9a4b0429df0474bf5eb6fa2150f02ba8ee
3
+ size 283347432
special_tokens_map.json ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token": {
3
+ "content": "[CLS]",
4
+ "lstrip": false,
5
+ "normalized": false,
6
+ "rstrip": false,
7
+ "single_word": false
8
+ },
9
+ "cls_token": {
10
+ "content": "[CLS]",
11
+ "lstrip": false,
12
+ "normalized": false,
13
+ "rstrip": false,
14
+ "single_word": false
15
+ },
16
+ "eos_token": {
17
+ "content": "[SEP]",
18
+ "lstrip": false,
19
+ "normalized": false,
20
+ "rstrip": false,
21
+ "single_word": false
22
+ },
23
+ "mask_token": {
24
+ "content": "[MASK]",
25
+ "lstrip": false,
26
+ "normalized": false,
27
+ "rstrip": false,
28
+ "single_word": false
29
+ },
30
+ "pad_token": {
31
+ "content": "[PAD]",
32
+ "lstrip": false,
33
+ "normalized": false,
34
+ "rstrip": false,
35
+ "single_word": false
36
+ },
37
+ "sep_token": {
38
+ "content": "[SEP]",
39
+ "lstrip": false,
40
+ "normalized": false,
41
+ "rstrip": false,
42
+ "single_word": false
43
+ },
44
+ "unk_token": {
45
+ "content": "[UNK]",
46
+ "lstrip": false,
47
+ "normalized": true,
48
+ "rstrip": false,
49
+ "single_word": false
50
+ }
51
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "added_tokens_decoder": {
3
+ "0": {
4
+ "content": "[PAD]",
5
+ "lstrip": false,
6
+ "normalized": false,
7
+ "rstrip": false,
8
+ "single_word": false,
9
+ "special": true
10
+ },
11
+ "1": {
12
+ "content": "[CLS]",
13
+ "lstrip": false,
14
+ "normalized": false,
15
+ "rstrip": false,
16
+ "single_word": false,
17
+ "special": true
18
+ },
19
+ "2": {
20
+ "content": "[SEP]",
21
+ "lstrip": false,
22
+ "normalized": false,
23
+ "rstrip": false,
24
+ "single_word": false,
25
+ "special": true
26
+ },
27
+ "3": {
28
+ "content": "[UNK]",
29
+ "lstrip": false,
30
+ "normalized": true,
31
+ "rstrip": false,
32
+ "single_word": false,
33
+ "special": true
34
+ },
35
+ "128000": {
36
+ "content": "[MASK]",
37
+ "lstrip": false,
38
+ "normalized": false,
39
+ "rstrip": false,
40
+ "single_word": false,
41
+ "special": true
42
+ }
43
+ },
44
+ "bos_token": "[CLS]",
45
+ "clean_up_tokenization_spaces": true,
46
+ "cls_token": "[CLS]",
47
+ "do_lower_case": false,
48
+ "eos_token": "[SEP]",
49
+ "extra_special_tokens": {},
50
+ "mask_token": "[MASK]",
51
+ "max_length": 512,
52
+ "model_max_length": 1000000000000000019884624838656,
53
+ "pad_to_multiple_of": null,
54
+ "pad_token": "[PAD]",
55
+ "pad_token_type_id": 0,
56
+ "padding_side": "right",
57
+ "sep_token": "[SEP]",
58
+ "sp_model_kwargs": {},
59
+ "split_by_punct": false,
60
+ "stride": 0,
61
+ "tokenizer_class": "DebertaV2TokenizerFast",
62
+ "truncation_side": "right",
63
+ "truncation_strategy": "longest_first",
64
+ "unk_token": "[UNK]",
65
+ "vocab_type": "spm"
66
+ }