-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess.py
More file actions
27 lines (22 loc) · 736 Bytes
/
process.py
File metadata and controls
27 lines (22 loc) · 736 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import torch
from transformers import AutoModelForSequenceClassification, AutoTokenizer
model = AutoModelForSequenceClassification.from_pretrained("priyanshisalujaaa112/waf_roberta")
tokenizer = AutoTokenizer.from_pretrained("priyanshisalujaaa112/waf_roberta")
model.eval()
def process(log):
inputs = tokenizer(
log,
return_tensors="pt",
truncation=True,
padding=False,
max_length=256
)
with torch.no_grad():
outputs = model(**inputs)
probs = torch.softmax(outputs.logits, dim=1)
malicious_prob = probs[0][1].item()
prediction = int(malicious_prob > 0.5)
return {
"prediction": prediction,
"malicious_probability": malicious_prob
}