Views
No views yet
1pip install transformers torch
21from transformers import BertForSequenceClassification, BertTokenizer
2 import torch
3
4 # Replace with your Hugging Face model repo name
5 model_name = 'ElSlay/BERT-Phishing-Email-Model'
6
7 # Load the pre-trained model and tokenizer
8 model = BertForSequenceClassification.from_pretrained(model_name)
9 tokenizer = BertTokenizer.from_pretrained(model_name)
10
11 # Ensure the model is in evaluation mode
12 model.eval()
131# Input email text
2 email_text = "Your email content here"
3
4 # Tokenize and preprocess the input text
5 inputs = tokenizer(email_text, return_tensors="pt", truncation=True, padding='max_length', max_length=512)
6
7 # Make the prediction
8 with torch.no_grad():
9 outputs = model(**inputs)
10 logits = outputs.logits
11 predictions = torch.argmax(logits, dim=-1)
12
13 # Interpret the prediction
14 result = "Phishing" if predictions.item() == 1 else "Legitimate"
15 print(f"Prediction: {result}")
16