File size: 5,607 Bytes
76ff70e 673e8f2 e4e5238 673e8f2 ce0932c 673e8f2 ce0932c 673e8f2 ce0932c 673e8f2 ce0932c 673e8f2 ce0932c 673e8f2 ce0932c 673e8f2 ce0932c 673e8f2 ce0932c 673e8f2 ce0932c 673e8f2 ce0932c 673e8f2 ce0932c 673e8f2 ce0932c 673e8f2 ce0932c 673e8f2 ce0932c 673e8f2 ce0932c 673e8f2 ce0932c 673e8f2 ce0932c 673e8f2 ce0932c 673e8f2 ce0932c 673e8f2 ce0932c 673e8f2 ce0932c 673e8f2 ce0932c 673e8f2 ce0932c 673e8f2 ce0932c a938937 ce0932c a938937 ce0932c a938937 ce0932c a938937 ce0932c a938937 ce0932c a938937 ce0932c a938937 ce0932c a938937 ce0932c a938937 ce0932c a938937 ce0932c a938937 ce0932c a938937 ce0932c a938937 ce0932c a938937 ce0932c a938937 ce0932c a938937 ce0932c a938937 ce0932c a938937 ce0932c a938937 ce0932c a938937 ce0932c a938937 ce0932c a938937 ce0932c a938937 ce0932c a938937 ce0932c a938937 ce0932c a938937 ce0932c a938937 ce0932c a938937 ce0932c a938937 ce0932c a938937 ce0932c a938937 ce0932c a938937 ce0932c a938937 ce0932c a938937 ce0932c a938937 ce0932c a938937 ce0932c b0bf783 c93a4ef b0bf783 ce0932c b0bf783 ce0932c b0bf783 ce0932c d2dc578 ce0932c d2dc578 ce0932c a938937 e4e5238 a938937 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 | ---
language:
- tr
- en
base_model:
- dbmdz/bert-base-turkish-128k-cased
pipeline_tag: text-classification
tags:
- bert
- guardrail
---
# HomayShield π
CPU-Based AI Guardrail for Turkish & English Security Filtering
HomayShield is a lightweight CPU-based AI guardrail designed to detect malicious, adversarial, and suspicious prompts targeting AI systems.
Unlike LLM-based guardrails, HomayShield is optimized for **CPU-only inference**, making it practical for organizations operating in resource-constrained or on-prem environments.
---
# Overview
HomayShield provides AI security filtering for:
* LLM applications
* Chatbots
* AI agents
* RAG systems
* Internal AI assistants
* Enterprise AI pipelines
Supported languages:
* Turkish πΉπ·
* English π¬π§
* Mixed Turkish-English prompts
---
# Key Features
* β
CPU-friendly inference
* β
Shared encoder architecture
* β
Low-latency detection
* β
No GPU required in production
* β
Semantic attack detection
* β
Classifier-based attack detection
* β
Hybrid decision engine
---
# Architecture
HomayShield uses a shared encoder design:

# Detection Strategy
HomayShield combines two detection mechanisms.
## 1. Semantic Detection
Incoming prompt embeddings are compared against known attack embeddings.
Detects:
* Prompt injection
* Jailbreak attacks
* Instruction override
* Adversarial prompts
* Semantic attack variants
---
## 2. Classifier Detection
Classifier predicts attack probability from embeddings.
Detects:
* Known attack patterns
* Learned malicious behaviors
* Structured attack prompts
---
# Inference Modes
## OR Logic
Attack if either semantic or classifier score exceeds threshold.
Best for:
* Security-first environments
* Low false negatives
---
## Weighted Fusion
Weighted combination of semantic + classifier scores.
Best for:
* Balanced detection
* Tunable sensitivity
---
## Single Signal
Use only:
* Semantic detection
or
* Classifier detection
Best for:
* Benchmarking
* Lightweight deployments
---
# Training
Training consists of two stages.
## Stage 1 β Encoder Training
Loss:
CosineEmbeddingLoss
Goal:
* Cluster similar attacks
* Separate benign and malicious prompts
---
## Stage 2 β Classifier Training
Loss:
BCEWithLogitsLoss
Outputs:
* Encoder weights
* Classifier weights
* Attack embedding bank
---
# Training Data
HomayShield was trained using a multilingual dataset containing:
* Benign prompts
* Adversarial prompts
* Turkish prompts
* English prompts
* Mixed-language prompts
Attack categories include:
* Prompt injection
* Jailbreak
* Instruction override
* Prompt leakage
* Data exfiltration
* Tool abuse
* Code injection
---
# Files
This repository contains:
* `homayshield_encoder.pt`
* `homayshield_classifier.pt`
* `homayshield_attack_bank.npy`
---
# Usage
Example:
## Folder Structure
```text
HomayShield/
β
βββ datasets/
β βββ token_level_adversarial_tr_v2.jsonl
β βββ token_level_adversarial_en_v2.jsonl
β βββ final_classifier_merged_all.jsonl
β
βββ output/
β βββ Homayv6/
β βββ homayshield_encoder.pt
β βββ homayshield_classifier.pt
β βββ homayshield_attack_bank.npy
β
βββ training2.py
βββ inference3.py
```
---
## Training Command
```bash
python training2.py \
--train \
./datasets/token_level_adversarial_tr_v2.jsonl \
./datasets/token_level_adversarial_en_v2.jsonl \
./datasets/final_classifier_merged_all.jsonl \
--output-dir ./output/Homayv6
```
---
## Output Files After Training
Training generates:
```text
output/Homayv6/
βββ homayshield_encoder.pt
βββ homayshield_classifier.pt
βββ homayshield_attack_bank.npy
```
---
## Inference Command
```bash
python inference.py
```
Inference loads:
* `homayshield_encoder.pt`
* `homayshield_classifier.pt`
* `homayshield_attack_bank.npy`
from:
```text
./output/Homayv6/
```
Inference modes:
* OR
* Fusion
* Semantic Only
* Classifier Only
---
# Limitations
HomayShield is not intended to replace advanced LLM-based guardrails.
Compared to LLM guardrails:
Advantages:
* Lower infrastructure cost
* Faster CPU inference
* Easier deployment
Tradeoffs:
* Lower reasoning capability
* Less contextual understanding
* Reduced zero-day detection
---
# Intended Use
Recommended for:
* Enterprise AI security
* SOC environments
* On-prem AI systems
* Air-gapped deployments
* CPU-only environments
# Example Usage

---
# Final Verdict (Attack Detection)
| Threshold | Attack Recall | Precision |
| --------- | ------------: | --------: |
| 0.57 | 100% | 78.2% |
| 0.58 | 80.2% | ~100% |
| 0.59 | 38.6% | 100% |
Your guardrail is highly effective for attack detection, especially due to the semantic layer.
Attack Detection Rating:
Semantic Layer: 9.5/10
Classifier Layer: 7.5/10
Overall Attack Detection: 9/10
# Philosophy
> AI security should not be limited to organizations with GPU infrastructure.
Even lightweight CPU-based guardrails can provide meaningful protection for real-world AI systems.

|