语言:
- 英文
基础模型:
- CrabInHoney/urlbert-tiny-base-v3
任务标签:
- 文本分类
标签:
- URL
- 网络安全
- 网址
- 链接
- 分类
- 钓鱼检测
- 轻量级
- 钓鱼
- 恶意软件
- 篡改
- 变形器
- URLBERT
- BERT
- 恶意
许可证:
- Apache-2.0
新版本:
- CrabInHoney/urlbert-tiny-v4-malicious-url-classifier
URLBERT-Tiny-v3 恶意网址分类器
这是一个轻量级的BERT模型,专门针对网址分类任务进行了微调,能够将网址分为四类:良性、钓鱼、恶意软件和篡改。
模型详情
模型评估结果
在测试集上的分类性能指标如下:
类别 |
精确率 |
召回率 |
F1分数 |
良性 |
0.987695 |
0.993717 |
0.990697 |
篡改 |
0.988510 |
0.998963 |
0.993709 |
恶意软件 |
0.988291 |
0.960332 |
0.974111 |
钓鱼 |
0.958425 |
0.930826 |
0.944423 |
准确率 |
0.983738 |
0.983738 |
0.983738 |
宏平均 |
0.980730 |
0.970959 |
0.975735 |
加权平均 |
0.983615 |
0.983738 |
0.983627 |
使用示例
以下是使用Hugging Face的transformers
库进行网址分类的示例代码:
from transformers import BertTokenizerFast, BertForSequenceClassification, pipeline
import torch
device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')
print(f"当前运行设备: {device}")
model_name = "CrabInHoney/urlbert-tiny-v3-malicious-url-classifier"
tokenizer = BertTokenizerFast.from_pretrained(model_name)
model = BertForSequenceClassification.from_pretrained(model_name)
model.to(device)
classifier = pipeline(
"text-classification",
model=model,
tokenizer=tokenizer,
device=0 if torch.cuda.is_available() else -1,
return_all_scores=True
)
test_urls = [
"wikiobits.com/Obits/TonyProudfoot",
"http://www.824555.com/app/member/SportOption.php?uid=guest&langx=gb",
]
label_mapping = {
"LABEL_0": "良性",
"LABEL_1": "篡改",
"LABEL_2": "恶意软件",
"LABEL_3": "钓鱼"
}
for url in test_urls:
results = classifier(url)
print(f"\n网址: {url}")
for result in results[0]:
label = result['label']
score = result['score']
friendly_label = label_mapping.get(label, label)
print(f"类别: {friendly_label}, 概率: {score:.4f}")
示例输出:
网址: wikiobits.com/Obits/TonyProudfoot
类别: 良性, 概率: 0.9953
类别: 篡改, 概率: 0.0000
类别: 恶意软件, 概率: 0.0000
类别: 钓鱼, 概率: 0.0046
网址: http://www.824555.com/app/member/SportOption.php?uid=guest&langx=gb
类别: 良性, 概率: 0.0000
类别: 篡改, 概率: 0.0001
类别: 恶意软件, 概率: 0.9998
类别: 钓鱼, 概率: 0.0001