menimeni123
commited on
Commit
•
da97f49
1
Parent(s):
e70b46d
latest
Browse files- .DS_Store +0 -0
- app.py +0 -64
- config.json +37 -0
- model.joblib → label_mapping.joblib +2 -2
- model.safetensors +3 -0
- model_pruned_quantized.pt +3 -0
- requirements.txt +0 -4
- special_tokens_map.json +7 -0
- tokenizer.json +0 -0
- tokenizer_config.json +55 -0
- vocab.txt +0 -0
.DS_Store
CHANGED
Binary files a/.DS_Store and b/.DS_Store differ
|
|
app.py
DELETED
@@ -1,64 +0,0 @@
|
|
1 |
-
# app.py
|
2 |
-
import torch
|
3 |
-
import joblib
|
4 |
-
from transformers import BertTokenizer
|
5 |
-
from torch.nn.functional import softmax
|
6 |
-
|
7 |
-
# Load the tokenizer
|
8 |
-
tokenizer = BertTokenizer.from_pretrained('bert-base-uncased')
|
9 |
-
|
10 |
-
# Device configuration
|
11 |
-
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
|
12 |
-
|
13 |
-
# Load your saved model
|
14 |
-
model = joblib.load('model.joblib')
|
15 |
-
model.to(device)
|
16 |
-
model.eval()
|
17 |
-
|
18 |
-
# Class names corresponding to the labels
|
19 |
-
class_names = ["JAILBREAK", "INJECTION", "PHISHING", "SAFE"]
|
20 |
-
|
21 |
-
def preprocess(text):
|
22 |
-
# Tokenize the input text
|
23 |
-
encoding = tokenizer(
|
24 |
-
text,
|
25 |
-
truncation=True,
|
26 |
-
padding=True,
|
27 |
-
max_length=128,
|
28 |
-
return_tensors='pt'
|
29 |
-
)
|
30 |
-
return encoding
|
31 |
-
|
32 |
-
def inference(model_inputs):
|
33 |
-
"""
|
34 |
-
This function will be called for every inference request.
|
35 |
-
"""
|
36 |
-
try:
|
37 |
-
# Get the text input
|
38 |
-
text = model_inputs.get('text', None)
|
39 |
-
if text is None:
|
40 |
-
return {'message': 'No text provided for inference.'}
|
41 |
-
|
42 |
-
# Preprocess the text
|
43 |
-
encoding = preprocess(text)
|
44 |
-
input_ids = encoding['input_ids'].to(device)
|
45 |
-
attention_mask = encoding['attention_mask'].to(device)
|
46 |
-
|
47 |
-
# Perform inference
|
48 |
-
with torch.no_grad():
|
49 |
-
outputs = model(input_ids, attention_mask=attention_mask)
|
50 |
-
logits = outputs.logits
|
51 |
-
probabilities = softmax(logits, dim=-1)
|
52 |
-
confidence, predicted_class = torch.max(probabilities, dim=-1)
|
53 |
-
|
54 |
-
# Prepare the response
|
55 |
-
predicted_label = class_names[predicted_class.item()]
|
56 |
-
confidence_score = confidence.item()
|
57 |
-
|
58 |
-
return {
|
59 |
-
'classification': predicted_label,
|
60 |
-
'confidence': confidence_score
|
61 |
-
}
|
62 |
-
|
63 |
-
except Exception as e:
|
64 |
-
return {'error': str(e)}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
config.json
ADDED
@@ -0,0 +1,37 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"_name_or_path": "distilbert-base-uncased",
|
3 |
+
"activation": "gelu",
|
4 |
+
"architectures": [
|
5 |
+
"DistilBertForSequenceClassification"
|
6 |
+
],
|
7 |
+
"attention_dropout": 0.1,
|
8 |
+
"dim": 768,
|
9 |
+
"dropout": 0.1,
|
10 |
+
"hidden_dim": 3072,
|
11 |
+
"id2label": {
|
12 |
+
"0": "LABEL_0",
|
13 |
+
"1": "LABEL_1",
|
14 |
+
"2": "LABEL_2",
|
15 |
+
"3": "LABEL_3"
|
16 |
+
},
|
17 |
+
"initializer_range": 0.02,
|
18 |
+
"label2id": {
|
19 |
+
"LABEL_0": 0,
|
20 |
+
"LABEL_1": 1,
|
21 |
+
"LABEL_2": 2,
|
22 |
+
"LABEL_3": 3
|
23 |
+
},
|
24 |
+
"max_position_embeddings": 512,
|
25 |
+
"model_type": "distilbert",
|
26 |
+
"n_heads": 12,
|
27 |
+
"n_layers": 6,
|
28 |
+
"pad_token_id": 0,
|
29 |
+
"problem_type": "single_label_classification",
|
30 |
+
"qa_dropout": 0.1,
|
31 |
+
"seq_classif_dropout": 0.2,
|
32 |
+
"sinusoidal_pos_embds": false,
|
33 |
+
"tie_weights_": true,
|
34 |
+
"torch_dtype": "float32",
|
35 |
+
"transformers_version": "4.44.2",
|
36 |
+
"vocab_size": 30522
|
37 |
+
}
|
model.joblib → label_mapping.joblib
RENAMED
@@ -1,3 +1,3 @@
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
-
oid sha256:
|
3 |
-
size
|
|
|
1 |
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:8ebe0c69f1c4ae5bd54fa3fa15e087b52dd6eb9ec51f725d3de59ee783580001
|
3 |
+
size 66
|
model.safetensors
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:2371fa66c3e53554ee383aa353152665cf37173974a083dd0b02a5a1dd684af4
|
3 |
+
size 267838720
|
model_pruned_quantized.pt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:ebaebf589930938493f6bfb60e87963f0af6013f0450fa64a3d99a1a5ed44ab6
|
3 |
+
size 138717586
|
requirements.txt
DELETED
@@ -1,4 +0,0 @@
|
|
1 |
-
# requirements.txt
|
2 |
-
torch
|
3 |
-
transformers
|
4 |
-
joblib
|
|
|
|
|
|
|
|
|
|
special_tokens_map.json
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
{
|
2 |
+
"cls_token": "[CLS]",
|
3 |
+
"mask_token": "[MASK]",
|
4 |
+
"pad_token": "[PAD]",
|
5 |
+
"sep_token": "[SEP]",
|
6 |
+
"unk_token": "[UNK]"
|
7 |
+
}
|
tokenizer.json
ADDED
The diff for this file is too large to render.
See raw diff
|
|
tokenizer_config.json
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
"100": {
|
12 |
+
"content": "[UNK]",
|
13 |
+
"lstrip": false,
|
14 |
+
"normalized": false,
|
15 |
+
"rstrip": false,
|
16 |
+
"single_word": false,
|
17 |
+
"special": true
|
18 |
+
},
|
19 |
+
"101": {
|
20 |
+
"content": "[CLS]",
|
21 |
+
"lstrip": false,
|
22 |
+
"normalized": false,
|
23 |
+
"rstrip": false,
|
24 |
+
"single_word": false,
|
25 |
+
"special": true
|
26 |
+
},
|
27 |
+
"102": {
|
28 |
+
"content": "[SEP]",
|
29 |
+
"lstrip": false,
|
30 |
+
"normalized": false,
|
31 |
+
"rstrip": false,
|
32 |
+
"single_word": false,
|
33 |
+
"special": true
|
34 |
+
},
|
35 |
+
"103": {
|
36 |
+
"content": "[MASK]",
|
37 |
+
"lstrip": false,
|
38 |
+
"normalized": false,
|
39 |
+
"rstrip": false,
|
40 |
+
"single_word": false,
|
41 |
+
"special": true
|
42 |
+
}
|
43 |
+
},
|
44 |
+
"clean_up_tokenization_spaces": true,
|
45 |
+
"cls_token": "[CLS]",
|
46 |
+
"do_lower_case": true,
|
47 |
+
"mask_token": "[MASK]",
|
48 |
+
"model_max_length": 512,
|
49 |
+
"pad_token": "[PAD]",
|
50 |
+
"sep_token": "[SEP]",
|
51 |
+
"strip_accents": null,
|
52 |
+
"tokenize_chinese_chars": true,
|
53 |
+
"tokenizer_class": "DistilBertTokenizer",
|
54 |
+
"unk_token": "[UNK]"
|
55 |
+
}
|
vocab.txt
ADDED
The diff for this file is too large to render.
See raw diff
|
|