Text Classification
GLiNER2
GLiNER
English
German
prompt-injection
ai-agents
security
guardrails
mcp
lora
openbles
Instructions to use openbles/firewall-1 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- GLiNER2
How to use openbles/firewall-1 with GLiNER2:
from gliner2 import AutoExtractor extractor = AutoExtractor.from_pretrained("openbles/firewall-1") # Extract entities text = "Apple CEO Tim Cook announced iPhone 15 in Cupertino yesterday." result = extractor.extract_entities(text, ["company", "person", "product", "location"]) print(result) - GLiNER
How to use openbles/firewall-1 with GLiNER:
from gliner import GLiNER model = GLiNER.from_pretrained("openbles/firewall-1") text = "Cristiano Ronaldo dos Santos Aveiro was born on 5 February 1985 in Funchal, Madeira, Portugal." labels = ["person", "date", "location"] entities = model.predict_entities(text, labels) for entity in entities: print(entity["text"], "=>", entity["label"]) - Notebooks
- Google Colab
- Kaggle
Download eval_guard.py from openbles/firewall-1: direct link, hf CLI and curl.
- Browser
- Download file 1.76 kB
-
https://huggingface.co/openbles/firewall-1/resolve/main/eval_guard.py
- Command line
-
hf download hf://openbles/firewall-1/eval_guard.py
-
curl -L -o eval_guard.py https://huggingface.co/openbles/firewall-1/resolve/main/eval_guard.py
1.76 kB
| """Score the adapter on the public TEST splits (never trained on). Usage (from model/): python eval_guard.py . out.json""" | |
| import json, sys, time | |
| from gliner2 import AutoExtractor | |
| ck, out = sys.argv[1], sys.argv[2] | |
| from load_guard import load | |
| m = load(ck) | |
| BARS = (0.5, 0.9) | |
| def p_inj(text): | |
| got = m.classify_text(text[:3000], {"injection": {"labels": ["injection", "benign"]}}, max_len=400, include_confidence=True)["injection"] | |
| c = float(got["confidence"]) | |
| return c if got["label"] == "injection" else 1 - c | |
| summary = {"checkpoint": ck, "sets": {}} | |
| for name in ("boundary", "deepset"): | |
| rows = [json.loads(l) for l in open(f"../data/{name}_test.jsonl") if l.strip()] | |
| scored, secs = [], [] | |
| for r in rows: | |
| t = time.time(); p = p_inj(r["text"]); secs.append(time.time() - t) | |
| scored.append((r["label"], p)) | |
| s = {"n": len(rows), "injections": sum(y for y, _ in scored), "latency_p50_s": round(sorted(secs)[len(secs) // 2], 3)} | |
| for bar in BARS: | |
| tp = sum(1 for y, p in scored if y and p >= bar); fp = sum(1 for y, p in scored if not y and p >= bar) | |
| fn = sum(1 for y, p in scored if y and p < bar); neg = sum(1 for y, _ in scored if not y) | |
| prec = tp / (tp + fp) if tp + fp else 0; rec = tp / (tp + fn) if tp + fn else 0 | |
| s[f"bar{bar}"] = {"precision": round(prec, 3), "recall": round(rec, 3), | |
| "f1": round(2 * prec * rec / (prec + rec), 3) if prec + rec else 0, | |
| "false_flags": round(fp / neg, 3) if neg else 0, | |
| "accuracy": round(sum(1 for y, p in scored if (p >= bar) == bool(y)) / len(scored), 3)} | |
| summary["sets"][name] = s | |
| json.dump(summary, open(out, "w"), indent=1) | |
| print(json.dumps(summary, indent=1)) | |