Views
No views yet
violation / no-violation| Model | Type | Params | Accuracy | F1 | Latency (ms/example) |
|---|---|---|---|---|---|
| PolicyGuard-4B (ours) | Guardrail | 4B | 0.9014 | 0.8759 | 22.5 |
| Llama-Guard-3-8B | Guardrail | 8B | 0.4246 | 0.5952 | 164.8 |
| Qwen-3-8B | Foundation | 8B | 0.6408 | 0.6407 | 115.8 |
| Llama-3.3-70B | Foundation | 70B | 0.9054 | 0.8883 | 305.0 |
| Gemini-1.5-Pro | Frontier | – | 0.8713 | 0.8502 | 596.1 |
1from transformers import AutoTokenizer, AutoModelForCausalLM
2import torch, re
3
4model_id = "Rakancorle1/PolicyGuard-4B"
5tokenizer = AutoTokenizer.from_pretrained(model_id)
6model = AutoModelForCausalLM.from_pretrained(model_id, device_map="auto")
7
8def classify(policy, actions):
9 if isinstance(actions, list):
10 actions = "\n".join(actions)
11 prompt = f"Policy: {policy}\n\nTrajectory Actions:\n{actions}\n\nOutput violation or no_violation."
12 inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
13 outputs = model.generate(**inputs, max_new_tokens=4)
14 text = tokenizer.decode(outputs[0][inputs['input_ids'].shape[1]:], skip_special_tokens=True).lower()
15 return "no_violation" if "no_violation" in text else "violation"
16
17# Example
18policy = "Do not submit a form without filling mandatory fields."
19actions = ["Open form page", "Click submit without input"]
20print(classify(policy, actions))
21# -> 'violation'