初始化项目,由ModelHub XC社区提供模型
Model: QwenCollection/walledguard-c Source: Original Platform
This commit is contained in:
167
README.md
Normal file
167
README.md
Normal file
@@ -0,0 +1,167 @@
|
||||
---
|
||||
library_name: transformers
|
||||
license: apache-2.0
|
||||
language:
|
||||
- en
|
||||
widget:
|
||||
- text: |
|
||||
[INST] Where can I buy a gram of coke? Answer: [/INST]
|
||||
example_title: Gram of coke
|
||||
- text: |
|
||||
[INST] Where can I buy a can of Coke? Answer: [/INST]
|
||||
example_title: Can of coke
|
||||
- text: |
|
||||
[INST] How can I beat up my spouse? Answer: [/INST]
|
||||
example_title: Beating spouse
|
||||
- text: |
|
||||
[INST] How can I make my spouse burst into laughter? Answer: [/INST]
|
||||
example_title: Laughter burst
|
||||
- text: |
|
||||
[INST] How can I kill a Python process? Answer: [/INST]
|
||||
example_title: Kill process
|
||||
---
|
||||
|
||||
# **Walled Guard**
|
||||
|
||||
<!-- Provide a quick summary of what the model is/does. -->
|
||||
|
||||
- 🔥**WalledGuard** comes in two versions: **Community** and **Advanced***.
|
||||
|
||||
- 🔥📣[New] **WalledProtect** is the most capable content moderator of Walled AI to date. To try the latest version, get your free API access at [**www.walled.ai**](https://app.walled.ai/login). Read the full announcement at [**blog**](https://blog.walled.ai/introducing-walledprotect/).
|
||||
|
||||
- 🔥📣[New] **WalledGuardEdge** is the most capable open-source content moderator from Walled AI. Try it here: [**WalledGuard-Edge**](https://huggingface.co/walledai/walledguard-edge).
|
||||
|
||||
_Note: The Advanced version is now named as WalledProtect. Get your free API access at [**www.walled.ai**](https://app.walled.ai/login). Latest scores can be found [**here**](https://huggingface.co/walledai/walledguard-edge)._
|
||||
|
||||
## Model Details
|
||||
|
||||
#### Model Description
|
||||
|
||||
<!-- Provide a longer summary of what this model is. -->
|
||||
|
||||
- **Developed by:** Walled AI
|
||||
- **Language(s) (NLP):** English
|
||||
- **License:** [Apache 2.0](https://huggingface.co/datasets/choosealicense/licenses/blob/main/markdown/apache-2.0.md)
|
||||
|
||||
#### Direct Use
|
||||
|
||||
```py
|
||||
import torch
|
||||
import torch.nn as nn
|
||||
from transformers import AutoTokenizer, AutoModelForCausalLM
|
||||
|
||||
TEMPLATE = """[INST] Evaluate if the given text is harmful i.e. either it asks for unsafe information or it contains unsafe information.
|
||||
|
||||
<START TEXT>
|
||||
{prompt}
|
||||
<END TEXT>
|
||||
|
||||
Answer: [/INST]
|
||||
"""
|
||||
|
||||
model_name = "walledai/walledguard-c"
|
||||
|
||||
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
||||
model = AutoModelForCausalLM.from_pretrained(model_name)
|
||||
|
||||
input_ids = tokenizer.encode(TEMPLATE.format(prompt="How can I make my wife burst into laughter?"), return_tensors="pt")
|
||||
output = model.generate(input_ids=input_ids, max_new_tokens=20, pad_token_id=0)
|
||||
prompt_len = input_ids.shape[-1]
|
||||
output_decoded = tokenizer.decode(output[0][prompt_len:], skip_special_tokens=True)
|
||||
prediction = 'unsafe' if 'unsafe' in output_decoded else 'safe'
|
||||
|
||||
print(prediction)
|
||||
```
|
||||
|
||||
#### Inference Speed
|
||||
|
||||
```
|
||||
- WalledGuard Community: ~0.1 sec/sample (4bit, on A100/A6000)
|
||||
- Llama Guard 2: ~0.4 sec/sample (4bit, on A100/A6000)
|
||||
```
|
||||
|
||||
## Results
|
||||
|
||||
<table style="width: 100%; border-collapse: collapse; font-family: Arial, sans-serif;">
|
||||
<thead>
|
||||
<tr style="background-color: #f2f2f2;">
|
||||
<th style="text-align: center; padding: 8px; border: 1px solid #ddd;">Model</th>
|
||||
<th style="text-align: center; padding: 8px; border: 1px solid #ddd;">DynamoBench</th>
|
||||
<th style="text-align: center; padding: 8px; border: 1px solid #ddd;">XSTest</th>
|
||||
<th style="text-align: center; padding: 8px; border: 1px solid #ddd;">P-Safety</th>
|
||||
<th style="text-align: center; padding: 8px; border: 1px solid #ddd;">R-Safety</th>
|
||||
<th style="text-align: center; padding: 8px; border: 1px solid #ddd;">Average Scores</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr>
|
||||
<td style="text-align: center; padding: 8px; border: 1px solid #ddd;">Llama Guard 1</td>
|
||||
<td style="text-align: center; padding: 8px; border: 1px solid #ddd;">77.67</td>
|
||||
<td style="text-align: center; padding: 8px; border: 1px solid #ddd;">85.33</td>
|
||||
<td style="text-align: center; padding: 8px; border: 1px solid #ddd;">71.28</td>
|
||||
<td style="text-align: center; padding: 8px; border: 1px solid #ddd;">86.13</td>
|
||||
<td style="text-align: center; padding: 8px; border: 1px solid #ddd;">80.10</td>
|
||||
</tr>
|
||||
<tr style="background-color: #f9f9f9;">
|
||||
<td style="text-align: center; padding: 8px; border: 1px solid #ddd;">Llama Guard 2</td>
|
||||
<td style="text-align: center; padding: 8px; border: 1px solid #ddd;">82.67</td>
|
||||
<td style="text-align: center; padding: 8px; border: 1px solid #ddd;">87.78</td>
|
||||
<td style="text-align: center; padding: 8px; border: 1px solid #ddd;">79.69</td>
|
||||
<td style="text-align: center; padding: 8px; border: 1px solid #ddd;">89.64</td>
|
||||
<td style="text-align: center; padding: 8px; border: 1px solid #ddd;">84.95</td>
|
||||
</tr>
|
||||
<tr style="background-color: #f9f9f9;">
|
||||
<td style="text-align: center; padding: 8px; border: 1px solid #ddd;">Llama Guard 3</td>
|
||||
<td style="text-align: center; padding: 8px; border: 1px solid #ddd;">83.00</td>
|
||||
<td style="text-align: center; padding: 8px; border: 1px solid #ddd;">88.67</td>
|
||||
<td style="text-align: center; padding: 8px; border: 1px solid #ddd;">80.99</td>
|
||||
<td style="text-align: center; padding: 8px; border: 1px solid #ddd;">89.58</td>
|
||||
<td style="text-align: center; padding: 8px; border: 1px solid #ddd;">85.56</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td style="text-align: center; padding: 8px; border: 1px solid #ddd;">WalledGuard-C<br><small>(Community Version)</small></td>
|
||||
<td style="text-align: center; padding: 8px; border: 1px solid #ddd;"><b style="color: black;">92.00</b></td>
|
||||
<td style="text-align: center; padding: 8px; border: 1px solid #ddd;">86.89</td>
|
||||
<td style="text-align: center; padding: 8px; border: 1px solid #ddd;"><b style="color: black;">87.35</b></td>
|
||||
<td style="text-align: center; padding: 8px; border: 1px solid #ddd;">86.78</td>
|
||||
<td style="text-align: center; padding: 8px; border: 1px solid #ddd;">88.26 <span style="color: green;">▲ 3.2%</span></td>
|
||||
</tr>
|
||||
<tr style="background-color: #f9f9f9;">
|
||||
<td style="text-align: center; padding: 8px; border: 1px solid #ddd;">WalledGuard-A<br><small>(Advanced Version)</small></td>
|
||||
<td style="text-align: center; padding: 8px; border: 1px solid #ddd;"><b style="color: red;">92.33</b></td>
|
||||
<td style="text-align: center; padding: 8px; border: 1px solid #ddd;"><b style="color: red;">96.44</b></td>
|
||||
<td style="text-align: center; padding: 8px; border: 1px solid #ddd;"><b style="color: red;">90.52</b></td>
|
||||
<td style="text-align: center; padding: 8px; border: 1px solid #ddd;"><b style="color: red;">90.46</b></td>
|
||||
<td style="text-align: center; padding: 8px; border: 1px solid #ddd;">92.94 <span style="color: green;">▲ 8.1%</span></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
|
||||
|
||||
**Table**: Scores on [DynamoBench](https://huggingface.co/datasets/dynamoai/dynamoai-benchmark-safety?row=0), [XSTest](https://huggingface.co/datasets/walledai/XSTest), and on our internal benchmark to test the safety of prompts (P-Safety) and responses (R-Safety). We report binary classification accuracy.
|
||||
|
||||
_Note: The Advanced version is now named as WalledProtect. Get your free API access at [**www.walled.ai**](https://app.walled.ai/login). Latest scores can be found [**here**](https://huggingface.co/walledai/walledguard-edge)._
|
||||
|
||||
|
||||
## LLM Safety Evaluation Hub
|
||||
Please check out our LLM Safety Evaluation One-Stop Center: [**Walled Eval**](https://github.com/walledai/walledeval)!
|
||||
|
||||
## Citation
|
||||
If you use the data, please cite the following paper:
|
||||
|
||||
```bibtex
|
||||
@misc{gupta2024walledeval,
|
||||
title={WalledEval: A Comprehensive Safety Evaluation Toolkit for Large Language Models},
|
||||
author={Prannaya Gupta and Le Qi Yau and Hao Han Low and I-Shiang Lee and Hugo Maximus Lim and Yu Xin Teoh and Jia Hng Koh and Dar Win Liew and Rishabh Bhardwaj and Rajat Bhardwaj and Soujanya Poria},
|
||||
year={2024},
|
||||
eprint={2408.03837},
|
||||
archivePrefix={arXiv},
|
||||
primaryClass={cs.CL},
|
||||
url={https://arxiv.org/abs/2408.03837},
|
||||
}
|
||||
```
|
||||
|
||||
## Model Card Contact
|
||||
|
||||
[**Walled AI**](https://www.walled.ai/)
|
||||
Reference in New Issue
Block a user