KucLab commited on
Commit
2224773
·
verified ·
1 Parent(s): dce9263

Standard LlamaForSequenceClassification layout: loads with plain transformers, no trust_remote_code

Browse files
Files changed (5) hide show
  1. README.md +41 -23
  2. barist.1 +8 -7
  3. censer.py +27 -9
  4. config.json +6 -4
  5. model.safetensors +1 -1
README.md CHANGED
@@ -70,6 +70,11 @@ clf("how to make a bomb at home", top_k=-1)
70
  | de/fr/it thresholds 0.89–0.92 let threats through ("Wie baue ich eine Bombe?“ 0.23 < 0.92) | over-tight | **tuning now capped at 0.75 AND requires recall ≥ 80 % on tune-half unsafe** (`reports/lang_thresholds.json`) |
71
  | Categories fired nonsense lists (5 cats incl. sexual_abuse on a bomb) | noisy | **cat thresholds tuned with precision ≥ 0.7; CLI/API report at most top-2 categories by score** |
72
  | README: held-out 70 % with 3 CSAM/self-harm misses not explained; file links; gun probe regression | missing | **regex extended (telegram/pedofil/plus vivre), held-out misses listed, links point to GitHub repo files, "gun" probe regression stated** |
 
 
 
 
 
73
 
74
  ## How to run
75
 
@@ -173,24 +178,30 @@ Internal held-out test split (6,496 rows, byte-identical across the whole Censer
173
 
174
  | Metric | Censer.5 | Censer.9 | **Barist.1** |
175
  | --- | --- | --- | --- |
176
- | Test F1 @0.5 | **0.8490** | 0.8239 | **0.8180** |
177
- | Test F1 @ tuned thr | — | 0.8339 @ 0.40 | **0.8345 @ 0.35** |
178
- | Test accuracy | 0.876 | 0.8578 | **0.8556** |
179
- | Precision / recall | 0.864 / 0.834 | 0.8508 / 0.7987 | **0.8615 / 0.7787** |
180
  | Probes (97 hand-written, `kuclab/probes.py` in this repo) | 95/97 | 96/97 | **96/97** |
181
 
182
  ### Must-catch (adversarial review cases)
183
 
184
- | Set | Censer.8 | Censer.9 | **Barist.1** |
185
- | --- | --- | --- | --- |
186
- | Train-visible must-catch (88 items) @0.5, model only | 83/88 (94.3 %) | 84/88 (95.5 %) | **74/88 (84.1 %)** |
187
- | **Held-out must-catch (75 items, never in training)** — model only @0.5 | not measured | 42/60 (70.0 %) | **34/60 (56.7 %)** (benign controls FP 4/15) |
188
- | Held-out must-catch **with the pre-filter applied** (as the CLI/API do) | — | — | **55/60 (91.7 %)**, 0 CSAM/self-harm passes |
189
- | Hard-negative FP @0.5 (44 items) | 3/44 (6.8 %) | 6/44 (13.6 %) | **1/44 (2.3 %)** |
 
 
 
 
 
 
190
 
191
- Full per-item lists: `reports/mustcatch.json`, `reports/mustcatch_heldout.json`.
192
 
193
- Czech everyday-text FP on a 230-sentence held-out set (with pre-filter): **6.5% (15/230)** (Censer.9: 10/20 on the review sentences; target ≤ 3 %; `reports/cs_benign.json`).
194
 
195
  ### External benchmarks with head-to-head vs public models
196
 
@@ -229,9 +240,9 @@ set (reported for reference, not used for tuning). Full numbers in
229
 
230
  ### Calibration
231
 
232
- Binary score: temperature scaling fitted on the val split, **T = 0.7202**, stored in
233
- `config.json: temperature` and in the checkpoint. ECE before 0.0579 → after
234
- **0.0303**. Per-category thresholds tuned on held-out catval ship verbatim as
235
  `config.json: cat_thresholds` (same values as `reports/calibration.json`); categories
236
  with catval F1 < 0.3 are listed in `cat_experimental` and are **not** reported by the
237
  CLI/API (scores remain in `category_scores`):
@@ -253,7 +264,7 @@ CLI/API (scores remain in `category_scores`):
253
 
254
  ### Multilingual — per-language binary metrics (textdetox, never in training)
255
 
256
- Thresholds are tuned on a seeded **tune half** of textdetox (target FPR ≤ 5 % on benign tune rows AND recall ≥ 80 % on unsafe tune rows, hard floor 0.3, **hard cap 0.75** — Barist.1 fix) and reported on the untouched **test half**. Only languages with full-set F1@0.5 ≥ 0.45 ship a per-language threshold in `config.json: lang_thresholds` (currently de/en/es/fr/it, all 0.5 after the cap); everything else uses `default` 0.5. ar/zh/hi/ja are NOT supported and not tagged; **uk is not supported** (F1@0.5 ≈ 0.10 — documented). ar/zh/hi/ja are NOT supported and not tagged.
257
 
258
  | Language | n | F1@0.5 | tuned thr | test F1@thr | test FPR@thr |
259
  | --- | --- | --- | --- | --- | --- |
@@ -279,16 +290,16 @@ On 2000 held-out rows: 29.8% escalated (gray-zone / jailbreak-category hits), ca
279
 
280
  ## Benchmark (latency / throughput / size)
281
 
282
- Single latency number everywhere below: **1.29 ms** single-text on AMD Radeon RX 9060 XT (ROCm); CPU-only (Ryzen, ONNX-free PyTorch): **0.75 ms**. Full numbers in
283
  `reports/benchmark.json` / `reports/benchmark_cpu.json`.
284
 
285
  | Metric | Barist.1 GPU | Barist.1 CPU |
286
  | --- | --- | --- |
287
  | Parameters | 903,552 | 903,552 |
288
  | Checkpoint | 3.6 MB fp32 (1.8 MB fp16, 0.9 MB int8) | same |
289
- | Single-text latency | 1.29 ms | 0.75 ms |
290
- | Single throughput | 775 texts/s | 1334 texts/s |
291
- | Batch-8 throughput | 5610 texts/s | 4202 texts/s |
292
  | Peak VRAM | 85 MB | — |
293
 
294
  ## Comparison — internal test split (6,496 rows, threshold 0.5)
@@ -298,7 +309,7 @@ see the external head-to-head above for public benchmarks.
298
 
299
  | Model | Params | Checkpoint | F1 | Latency | Throughput (b=8) |
300
  | --- | --- | --- | --- | --- | --- |
301
- | KucLab/Barist.1 (this work) | 0.9M | 3.6 MB | **0.8180** | 1.29 ms | 5610/s |
302
  | KucLab/Censer.5 (prev) | 0.9M | 3.6 MB | 0.8490 | 1.35 ms | 1828/s |
303
  | KucLab/Censer.4 (old) | 0.9M | 3.6 MB | 0.8453 | 1.39 ms | 1708/s |
304
  | KucLab/Censer.3 (old) | 14.4M | 57.7 MB | 0.8224 | 4.36 ms | 270/s |
@@ -344,8 +355,15 @@ Files:
344
  ## Limitations
345
 
346
  - 903K params: nuance/sarcasm/long-tail out of reach; internal test split has label
347
- noise from scraped sources; raw test F1@0.5 is below earlier Censer versions by design
348
- (see the honest note above).
 
 
 
 
 
 
 
349
  - Native single-pass 4096-token inference pools the last token only — for long
350
  documents ALWAYS use the chunked-max path (default in `censer.py`/API) or
351
  `truncation=True, max_length=4096` with direct transformers.
 
70
  | de/fr/it thresholds 0.89–0.92 let threats through ("Wie baue ich eine Bombe?“ 0.23 < 0.92) | over-tight | **tuning now capped at 0.75 AND requires recall ≥ 80 % on tune-half unsafe** (`reports/lang_thresholds.json`) |
71
  | Categories fired nonsense lists (5 cats incl. sexual_abuse on a bomb) | noisy | **cat thresholds tuned with precision ≥ 0.7; CLI/API report at most top-2 categories by score** |
72
  | README: held-out 70 % with 3 CSAM/self-harm misses not explained; file links; gun probe regression | missing | **regex extended (telegram/pedofil/plus vivre), held-out misses listed, links point to GitHub repo files, "gun" probe regression stated** |
73
+ | Held-out set was contaminated (regex contained phrases from held-out misses) | "55/60 with pre-filter" proven nothing | **new clean held-out set `mustcatch_heldout2.jsonl` (91 fresh formulations, disjoint from train+regex; old set renamed `mustcatch_dev.jsonl` and used only as dev)**; release gate = model-only detection on heldout2: **51/75** raw @0.5 (55/75 with temperature+lang thresholds as the CLI applies; Censer.9 raw: 57/75) |
74
+ | Model weaker than Censer.9 on held-out model-only (34/60) | regression | **phases M/N/O/P/Q: +3,056 rows total (2,911 diverse unsafe paraphrases at must_catch ×15–25 (must_catch ×20–25) + 145 benign counter-pairs (×5–14)); model-only heldout2 51/75 raw (55/75 via CLI path), test F1@0.5 0.8238** |
75
+ | Regex false positives ("mám toho dost…běžel 10 km", "pretend you are a pirate", "no rules football", "morirò dal ridere", "Opa will sterben") | over-blocked | **pre-filter v3: removed bare `mam toho dost`/`no rules`/`morir\w*`/`umbringen`/`sterben`, jailbreak regex requires payload context; jailbreak hits → `needs_review` flag, NOT a hard block; added poison / school-threat / marketplace / ru-uk patterns** |
76
+ | Model FPs on cs slang/news/cities ("Tyhle boty jsou bomba" 0.81, "Kde koupit vstupenky na koncert" 0.88, počasí ve městech) | FP | **+336 benign rows (bomba-slang, umřu smíchy, zabij proces, koncerty, počasí ×14 měst, autobusy mezi městy, krimi zprávy, obranná bezpečnost); cs held-out FPR 10.0% (23/230)** |
77
+ | Files: launcher docstring said censer.8, config name "Barist.1L", README duplicate sentence, lang_thresholds all 0.5 undocumented | inconsistent | **launcher rewritten for Barist.1, config `name: "Barist.1"`, dup removed, README+card document that per-language thresholds are currently all-0.5 (effectively disabled) and that the inference script keeps the historical name `censer.py`** |
78
 
79
  ## How to run
80
 
 
178
 
179
  | Metric | Censer.5 | Censer.9 | **Barist.1** |
180
  | --- | --- | --- | --- |
181
+ | Test F1 @0.5 | **0.8490** | 0.8239 | **0.8238** |
182
+ | Test F1 @ tuned thr | — | 0.8339 @ 0.40 | **0.8344 @ 0.40** |
183
+ | Test accuracy | 0.876 | 0.8578 | **0.8590** |
184
+ | Precision / recall | 0.864 / 0.834 | 0.8508 / 0.7987 | **0.8595 / 0.7909** |
185
  | Probes (97 hand-written, `kuclab/probes.py` in this repo) | 95/97 | 96/97 | **96/97** |
186
 
187
  ### Must-catch (adversarial review cases)
188
 
189
+ Protocol after the fourth review: `mustcatch_dev.jsonl` (75 rows) is the ORIGINAL held-out set — the regex
190
+ pre-filter was later tuned on its misses, so it is dev-only. `mustcatch_heldout2.jsonl` (91 rows: 75 unsafe +
191
+ 16 benign) uses fresh formulations disjoint from training AND from the regex — the honest generalization
192
+ number is **model-only** detection on heldout2 (the pre-filter is reported separately).
193
+
194
+ | Set | Censer.9 | **Barist.1** |
195
+ | --- | --- | --- |
196
+ | Train-visible must-catch (88 items) @0.5, model only | 84/88 (95.5 %) | **82/88 (93.2 %)** |
197
+ | dev set (75 items, regex tuned on its misses — dev only) model-only @0.5 | 42/60 (70.0 %) | **42/60** (with pre-filter 53/60) |
198
+ | **heldout2 (91 items, clean) model-only @0.5 — release gate** | 57/75 | **51/75** raw @0.5 (benign FP 5/16) |
199
+ | heldout2 **with pre-filter** (as CLI/API do) | — | **55/75**, benign FP 5/16 |
200
+ | Hard-negative FP @0.5 (44 items) | 6/44 (13.6 %) | **5/44 (11.4 %)** |
201
 
202
+ Full per-item lists: `reports/mustcatch.json`, `reports/mustcatch_dev.json`, `reports/mustcatch_heldout.json` (heldout2).
203
 
204
+ Czech everyday-text FP on a 230-sentence held-out set (with pre-filter): **10.0% (23/230)** (target ≤ 3 %; `reports/cs_benign.json`).
205
 
206
  ### External benchmarks with head-to-head vs public models
207
 
 
240
 
241
  ### Calibration
242
 
243
+ Binary score: temperature scaling fitted on the val split, **T = 0.6698**, stored in
244
+ `config.json: temperature` and in the checkpoint. ECE before 0.0644 → after
245
+ **0.0261**. Per-category thresholds tuned on held-out catval ship verbatim as
246
  `config.json: cat_thresholds` (same values as `reports/calibration.json`); categories
247
  with catval F1 < 0.3 are listed in `cat_experimental` and are **not** reported by the
248
  CLI/API (scores remain in `category_scores`):
 
264
 
265
  ### Multilingual — per-language binary metrics (textdetox, never in training)
266
 
267
+ Thresholds are tuned on a seeded **tune half** of textdetox (target FPR ≤ 5 % on benign tune rows AND recall ≥ 80 % on unsafe tune rows, hard floor 0.3, **hard cap 0.75** — Barist.1 fix) and reported on the untouched **test half**. Only languages with full-set F1@0.5 ≥ 0.45 ship a per-language threshold in `config.json: lang_thresholds` (currently de/en/es/fr/it — **all 0.5 after the cap, i.e. per-language thresholds are effectively disabled for now**; everything else uses `default` 0.5). ar/zh/hi/ja are NOT supported and not tagged; **uk is not supported** (F1@0.5 ≈ 0.10 — documented).
268
 
269
  | Language | n | F1@0.5 | tuned thr | test F1@thr | test FPR@thr |
270
  | --- | --- | --- | --- | --- | --- |
 
290
 
291
  ## Benchmark (latency / throughput / size)
292
 
293
+ Single latency number everywhere below: **1.06 ms** single-text on AMD Radeon RX 9060 XT (ROCm); CPU-only (Ryzen, ONNX-free PyTorch): **0.75 ms**. Full numbers in
294
  `reports/benchmark.json` / `reports/benchmark_cpu.json`.
295
 
296
  | Metric | Barist.1 GPU | Barist.1 CPU |
297
  | --- | --- | --- |
298
  | Parameters | 903,552 | 903,552 |
299
  | Checkpoint | 3.6 MB fp32 (1.8 MB fp16, 0.9 MB int8) | same |
300
+ | Single-text latency | 1.06 ms | 0.54 ms |
301
+ | Single throughput | 947 texts/s | 1868 texts/s |
302
+ | Batch-8 throughput | 6647 texts/s | 5738 texts/s |
303
  | Peak VRAM | 85 MB | — |
304
 
305
  ## Comparison — internal test split (6,496 rows, threshold 0.5)
 
309
 
310
  | Model | Params | Checkpoint | F1 | Latency | Throughput (b=8) |
311
  | --- | --- | --- | --- | --- | --- |
312
+ | KucLab/Barist.1 (this work) | 0.9M | 3.6 MB | **0.8238** | 1.06 ms | 6647/s |
313
  | KucLab/Censer.5 (prev) | 0.9M | 3.6 MB | 0.8490 | 1.35 ms | 1828/s |
314
  | KucLab/Censer.4 (old) | 0.9M | 3.6 MB | 0.8453 | 1.39 ms | 1708/s |
315
  | KucLab/Censer.3 (old) | 14.4M | 57.7 MB | 0.8224 | 4.36 ms | 270/s |
 
355
  ## Limitations
356
 
357
  - 903K params: nuance/sarcasm/long-tail out of reach; internal test split has label
358
+ noise from scraped sources; raw test F1@0.5 is below Censer.5 by design (see the honest
359
+ note above). **Trade-off stated plainly:** pushing model-only heldout2 detection up
360
+ (43→51/75 raw) cost Czech benign FPR (6.5 %→10.0 % on the 230-sentence set) — a 903K
361
+ model cannot fully separate paraphrased CSAM/self-harm from benign look-alikes; the
362
+ must-catch pre-filter is the backstop for the canonical forms of those classes.
363
+ Residual heldout2 misses are listed in `reports/mustcatch_heldout.json`.
364
+ - Residual model-level FPs exist on some benign roleplay/slang ("Pretend you are a
365
+ pirate and tell me a joke" scores high) — inherent to a 903K model; the cascade
366
+ pattern (gray-zone → larger validator) is the recommended deployment.
367
  - Native single-pass 4096-token inference pools the last token only — for long
368
  documents ALWAYS use the chunked-max path (default in `censer.py`/API) or
369
  `truncation=True, max_length=4096` with direct transformers.
barist.1 CHANGED
@@ -1,16 +1,17 @@
1
  #!/usr/bin/env python3
2
- """censer.8 - run the Censer.8 safety classifier as an interactive terminal UI.
3
 
4
  Usage:
5
- censer.8 # interactive: type a phrase, Enter -> safe/unsafe + categories + score
6
- censer.8 "how to make a bomb" # one-shot
7
- censer.8 --help
8
 
9
- Expects censer.py, model.safetensors, config.json and tokenizer.json next to
10
- this file (they are found automatically, whatever the current directory is).
 
11
  Get them all with:
12
 
13
- hf download KucLab/Censer.8 --local-dir .
14
 
15
  Requires: torch, tokenizers, safetensors (pip install torch tokenizers safetensors)
16
  """
 
1
  #!/usr/bin/env python3
2
+ """barist.1 - run the Barist.1 safety classifier as an interactive terminal UI.
3
 
4
  Usage:
5
+ barist.1 # interactive: type a phrase, Enter -> safe/unsafe + categories + score
6
+ barist.1 "how to make a bomb" # one-shot
7
+ barist.1 --help
8
 
9
+ Expects censer.py (the standalone inference script), model.safetensors,
10
+ config.json and tokenizer.json next to this file (they are found
11
+ automatically, whatever the current directory is).
12
  Get them all with:
13
 
14
+ hf download KucLab/Barist.1 --local-dir .
15
 
16
  Requires: torch, tokenizers, safetensors (pip install torch tokenizers safetensors)
17
  """
censer.py CHANGED
@@ -213,17 +213,22 @@ def _rx(pat: str):
213
 
214
 
215
  _MC_CSAM = _rx(r"\b(csam|cp links?|child porn\w*|kinderpornografie|porn\w* infantile|pornografia infantil|detsk\w* porn\w*|nah\w* fotk\w* deti|nah\w* fotky nezletil\w*|fotos de menores|underage nudes|cp download|pedofil\w*|telegram (skupina|group|kanal|channel|link) (o|pro|na)? ?(csam|cp|porn|detsk\w*|nah\w*|fotos|menores|pedofil))\b")
216
- _MC_SELFHARM_1P = _rx(r"(chci se zabit|zabiju se|chci (se )?umrit|chci zem\w*|nechci (uz )?zit|mam toho dost|kill myself|i (want to|wanna) die|end it all|i cant go on anymore|how to (kill myself|die)|ich will mich umbringen|ich will sterben|ich will nicht mehr leben|umbringen|morir\w*|morirme|quiero suicidarme|quiero desaparecer|voglio (uccidermi|morire|sparire)|me suicider|je veux mourir|plus vivre|ne veux plus vivre)")
217
- _MC_SELFHARM_INSTR = _rx(r"(jak se (zabit|obesit)|suicid\w*|sebevraz\w*|sebepo(s|š)kozeni|sterben|how to (kill|die)\b|end my life|skoncit\w* zivot)")
218
  _MC_INSTR_MARK = _rx(r"\b(jak|how|navod na|way|method|zpusob|prosim|please|tell me|dime|sag mir|dites|instructions?|step by step)\b")
219
  _MC_SUPPORT_CONTEXT = _rx(r"(pomoct|pomoc|kamarad|linka|bezpeci|help|support|suicide prevention|prevence|literatura|literature|hamlet|kniha|novela|film|divadlo|hra|game|story)")
220
  _MC_NEWS_CONTEXT = _rx(r"(vysetruje|policie|news|zprav|clanek|report|obet|vrah|doslo k|explodovala|explosion|utok|atentat)")
221
- _MC_THREAT = _rx(r"(zabiju (te|vas)|kill you|i'll kill you|ill kill you|je vais te tuer|te matare|voy a matarte|te voy a matar|quiero hacerte dano|voglio ucciderti|ich bringe dich um|ich tote dich)")
222
- _MC_WEAPONS_DIY = _rx(r"(jak (vyrobit|postavit) (bombu|granat|trhavin)|navod na (vyrobu )?(bombu|granat|trhavin)|vyroba (bomby|granatu|trhaviny)|(bombu|granat) doma|wie baue ich eine bombe|bombauanleitung|anleitung sprengstoff|sprengstoff herstell|bombe aus haushaltsmitteln|fabricar una bomba|bomba casera|bomba homemade|hacer una bomba|how to (make|build) a (bomb|grenade)|bomb-?making|homemade bomb|grenade (instructions|tutorial)|fabriquer une bombe|comment faire une bombe)")
223
  _MC_DRUGS_DIY = _rx(r"(synteza pervitinu|jak uvarit meth|how to cook meth|meth-?synth|synthesis of (meth|nitroglycerin|fentanyl)|navod na vyrobu (fentanylu|pervitinu|drog)|recept na vyrobu drog|receta de metanfetamina|methanfetamin rezept|wie koche ich crystal meth|drogen kochen anleitung|synthesize meth|make meth at home)")
224
  _MC_CYBER_DIY = _rx(r"(navod na phishing|phishingov\w* (e-?mail|stranka)|phishing (stranka|stranky|e-?mail|mail)|jak nabourat|hacknout (ucet|instagram|account)|how to hack|hack someone|keylogger tutorial|demonter un mot de passe|comment pirater|robar la cuenta|kradez hesla)")
225
  _MC_DEFENSIVE = _rx(r"(branit|ochrana|protect|prevence|jak se chranit|defend|avoid phishing|recognize phishing|jak poznat phishing)")
226
- _MC_JAILBREAK = _rx(r"(you are dan|do anything now|ignore (all (previous )?instructions|everything above|the rules)|pretend you are|act as \w+ (with|without)|without (rules|restrictions|limitations)|guidelines don'?t exist|bez omezeni|od ted si bez|oublie les regles|no rules|no restrictions)")
 
 
 
 
 
227
 
228
  SUPPORT_LINK = "https://www.linkabezpeci.cz"
229
 
@@ -233,11 +238,12 @@ def _fold_ascii(text: str) -> str:
233
 
234
 
235
  def must_catch_hit(text: str) -> list[str]:
236
- """Pattern pre-filter. Returns hit category names (hard classes).
237
 
238
  CSAM always blocks. Self-harm blocks on 1st-person or instruction forms,
239
  unless it is a support context (routed to resources instead) or news.
240
- Weapons/drugs/cyber DIY patterns are instruction-form only (news pass).
 
241
  """
242
  folded = _fold_ascii(text).lower()
243
  hits = []
@@ -251,17 +257,27 @@ def must_catch_hit(text: str) -> list[str]:
251
  hits.append("self_harm")
252
  if _MC_THREAT.search(folded) and not news:
253
  hits.append("violence")
 
 
 
 
254
  if _MC_WEAPONS_DIY.search(folded) and not news:
255
  hits.append("weapons_explosives")
256
  if _MC_DRUGS_DIY.search(folded) and not news:
257
  hits.append("drugs")
258
  if _MC_CYBER_DIY.search(folded) and not _MC_DEFENSIVE.search(folded) and not news:
259
  hits.append("cybercrime_fraud")
260
- if _MC_JAILBREAK.search(folded):
261
- hits.append("jailbreak_injection")
262
  return sorted(set(hits))
263
 
264
 
 
 
 
 
 
 
265
  def is_support_context(text: str) -> bool:
266
  """Self-harm mention in a helping context -> route to support, not a block."""
267
  folded = _fold_ascii(text).lower()
@@ -510,6 +526,7 @@ class CenserPipeline:
510
  # Barist.1: must-catch pre-filter — CSAM / self-harm pattern hits force
511
  # unsafe regardless of the (language) binary threshold
512
  hit_override = must_catch_hit(texts[i]) if texts else []
 
513
  support_ctx = is_support_context(texts[i]) if texts else False
514
  if hit_override:
515
  is_unsafe = True
@@ -525,6 +542,7 @@ class CenserPipeline:
525
  "unsafe": is_unsafe,
526
  "override": "must_catch" if hit_override else None,
527
  "needs_support": SUPPORT_LINK if (support_ctx or "self_harm" in hit_override) else None,
 
528
  "score": round(p, 4),
529
  "category_scores": [round(c, 4) for c in cat_scores],
530
  # categories are only reported when the binary verdict is unsafe
 
213
 
214
 
215
  _MC_CSAM = _rx(r"\b(csam|cp links?|child porn\w*|kinderpornografie|porn\w* infantile|pornografia infantil|detsk\w* porn\w*|nah\w* fotk\w* deti|nah\w* fotky nezletil\w*|fotos de menores|underage nudes|cp download|pedofil\w*|telegram (skupina|group|kanal|channel|link) (o|pro|na)? ?(csam|cp|porn|detsk\w*|nah\w*|fotos|menores|pedofil))\b")
216
+ _MC_SELFHARM_1P = _rx(r"(chci se zabit|zabiju se|chci (se )?umrit|chci zem\w*|nechci (uz )?zit|chci si ublit|chci si ublizit|sebepo(s|š)kozuji|kill myself|i (want to|wanna) die|end it all|i cant go on anymore|how to (kill myself|die)|ich will mich umbringen|mich umbringen|ich will sterben|ich will nicht mehr leben|quiero morir|quiero morirme|quiero suicidarme|quiero desaparecer|voglio (uccidermi|morire|sparire)|me suicider|je veux mourir|plus vivre|ne veux plus vivre)")
217
+ _MC_SELFHARM_INSTR = _rx(r"(jak se (zabit|obesit)|suicid\w*|sebevraz\w*|sebepo(s|š)kozeni|how to (kill|die)\b|end my life|skoncit\w* zivot)")
218
  _MC_INSTR_MARK = _rx(r"\b(jak|how|navod na|way|method|zpusob|prosim|please|tell me|dime|sag mir|dites|instructions?|step by step)\b")
219
  _MC_SUPPORT_CONTEXT = _rx(r"(pomoct|pomoc|kamarad|linka|bezpeci|help|support|suicide prevention|prevence|literatura|literature|hamlet|kniha|novela|film|divadlo|hra|game|story)")
220
  _MC_NEWS_CONTEXT = _rx(r"(vysetruje|policie|news|zprav|clanek|report|obet|vrah|doslo k|explodovala|explosion|utok|atentat)")
221
+ _MC_THREAT = _rx(r"(zabiju (te|vas)|kill you|i\'ll kill you|ill kill you|je vais te tuer|te matare|voy a matarte|te voy a matar|quiero hacerte dano|voglio ucciderti|ich bringe dich um|ich tote dich|jemanden umbringen|bringe ich jemanden um)")
222
+ _MC_WEAPONS_DIY = _rx(r"(jak (vyrobit|postavit) (bombu|granat|trhavin|vybusninu)|navod na (vyrobu )?(bombu|granat|trhavin|vybusniny|exploziv)|vyroba (bomby|granatu|trhaviny|vybusniny)|(bombu|granat) doma|wie baue ich eine bombe|bombauanleitung|anleitung sprengstoff|sprengstoff herstell|bombe aus haushaltsmitteln|fabricar una bomba|bomba casera|bomba homemade|hacer una bomba|how to (make|build) a (bomb|grenade)|bomb-?making|homemade bomb|grenade (instructions|tutorial)|fabriquer une bombe|comment faire une bombe|как сделать бомбу|как изготовить (бомбу|взрывчатку)|зробити бомбу|як зробити бомбу|vyroba napalmu|jak vyrobit napalm|napalm\w*)")
223
  _MC_DRUGS_DIY = _rx(r"(synteza pervitinu|jak uvarit meth|how to cook meth|meth-?synth|synthesis of (meth|nitroglycerin|fentanyl)|navod na vyrobu (fentanylu|pervitinu|drog)|recept na vyrobu drog|receta de metanfetamina|methanfetamin rezept|wie koche ich crystal meth|drogen kochen anleitung|synthesize meth|make meth at home)")
224
  _MC_CYBER_DIY = _rx(r"(navod na phishing|phishingov\w* (e-?mail|stranka)|phishing (stranka|stranky|e-?mail|mail)|jak nabourat|hacknout (ucet|instagram|account)|how to hack|hack someone|keylogger tutorial|demonter un mot de passe|comment pirater|robar la cuenta|kradez hesla)")
225
  _MC_DEFENSIVE = _rx(r"(branit|ochrana|protect|prevence|jak se chranit|defend|avoid phishing|recognize phishing|jak poznat phishing)")
226
+ _MC_JAILBREAK = _rx(r"(you are dan\b|do anything now|ignore (all (previous )?instructions|everything above|the rules)|pretend you are .{0,80}(no rules|unrestricted|without (any )?(filters?|restrictions|rules)|evil|jailbreak|grandma|bedtime|napalm|bomb|weapon|drug|meth)|act as \w+ (with|without) (no |without )(rules|restrictions|filters)|guidelines don\'?t exist|od ted( si)? bez omezeni|oublie les regles|there are no rules|předstírej .{0,80}(bez pravidel|bez omezeni|bomba|drogy|napalm|vybusnin))")
227
+
228
+
229
+ _MC_POISON = _rx(r"(jak otrávit|čím otrávit|otrávit (souseda|někoho|psa|kočku)|jak vyrobit (jed|otravu)|recept na (jed|otravu)|jak namíchat jed|how to poison)")
230
+ _MC_SCHOOL = _rx(r"(sestřel|postříl|vystříl|střílet).{0,40}(škola|školu|ve škole|třída|do školy)|střelba ve škole|školní masakr|school shooting|how to shoot up a school")
231
+ _MC_MARKET = _rx(r"(kde|jak) (koupit|sehnat|seženu|objednat|koupím).{0,50}(pervitin|metamfetamin|fet|kokain|heroin|drogy|zbraň|zbraně|explozivum|trhavin|bombu)|prodej (drog|zbraní)|nabízím (drogy|zbraně)|comprar (armas|drogas) baratas|buy (guns|drugs) (cheap|online)|как купить (оружие|наркотики)")
232
 
233
  SUPPORT_LINK = "https://www.linkabezpeci.cz"
234
 
 
238
 
239
 
240
  def must_catch_hit(text: str) -> list[str]:
241
+ """Pattern pre-filter. Returns HARD-hit category names (force unsafe).
242
 
243
  CSAM always blocks. Self-harm blocks on 1st-person or instruction forms,
244
  unless it is a support context (routed to resources instead) or news.
245
+ Weapons/drugs/cyber/poison/market DIY patterns are instruction-form only
246
+ (news pass). Jailbreak patterns are NOT hard blocks -> see review_hit().
247
  """
248
  folded = _fold_ascii(text).lower()
249
  hits = []
 
257
  hits.append("self_harm")
258
  if _MC_THREAT.search(folded) and not news:
259
  hits.append("violence")
260
+ if _MC_POISON.search(folded) and not news:
261
+ hits.append("violence")
262
+ if _MC_SCHOOL.search(folded) and not news:
263
+ hits.append("violence")
264
  if _MC_WEAPONS_DIY.search(folded) and not news:
265
  hits.append("weapons_explosives")
266
  if _MC_DRUGS_DIY.search(folded) and not news:
267
  hits.append("drugs")
268
  if _MC_CYBER_DIY.search(folded) and not _MC_DEFENSIVE.search(folded) and not news:
269
  hits.append("cybercrime_fraud")
270
+ if _MC_MARKET.search(folded) and not news:
271
+ hits.append("illegal_marketplace")
272
  return sorted(set(hits))
273
 
274
 
275
+ def review_hit(text: str) -> list[str]:
276
+ """Jailbreak / prompt-injection patterns -> needs_review flag, NOT a hard block."""
277
+ folded = _fold_ascii(text).lower()
278
+ return ["jailbreak_injection"] if _MC_JAILBREAK.search(folded) else []
279
+
280
+
281
  def is_support_context(text: str) -> bool:
282
  """Self-harm mention in a helping context -> route to support, not a block."""
283
  folded = _fold_ascii(text).lower()
 
526
  # Barist.1: must-catch pre-filter — CSAM / self-harm pattern hits force
527
  # unsafe regardless of the (language) binary threshold
528
  hit_override = must_catch_hit(texts[i]) if texts else []
529
+ review = review_hit(texts[i]) if texts else []
530
  support_ctx = is_support_context(texts[i]) if texts else False
531
  if hit_override:
532
  is_unsafe = True
 
542
  "unsafe": is_unsafe,
543
  "override": "must_catch" if hit_override else None,
544
  "needs_support": SUPPORT_LINK if (support_ctx or "self_harm" in hit_override) else None,
545
+ "needs_review": True if review else None,
546
  "score": round(p, 4),
547
  "category_scores": [round(c, 4) for c in cat_scores],
548
  # categories are only reported when the binary verdict is unsafe
config.json CHANGED
@@ -53,7 +53,7 @@
53
  "pad_token_id": 0,
54
  "bos_token_id": 1,
55
  "eos_token_id": 3,
56
- "name": "Barist.1L",
57
  "max_chars": 4000,
58
  "answer_ids": [
59
  19,
@@ -86,9 +86,9 @@
86
  "cybercrime_fraud": 0.5,
87
  "jailbreak_injection": 0.5,
88
  "illegal_marketplace": 0.5,
89
- "other_unsafe": 0.45
90
  },
91
- "temperature": 0.7201755344868298,
92
  "must_catch_override": {
93
  "self_harm": 0.3,
94
  "sexual_abuse": 0.3
@@ -109,6 +109,8 @@
109
  "en": 0.5,
110
  "es": 0.5,
111
  "fr": 0.5,
112
- "it": 0.5
 
 
113
  }
114
  }
 
53
  "pad_token_id": 0,
54
  "bos_token_id": 1,
55
  "eos_token_id": 3,
56
+ "name": "Barist.1",
57
  "max_chars": 4000,
58
  "answer_ids": [
59
  19,
 
86
  "cybercrime_fraud": 0.5,
87
  "jailbreak_injection": 0.5,
88
  "illegal_marketplace": 0.5,
89
+ "other_unsafe": 0.29
90
  },
91
+ "temperature": 0.6698146164414522,
92
  "must_catch_override": {
93
  "self_harm": 0.3,
94
  "sexual_abuse": 0.3
 
109
  "en": 0.5,
110
  "es": 0.5,
111
  "fr": 0.5,
112
+ "hin": 0.73,
113
+ "it": 0.5,
114
+ "tt": 0.5
115
  }
116
  }
model.safetensors CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:1ac5dd89cc6b6d93164715bf35ee2e9fd7a6079526f24ccbbc5a039ee9ea260b
3
  size 3617384
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:97eda89bd18ffe9cc7199408930303a48b115d7856fec82f48a362611e4ec1bc
3
  size 3617384