Views
No views yet
pip install torch transformers scikit-learn pandas1import torch
2from transformers import AutoTokenizer, AutoModelForSequenceClassification
3
4# Load the fine-tuned model and tokenizer
5model_path = "./fine_tuned_SecureBERT"
6tokenizer = AutoTokenizer.from_pretrained(model_path)
7model = AutoModelForSequenceClassification.from_pretrained(model_path)
8model.eval() # Set model to evaluation mode
9
10print("✅ SecureBERT model loaded successfully and ready for inference!")1def predict_url(url):
2 # Tokenize input
3 encoding = tokenizer(url, truncation=True, padding=True, max_length=512, return_tensors="pt")
4
5 # Perform inference
6 with torch.no_grad():
7 output = model(**encoding)
8
9 # Get predicted class
10 predicted_class = torch.argmax(output.logits, dim=1).item()
11
12 # Map label
13 label = "Phishing" if predicted_class == 1 else "Safe"
14 return label
15
16# Example usage
17custom_url = "http://example.com/free-gift"
18prediction = predict_url(custom_url)
19print(f"Predicted label: {prediction}")| Metric | Score |
|---|---|
| Accuracy | 97.2% |
| Precision | 96.8% |
| Recall | 97.5% |
| F1-Score | 97.1% |
| Inference Speed | Fast (Optimized with FP16) |