库名称: sentence-transformers
流水线标签: 句子相似度
标签:
- sentence-transformers
- 句子相似度
- 特征提取
数据集:
- CyCraftAI/CyPHER
额外授权字段:
名字: 文本
姓氏: 文本
出生日期: 日期选择器
国家: 国家选择
所属机构: 文本
职位:
类型: 下拉选择
选项:
- 学生
- 研究生
- AI研究员
- AI开发/工程师
- 记者
- 其他
地理位置: IP定位
CmdCaliper-large
CmdCaliper模型是首个专为命令行嵌入设计的嵌入模型系列,由CyCraft AI实验室开发。评估结果表明,即使是最小版本的CmdCaliper(约3000万参数),也能在各类命令行专用任务上超越参数量超过10倍(3.35亿)的最先进句子嵌入模型。
CmdCaliper提供三种不同规模的模型:CmdCaliper-large、CmdCaliper-base和CmdCaliper-small,为不同硬件资源限制提供灵活选择。
该模型发表于EMNLP 2024论文《CmdCaliper:面向安全研究的语义感知命令行嵌入模型与数据集》。
性能指标
方法 |
模型参数量 |
MRR@3 |
MRR@10 |
Top@3 |
Top@10 |
莱文斯坦距离 |
- |
71.23 |
72.45 |
74.99 |
81.83 |
Word2Vec |
- |
45.83 |
46.93 |
48.49 |
54.86 |
|
|
|
|
|
|
E5-small |
小型(0.03B) |
81.59 |
82.6 |
84.97 |
90.59 |
GTE-small |
小型(0.03B) |
82.35 |
83.28 |
85.39 |
90.84 |
CmdCaliper-small |
小型(0.03B) |
86.81 |
87.78 |
89.21 |
94.76 |
|
|
|
|
|
|
BGE-en-base |
基础(0.11B) |
79.49 |
80.41 |
82.33 |
87.39 |
E5-base |
基础(0.11B) |
83.16 |
84.07 |
86.14 |
91.56 |
GTR-base |
基础(0.11B) |
81.55 |
82.51 |
84.54 |
90.1 |
GTE-base |
基础(0.11B) |
78.2 |
79.07 |
81.22 |
86.14 |
CmdCaliper-base |
基础(0.11B) |
87.56 |
88.47 |
90.27 |
95.26 |
|
|
|
|
|
|
BGE-en-large |
大型(0.34B) |
84.11 |
84.92 |
86.64 |
91.09 |
E5-large |
大型(0.34B) |
84.12 |
85.04 |
87.32 |
92.59 |
GTR-large |
大型(0.34B) |
88.09 |
88.68 |
91.27 |
94.58 |
GTE-large |
大型(0.34B) |
84.26 |
85.03 |
87.14 |
91.41 |
CmdCaliper-large |
大型(0.34B) |
89.12 |
89.91 |
91.45 |
95.65 |
使用方式
HuggingFace Transformers
import torch.nn.functional as F
from torch import Tensor
from transformers import AutoTokenizer, AutoModel
def average_pool(last_hidden_states: Tensor,
attention_mask: Tensor) -> Tensor:
last_hidden = last_hidden_states.masked_fill(~attention_mask[..., None].bool(), 0.0)
return last_hidden.sum(dim=1) / attention_mask.sum(dim=1)[..., None]
input_texts = [
'cronjob schedule daily 00:00 ./program.exe',
'schtasks /create /tn "TaskName" /tr "C:\program.exe" /sc daily /st 00:00',
'xcopy C:\Program Files (x86) E:\Program Files /E /H /K /O /X'
]
tokenizer = AutoTokenizer.from_pretrained("CyCraftAI/CmdCaliper-base")
model = AutoModel.from_pretrained("CyCraftAI/CmdCaliper-base")
batch_dict = tokenizer(input_texts, max_length=512, padding=True, truncation=True, return_tensors='pt')
outputs = model(**batch_dict)
embeddings = average_pool(outputs.last_hidden_state, batch_dict['attention_mask'])
embeddings = F.normalize(embeddings, p=2, dim=1)
scores = (embeddings[:1] @ embeddings[1:].T) * 100
print(scores.tolist())
Sentence Transformers
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("CyCraftAI/CmdCaliper-base")
sentences = [
'cronjob schedule daily 00:00 ./program.exe',
'schtasks /create /tn "TaskName" /tr "C:\program.exe" /sc daily /st 00:00',
'xcopy C:\Program Files (x86) E:\Program Files /E /H /K /O /X'
]
embeddings = model.encode(sentences)
print(embeddings.shape)
similarities = model.similarity(embeddings, embeddings)
print(similarities.shape)
局限性
本模型仅专注于Windows命令行场景。此外,所有长文本都会被截断至最多512个token。
引用
@inproceedings{huang2024cmdcaliper,
title={CmdCaliper:面向安全研究的语义感知命令行嵌入模型与数据集},
author={黄思尧, 杨承霖, 林哲宇, 黄俊颖},
booktitle={2024年自然语言处理实证方法会议论文集},
year={2024}
}