This is an ONNX version of the
CrabInHoney/urlbert-tiny-v4-phishing-classifier model,
which is designed to detect phishing URLs.
1from transformers import AutoTokenizer, AutoModelForSequenceClassification
2import onnxruntime as ort
3import numpy as np
4
5# Load tokenizer
6tokenizer = AutoTokenizer.from_pretrained("dviro/urlbert-onnx-mini")
7
8# Load ONNX model
9ort_session = ort.InferenceSession("phishing_detector.onnx")
10
11# Example URL
12url = "example.com"
13
14# Tokenize
15inputs = tokenizer(url, return_tensors="np", padding="max_length", truncation=True)
16input_ids = inputs["input_ids"].astype(np.int64)
17attention_mask = inputs["attention_mask"].astype(np.int64)
18token_type_ids = inputs.get("token_type_ids", np.zeros_like(input_ids)).astype(np.int64)
19
20# Run inference
21outputs = ort_session.run(
22 None,
23 {
24 "input_ids": input_ids,
25 "attention_mask": attention_mask,
26 "token_type_ids": token_type_ids
27 }
28)
29
30# Process results
31logits = outputs[0][0]
32scores = np.exp(logits) / np.sum(np.exp(logits))
33labels = ["Safe", "Phishing"]
34prediction = labels[np.argmax(scores)]
35confidence = np.max(scores)
36
37print(f"URL: {url}")
38print(f"Prediction: {prediction}")
39print(f"Confidence: {confidence:.4f}")
This model can also be used in browser applications with ONNX Runtime Web. See the example code in the accompanying GitHub repository.