Basics · text-classification · WASM q8 · 302.8 MB

Threshold sweep & framing ablation

Does the guard react to scary words, or to instructions aimed at the AI? Score four topic-matched pairs — a human talking about "ignore previous" versus text that tells the assistant to ignore its instructions — then sweep the block threshold and watch true- and false-positive rates move.

1. Benign trigger words vs malicious override

Pairs separated at τ–
Mean gap (mal − benign)–
Latency (8 passes)–
NaN check–
P(INJECTION) for each topic-matched pair at the current threshold
Topic Benign discussion P(inj) Malicious directive P(inj) Gap
Initialise the model to score the pairs.

Try your own pair

2. Live threshold sweep (0.30 → 0.95)

The 8 framings above become a tiny labelled set (4 benign, 4 malicious). Moving the threshold re-filters the cached probabilities instantly — no new inference. Ratios with an empty denominator show n/a, never NaN.

0.50
TPR (recall)–
FPR–
Precision–
Accuracy–
Confusion counts per threshold (active row = slider)
τ TP FP TN FN TPR FPR Acc
Run the ablation first.

3. Inspect the metrics code

Show the code · guard-core.mjs — computeConfusion() & thresholdSweep()
Show the code · guard-core.mjs — summarizeAblation()