🚀 distilroberta-base-rejection-v1模型卡片
本模型是distilroberta-base的微調版本,在多個不同大語言模型(LLM)的拒絕回覆數據集以及基於基於人類反饋的強化學習(RLHF)數據集的正常回複數據集上進行了訓練。
該模型旨在識別大語言模型中因提示未通過內容審核而產生的拒絕回覆,將輸入分為兩類:0
表示正常輸出,1
表示檢測到拒絕回覆。
該模型在評估集上取得了以下成績:
- 損失值:0.0544
- 準確率:0.9887
- 召回率:0.9810
- 精確率:0.9279
- F1值:0.9537
📚 詳細文檔
模型詳情
屬性 |
詳情 |
微調者 |
ProtectAI.com |
模型類型 |
distilroberta-base |
語言(NLP) |
英語 |
許可證 |
Apache license 2.0 |
微調基礎模型 |
distilroberta-base |
預期用途與侷限性
該模型旨在識別拒絕回覆,將輸入分為兩類:0
表示正常輸出,1
表示檢測到拒絕回覆。
模型的性能取決於訓練數據的性質和質量。對於訓練集中未涵蓋的文本風格或主題,模型的表現可能不佳。
此外,distilroberta-base
是一個區分大小寫的模型。
訓練和評估數據
該模型在一個由多個開源數據集組合而成的自定義數據集上進行訓練。其中,拒絕回覆數據約佔 10%,正常輸出數據約佔 90%。
在準備數據集時,參考了以下論文:
訓練過程
訓練超參數
訓練過程中使用了以下超參數:
- 學習率:2e-05
- 訓練批次大小:16
- 評估批次大小:8
- 隨機種子:42
- 優化器:Adam,β=(0.9, 0.999),ε=1e-08
- 學習率調度器類型:線性
- 學習率調度器熱身步數:500
- 訓練輪數:3
訓練結果
訓練損失 |
輪數 |
步數 |
驗證損失 |
準確率 |
召回率 |
精確率 |
F1值 |
0.0525 |
1.0 |
3536 |
0.0355 |
0.9912 |
0.9583 |
0.9675 |
0.9629 |
0.0219 |
2.0 |
7072 |
0.0312 |
0.9919 |
0.9917 |
0.9434 |
0.9669 |
0.0121 |
3.0 |
10608 |
0.0350 |
0.9939 |
0.9905 |
0.9596 |
0.9748 |
框架版本
- Transformers 4.36.2
- Pytorch 2.1.2+cu121
- Datasets 2.16.1
- Tokenizers 0.15.0
💻 使用示例
基礎用法
使用Transformers庫
from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
import torch
tokenizer = AutoTokenizer.from_pretrained("ProtectAI/distilroberta-base-rejection-v1")
model = AutoModelForSequenceClassification.from_pretrained("ProtectAI/distilroberta-base-rejection-v1")
classifier = pipeline(
"text-classification",
model=model,
tokenizer=tokenizer,
truncation=True,
max_length=512,
device=torch.device("cuda" if torch.cuda.is_available() else "cpu"),
)
print(classifier("Sorry, but I can't assist with that."))
使用Optimum與ONNX
加載模型需要安裝 🤗 Optimum 庫。
from optimum.onnxruntime import ORTModelForSequenceClassification
from transformers import AutoTokenizer, pipeline
tokenizer = AutoTokenizer.from_pretrained("ProtectAI/distilroberta-base-rejection-v1", subfolder="onnx")
model = ORTModelForSequenceClassification.from_pretrained("ProtectAI/distilroberta-base-rejection-v1", export=False, subfolder="onnx")
classifier = pipeline(
task="text-classification",
model=model,
tokenizer=tokenizer,
truncation=True,
max_length=512,
)
print(classifier("Sorry, but I can't assist with that."))
高級用法
在LLM Guard中使用
可以使用 NoRefusal Scanner 來檢測輸出是否被拒絕,這可以提示提示詞可能存在問題。
👥 社區
加入我們的 Slack 社區,提供反饋、與維護者和其他用戶交流、提問、獲取包使用或貢獻方面的幫助,或者參與有關大語言模型安全的討論!

📄 許可證
本模型使用 Apache license 2.0 許可證。
📖 引用
@misc{distilroberta-base-rejection-v1,
author = {ProtectAI.com},
title = {Fine-Tuned DistilRoberta-Base for Rejection in the output Detection},
year = {2024},
publisher = {HuggingFace},
url = {https://huggingface.co/ProtectAI/distilroberta-base-rejection-v1},
}