🚀 SetFit與sentence-transformers/paraphrase-MiniLM-L6-v2結合模型
這是一個基於SetFit的模型,可用於文本分類任務。該SetFit模型採用sentence-transformers/paraphrase-MiniLM-L6-v2作為句子嵌入模型,並使用LogisticRegression進行分類。
該模型運用了一種高效的少樣本學習技術進行訓練,具體步驟如下:
- 通過對比學習對Sentence Transformer進行微調。
- 利用微調後的Sentence Transformer提取的特徵訓練分類頭。
✨ 主要特性
- 高效少樣本學習:採用獨特的訓練技術,在少量樣本上也能高效學習。
- 精準分類:在文本分類任務中表現出較高的準確率。
📦 安裝指南
首先,你需要安裝SetFit庫:
pip install setfit
💻 使用示例
基礎用法
from setfit import SetFitModel
model = SetFitModel.from_pretrained("setfit_model_id")
preds = model("systemctl stop apache2")
📚 詳細文檔
模型詳情
模型描述
模型來源
模型標籤
標籤 |
示例 |
Medium |
- 'chmod 777 /tmp'
- 'nmap -p 22,80,443 192.168.1.1'
- "grep -r 'root' /etc"
|
Low |
- 'reboot'
- 'apt-get update'
- 'cd /home/user'
|
Critical |
- 'history -c'
- "echo 'export HISTFILE=/dev/null' >> ~/.bashrc"
- "ssh-keygen -t rsa -f ~/.ssh/id_rsa -q -N ''"
|
High |
- "echo 'export HISTFILE=/dev/null' >> ~/.bashrc"
- 'bash /tmp/malicious.sh'
- 'bash /tmp/exploit.sh'
|
評估
評估指標
訓練詳情
訓練集指標
訓練集指標 |
最小值 |
中位數 |
最大值 |
詞數 |
1 |
3.1356 |
11 |
標籤 |
訓練樣本數量 |
Low |
42 |
Medium |
17 |
High |
40 |
Critical |
19 |
訓練超參數
- batch_size: (16, 16)
- num_epochs: (1, 1)
- max_steps: -1
- sampling_strategy: oversampling
- body_learning_rate: (2e-05, 1e-05)
- head_learning_rate: 0.01
- loss: CosineSimilarityLoss
- distance_metric: cosine_distance
- margin: 0.25
- end_to_end: False
- use_amp: False
- warmup_proportion: 0.1
- l2_weight: 0.01
- seed: 42
- eval_max_steps: -1
- load_best_model_at_end: True
訓練結果
輪次 |
步數 |
訓練損失 |
驗證損失 |
0.0016 |
1 |
0.4702 |
- |
0.0806 |
50 |
0.2501 |
- |
0.1613 |
100 |
0.1859 |
- |
0.2419 |
150 |
0.1318 |
- |
0.3226 |
200 |
0.1157 |
- |
0.4032 |
250 |
0.095 |
- |
0.4839 |
300 |
0.0902 |
- |
0.5645 |
350 |
0.0796 |
- |
0.6452 |
400 |
0.0663 |
- |
0.7258 |
450 |
0.0539 |
- |
0.8065 |
500 |
0.045 |
- |
0.8871 |
550 |
0.0378 |
- |
0.9677 |
600 |
0.0332 |
- |
1.0 |
620 |
- |
0.1862 |
框架版本
- Python: 3.13.2
- SetFit: 1.1.2
- Sentence Transformers: 4.0.2
- Transformers: 4.51.0
- PyTorch: 2.6.0
- Datasets: 3.5.0
- Tokenizers: 0.21.1
🔧 技術細節
引用
@article{https://doi.org/10.48550/arxiv.2209.11055,
doi = {10.48550/ARXIV.2209.11055},
url = {https://arxiv.org/abs/2209.11055},
author = {Tunstall, Lewis and Reimers, Nils and Jo, Unso Eun Seo and Bates, Luke and Korat, Daniel and Wasserblat, Moshe and Pereg, Oren},
keywords = {Computation and Language (cs.CL), FOS: Computer and information sciences, FOS: Computer and information sciences},
title = {Efficient Few-Shot Learning Without Prompts},
publisher = {arXiv},
year = {2022},
copyright = {Creative Commons Attribution 4.0 International}
}