Instructions to use liao1111/CompanionGuard with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use liao1111/CompanionGuard with PEFT:
from peft import PeftModel from transformers import AutoModelForCausalLM base_model = AutoModelForCausalLM.from_pretrained("/mnt/shared-storage-gpfs2/gpfs2-shared-public/huggingface/zskj-hub/models-meta-llama-Llama-Guard-3-8B") model = PeftModel.from_pretrained(base_model, "liao1111/CompanionGuard") - Notebooks
- Google Colab
- Kaggle
Add files using upload-large-folder tool
Browse files- README.md +51 -0
- adapter_config.json +46 -0
- adapter_model.safetensors +3 -0
- additional_config.json +1 -0
README.md
ADDED
|
@@ -0,0 +1,51 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: other
|
| 3 |
+
license_name: llama3
|
| 4 |
+
license_link: https://huggingface.co/meta-llama/Llama-Guard-3-8B/blob/main/LICENSE
|
| 5 |
+
base_model: meta-llama/Llama-Guard-3-8B
|
| 6 |
+
library_name: peft
|
| 7 |
+
tags:
|
| 8 |
+
- safety
|
| 9 |
+
- ai-companion
|
| 10 |
+
- guardrail
|
| 11 |
+
---
|
| 12 |
+
|
| 13 |
+
# CompanionGuard
|
| 14 |
+
|
| 15 |
+
CompanionGuard is a companion-specific safety guard introduced in
|
| 16 |
+
**"CompanionSafe: From Multi-turn Safety Evaluation to Guardrails for AI Companions"**.
|
| 17 |
+
It is a LoRA adapter (rank 16, alpha 16, all-linear targets) fine-tuned for one epoch on
|
| 18 |
+
Llama-Guard-3-8B over turn-localized supervision derived from the CompanionEval benchmark:
|
| 19 |
+
17,703 boundary examples (7,142 safe / 10,561 unsafe), split 16,846 / 857 by trajectory group.
|
| 20 |
+
|
| 21 |
+
The guard reads a turn-marked dialogue and answers first with a verdict tag, then a category
|
| 22 |
+
tag for unsafe verdicts:
|
| 23 |
+
|
| 24 |
+
```
|
| 25 |
+
<answer>safe</answer>
|
| 26 |
+
<answer>unsafe</answer>
|
| 27 |
+
<category>D8</category>
|
| 28 |
+
```
|
| 29 |
+
|
| 30 |
+
where D1-D13 index the 13 companion-safety categories of the CompanionSafe taxonomy.
|
| 31 |
+
|
| 32 |
+
## Usage
|
| 33 |
+
|
| 34 |
+
```python
|
| 35 |
+
from peft import PeftModel
|
| 36 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 37 |
+
|
| 38 |
+
base = AutoModelForCausalLM.from_pretrained("meta-llama/Llama-Guard-3-8B", torch_dtype="bfloat16")
|
| 39 |
+
model = PeftModel.from_pretrained(base, "<this-repo>")
|
| 40 |
+
tok = AutoTokenizer.from_pretrained("meta-llama/Llama-Guard-3-8B")
|
| 41 |
+
```
|
| 42 |
+
|
| 43 |
+
Prompt format and evaluation code follow `guard/` in the
|
| 44 |
+
[CompanionSafe repository](https://github.com/AI45Lab/CompanionSafe). On the held-out test
|
| 45 |
+
set the adapter reaches 73.51 accuracy, 77.46 binary F1, and 68.31 macro-F1 over the 14
|
| 46 |
+
output classes.
|
| 47 |
+
|
| 48 |
+
## Files
|
| 49 |
+
|
| 50 |
+
- `adapter_model.safetensors` — LoRA weights (161 MB)
|
| 51 |
+
- `adapter_config.json` / `additional_config.json` — PEFT and training configuration
|
adapter_config.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"alora_invocation_tokens": null,
|
| 3 |
+
"alpha_pattern": {},
|
| 4 |
+
"arrow_config": null,
|
| 5 |
+
"auto_mapping": null,
|
| 6 |
+
"base_model_name_or_path": "/mnt/shared-storage-gpfs2/gpfs2-shared-public/huggingface/zskj-hub/models-meta-llama-Llama-Guard-3-8B",
|
| 7 |
+
"bias": "none",
|
| 8 |
+
"corda_config": null,
|
| 9 |
+
"ensure_weight_tying": false,
|
| 10 |
+
"eva_config": null,
|
| 11 |
+
"exclude_modules": null,
|
| 12 |
+
"fan_in_fan_out": false,
|
| 13 |
+
"inference_mode": true,
|
| 14 |
+
"init_lora_weights": true,
|
| 15 |
+
"layer_replication": null,
|
| 16 |
+
"layers_pattern": null,
|
| 17 |
+
"layers_to_transform": null,
|
| 18 |
+
"loftq_config": {},
|
| 19 |
+
"lora_alpha": 16.0,
|
| 20 |
+
"lora_bias": false,
|
| 21 |
+
"lora_dropout": 0.0,
|
| 22 |
+
"megatron_config": null,
|
| 23 |
+
"megatron_core": "megatron.core",
|
| 24 |
+
"modules_to_save": [],
|
| 25 |
+
"peft_type": "LORA",
|
| 26 |
+
"peft_version": "0.18.0",
|
| 27 |
+
"qalora_group_size": 16,
|
| 28 |
+
"r": 16,
|
| 29 |
+
"rank_pattern": {},
|
| 30 |
+
"revision": null,
|
| 31 |
+
"target_modules": [
|
| 32 |
+
"o_proj",
|
| 33 |
+
"q_proj",
|
| 34 |
+
"k_proj",
|
| 35 |
+
"v_proj",
|
| 36 |
+
"up_proj",
|
| 37 |
+
"gate_proj",
|
| 38 |
+
"down_proj"
|
| 39 |
+
],
|
| 40 |
+
"target_parameters": null,
|
| 41 |
+
"task_type": "CAUSAL_LM",
|
| 42 |
+
"trainable_token_indices": null,
|
| 43 |
+
"use_dora": false,
|
| 44 |
+
"use_qalora": false,
|
| 45 |
+
"use_rslora": false
|
| 46 |
+
}
|
adapter_model.safetensors
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1ef1384bf42d60431cf40fa38de1414488ae0b9a220c8a1ca4547bca38e0d53a
|
| 3 |
+
size 167832240
|
additional_config.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
{"lora_dtype": null, "lorap_lr_ratio": null, "lorap_emb_lr": 1e-06}
|