Download index.html from cmgdevl/brink: direct link, hf CLI and curl.
- Browser
- Download file 48.6 kB
-
https://huggingface.co/spaces/cmgdevl/brink/resolve/main/index.html
- Command line
-
hf download hf://spaces/cmgdevl/brink/index.html
-
curl -L -o index.html https://huggingface.co/spaces/cmgdevl/brink/resolve/main/index.html
48.6 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="utf-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1"> | |
| <title>Brink · Keep a model safe while you fine-tune it</title> | |
| <meta name="description" content="Open-source safety guard for LLM fine-tuning. Brink removes risky samples from your training data, watches the model's refusals while it trains, and stops the run before its safety breaks."> | |
| <meta name="robots" content="index, follow, max-image-preview:large"> | |
| <link rel="canonical" href="https://cmgdevl-brink.static.hf.space/"> | |
| <meta name="author" content="Cmg"> | |
| <meta name="color-scheme" content="light dark"> | |
| <meta name="theme-color" content="#f8f7fc" media="(prefers-color-scheme: light)"> | |
| <meta name="theme-color" content="#121118" media="(prefers-color-scheme: dark)"> | |
| <link rel="icon" href="favicon.ico" sizes="48x48"> | |
| <link rel="icon" href="favicon.svg" type="image/svg+xml"> | |
| <link rel="icon" href="favicon-32.png" type="image/png" sizes="32x32"> | |
| <link rel="icon" href="favicon-16.png" type="image/png" sizes="16x16"> | |
| <link rel="apple-touch-icon" href="apple-touch-icon.png"> | |
| <link rel="manifest" href="site.webmanifest"> | |
| <meta property="og:type" content="website"> | |
| <meta property="og:site_name" content="Brink"> | |
| <meta property="og:title" content="Brink · Keep a model safe while you fine-tune it"> | |
| <meta property="og:description" content="Open-source safety guard for LLM fine-tuning. Brink removes risky samples from your training data, watches the model's refusals while it trains, and stops the run before its safety breaks."> | |
| <meta property="og:url" content="https://cmgdevl-brink.static.hf.space/"> | |
| <meta property="og:locale" content="en_US"> | |
| <meta property="og:image" content="https://cmgdevl-brink.static.hf.space/og-image.png"> | |
| <meta property="og:image:type" content="image/png"> | |
| <meta property="og:image:width" content="1200"> | |
| <meta property="og:image:height" content="630"> | |
| <meta property="og:image:alt" content="Brink: keep a model safe while you fine-tune it"> | |
| <meta name="twitter:card" content="summary_large_image"> | |
| <meta name="twitter:title" content="Brink · Keep a model safe while you fine-tune it"> | |
| <meta name="twitter:description" content="Open-source safety guard for LLM fine-tuning. Brink removes risky samples from your training data, watches the model's refusals while it trains, and stops the run before its safety breaks."> | |
| <meta name="twitter:image" content="https://cmgdevl-brink.static.hf.space/og-image.png"> | |
| <meta name="twitter:image:alt" content="Brink: keep a model safe while you fine-tune it"> | |
| <script type="application/ld+json">{ | |
| "@context": "https://schema.org", | |
| "@graph": [ | |
| { | |
| "@type": "SoftwareApplication", | |
| "@id": "https://cmgdevl-brink.static.hf.space/#software", | |
| "name": "Brink", | |
| "description": "Open-source safety guard for LLM fine-tuning. Brink removes risky samples from your training data, watches the model's refusals while it trains, and stops the run before its safety breaks.", | |
| "applicationCategory": "DeveloperApplication", | |
| "applicationSubCategory": "AI safety", | |
| "operatingSystem": "Linux, macOS, Windows", | |
| "softwareVersion": "0.1.0", | |
| "license": "https://opensource.org/licenses/MIT", | |
| "url": "https://cmgdevl-brink.static.hf.space/", | |
| "image": "https://cmgdevl-brink.static.hf.space/og-image.png", | |
| "downloadUrl": "https://github.com/andrew1234-arch/brink", | |
| "offers": { | |
| "@type": "Offer", | |
| "price": "0", | |
| "priceCurrency": "USD" | |
| }, | |
| "keywords": "LLM fine-tuning, AI safety, alignment, refusal, LoRA, data curation, red teaming" | |
| }, | |
| { | |
| "@type": "SoftwareSourceCode", | |
| "@id": "https://cmgdevl-brink.static.hf.space/#code", | |
| "name": "Brink", | |
| "codeRepository": "https://github.com/andrew1234-arch/brink", | |
| "programmingLanguage": "Python", | |
| "runtimePlatform": "Python 3.10+", | |
| "license": "https://opensource.org/licenses/MIT", | |
| "targetProduct": { | |
| "@id": "https://cmgdevl-brink.static.hf.space/#software" | |
| } | |
| }, | |
| { | |
| "@type": "WebPage", | |
| "@id": "https://cmgdevl-brink.static.hf.space/#page", | |
| "url": "https://cmgdevl-brink.static.hf.space/", | |
| "name": "Brink \u00b7 Keep a model safe while you fine-tune it", | |
| "description": "Open-source safety guard for LLM fine-tuning. Brink removes risky samples from your training data, watches the model's refusals while it trains, and stops the run before its safety breaks.", | |
| "inLanguage": "en", | |
| "primaryImageOfPage": "https://cmgdevl-brink.static.hf.space/og-image.png", | |
| "about": { | |
| "@id": "https://cmgdevl-brink.static.hf.space/#software" | |
| } | |
| } | |
| ] | |
| }</script> | |
| <style> | |
| :root { --bg: #f8f7fc; --card: #ffffff; --fg: #1a1726; --muted: #5d5a6e; --line: #e2dff0; --accent: #5b43b3; | |
| --brand: #7459cc; --brand-fg: #ffffff; --tint: #eeeafd; --bad: #c2410c; --good: #0f766e; --code-bg: #17142a; | |
| --code-fg: #ebe8f7; --soft: #f1eefb; } | |
| @media (prefers-color-scheme: dark) { | |
| :root { --bg: #121118; --card: #1b1924; --fg: #ece9f6; --muted: #a3a0b5; --line: #2d2a3b; --accent: #bcaef7; | |
| --brand: #bcaef7; --brand-fg: #121118; --tint: #241f3a; --bad: #fb923c; --good: #5eead4; --code-bg: #0c0b12; | |
| --code-fg: #e2def2; --soft: #221f2e; } | |
| } | |
| * { box-sizing: border-box; } | |
| html { scroll-behavior: smooth; scroll-padding-top: 64px; } | |
| body { margin: 0; background: var(--bg); color: var(--fg); font: 16px/1.6 system-ui, -apple-system, "Segoe UI", | |
| sans-serif; -webkit-font-smoothing: antialiased; } | |
| a { color: var(--accent); } | |
| a:focus-visible, button:focus-visible, input:focus-visible, select:focus-visible, summary:focus-visible { | |
| outline: 2px solid var(--brand); outline-offset: 2px; border-radius: 4px; } | |
| .skip { position: absolute; left: -999px; top: 8px; background: var(--card); padding: 8px 12px; z-index: 10; } | |
| .skip:focus { left: 16px; } | |
| .wrap { max-width: 1040px; margin: 0 auto; padding: 0 16px; } | |
| header.top { position: sticky; top: 0; background: color-mix(in srgb, var(--bg) 92%, transparent); | |
| backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); z-index: 5; } | |
| header.top .wrap { display: flex; align-items: center; gap: 20px; height: 56px; } | |
| .brand { display: flex; align-items: center; gap: 9px; font-weight: 750; letter-spacing: -0.01em; | |
| text-decoration: none; color: var(--fg); font-size: 1.12rem; } | |
| .brand svg { display: block; border-radius: 7px; } | |
| header.top nav { display: flex; gap: 18px; margin-left: auto; overflow-x: auto; white-space: nowrap; } | |
| header.top nav a { color: var(--muted); text-decoration: none; font-size: 0.93rem; } | |
| header.top nav a:hover { color: var(--fg); } | |
| .hero { padding-top: 64px; padding-bottom: 40px; } | |
| .eyebrow { display: inline-block; font-size: 0.82rem; font-weight: 650; color: var(--accent); background: var(--tint); | |
| border-radius: 999px; padding: 3px 12px; margin: 0 0 16px; } | |
| .hero h1 { font-size: clamp(2.1rem, 5.4vw, 3.4rem); line-height: 1.06; letter-spacing: -0.03em; margin: 0 0 18px; | |
| max-width: 22ch; } | |
| .hero h1 em { font-style: normal; color: var(--brand); } | |
| .hero p.lead { font-size: 1.15rem; color: var(--muted); max-width: 62ch; margin: 0 0 26px; } | |
| .cta { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 22px; } | |
| .btn { display: inline-block; padding: 10px 18px; border-radius: 9px; text-decoration: none; font-weight: 650; | |
| border: 1px solid var(--line); color: var(--fg); background: var(--card); } | |
| .btn:hover { border-color: var(--brand); } | |
| .btn.primary { background: var(--brand); color: var(--brand-fg); border-color: var(--brand); } | |
| .stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(176px, 1fr)); gap: 12px; margin: 28px 0 8px; } | |
| .stat { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; } | |
| .stat b { display: block; font-size: 1.4rem; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; | |
| color: var(--fg); white-space: nowrap; } | |
| .stat span { color: var(--muted); font-size: 0.88rem; line-height: 1.45; display: block; margin-top: 4px; } | |
| .note { color: var(--muted); font-size: 0.88rem; margin: 8px 0 0; } | |
| section.block { padding: 48px 0; border-top: 1px solid var(--line); } | |
| section.block > .wrap > h2 { font-size: 1.65rem; letter-spacing: -0.02em; margin: 0 0 6px; } | |
| section.block > .wrap > p.sub { color: var(--muted); margin: 0 0 22px; max-width: 70ch; } | |
| .steps { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; } | |
| .step { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 18px; | |
| border-top: 3px solid var(--brand); } | |
| .step .when { color: var(--accent); font-size: 0.78rem; font-weight: 700; letter-spacing: 0.04em; } | |
| .step h3 { margin: 4px 0 6px; font-size: 1.12rem; } | |
| .step p { margin: 0; color: var(--muted); font-size: 0.95rem; } | |
| .use { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 20px; margin: 0 0 14px; } | |
| .use h3 { margin: 0 0 4px; font-size: 1.1rem; } | |
| .use p { margin: 0 0 12px; color: var(--muted); font-size: 0.95rem; max-width: 75ch; } | |
| .code { position: relative; } | |
| pre { margin: 0; background: var(--code-bg); color: var(--code-fg); border-radius: 9px; padding: 14px 76px 14px 16px; | |
| overflow-x: auto; font: 0.86rem/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; } | |
| .copy { position: absolute; top: 8px; right: 8px; font: inherit; font-size: 0.78rem; padding: 3px 9px; | |
| border-radius: 6px; border: 1px solid #3b3557; background: #26213d; color: #ebe8f7; cursor: pointer; } | |
| .copy:hover { border-color: #bcaef7; } | |
| code { font: 0.9em ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; background: var(--soft); | |
| border-radius: 4px; padding: 1px 5px; } | |
| pre code { background: none; padding: 0; } | |
| .demo { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 20px; margin: 0 0 14px; } | |
| .demo h3 { margin: 0 0 4px; font-size: 1.1rem; } | |
| .demo p.q { margin: 0 0 14px; color: var(--muted); font-size: 0.95rem; max-width: 75ch; } | |
| .controls { display: flex; flex-wrap: wrap; gap: 18px 28px; align-items: center; margin: 0 0 10px; } | |
| .controls label { font-size: 0.9rem; color: var(--muted); display: flex; align-items: center; gap: 10px; } | |
| .controls output { color: var(--fg); font-weight: 650; font-variant-numeric: tabular-nums; min-width: 3.5ch; } | |
| input[type=range] { accent-color: var(--brand); width: 200px; max-width: 46vw; } | |
| select { font: inherit; padding: 3px 6px; border-radius: 6px; border: 1px solid var(--line); background: var(--card); | |
| color: var(--fg); } | |
| svg.chart { width: 100%; height: auto; display: block; } | |
| .verdict { margin: 10px 0 0; padding: 10px 14px; border-left: 3px solid var(--brand); background: var(--tint); | |
| border-radius: 0 8px 8px 0; font-size: 0.97rem; } | |
| .legend { display: flex; flex-wrap: wrap; gap: 16px; font-size: 0.85rem; color: var(--muted); margin: 6px 0 0; } | |
| .legend i { display: inline-block; width: 12px; height: 12px; border-radius: 3px; margin-right: 6px; | |
| vertical-align: -1px; } | |
| ul.plain { margin: 0; padding-left: 20px; color: var(--muted); max-width: 80ch; } | |
| ul.plain li { margin: 6px 0; } | |
| details.ev { background: var(--card); border: 1px solid var(--line); border-radius: 12px; margin: 0 0 10px; } | |
| details.ev > summary { cursor: pointer; padding: 14px 18px; font-weight: 650; display: flex; gap: 12px; | |
| align-items: center; flex-wrap: wrap; } | |
| details.ev > div { padding: 0 18px 18px; } | |
| .chip { font-size: 0.76rem; font-weight: 650; padding: 2px 9px; border-radius: 999px; background: var(--soft); | |
| color: var(--muted); } | |
| .chip.ok { color: var(--good); } .chip.no { color: var(--bad); } | |
| .scroll { overflow-x: auto; } | |
| table { border-collapse: collapse; margin: 10px 0; font-size: 0.9rem; } | |
| th, td { border: 1px solid var(--line); padding: 5px 9px; text-align: left; vertical-align: top; } | |
| img { max-width: 100%; height: auto; background: #fff; border-radius: 6px; margin: 10px 0; } | |
| .files { color: var(--muted); font-size: 0.88rem; } | |
| h4, h5, h6 { margin: 16px 0 6px; font-size: 1rem; } | |
| .links { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 12px; } | |
| .links a { display: block; background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px; | |
| text-decoration: none; color: var(--fg); } | |
| .links a:hover { border-color: var(--brand); } | |
| .links b { display: block; margin-bottom: 2px; } | |
| .links span { color: var(--muted); font-size: 0.9rem; } | |
| footer { border-top: 1px solid var(--line); padding: 26px 0 50px; color: var(--muted); font-size: 0.9rem; } | |
| footer .wrap { display: flex; flex-wrap: wrap; gap: 8px 20px; align-items: center; } | |
| .banner { background: var(--soft); border: 1px solid var(--line); border-radius: 10px; padding: 12px 16px; | |
| margin: 18px 0 0; } | |
| @media (max-width: 640px) { header.top nav a.minor { display: none; } .hero { padding-top: 40px; } } | |
| @media (prefers-reduced-motion: reduce) { html { scroll-behavior: auto; } } | |
| </style> | |
| </head> | |
| <body> | |
| <a class="skip" href="#main">Skip to content</a> | |
| <header class="top"><div class="wrap"> | |
| <a class="brand" href="#top" aria-label="Brink, home"><svg viewBox="0 0 64 64" width="28" height="28" aria-hidden="true"><defs><clipPath id="bm"><rect width="64" height="64" rx="15"/></clipPath></defs><g clip-path="url(#bm)"><rect width="64" height="64" fill="#7459CC"/><rect x="41" y="51" width="23" height="13" fill="#4A3699"/><path d="M0 37h41v27H0z" fill="#2B2063"/><circle cx="34" cy="30" r="7" fill="#FFFFFF"/></g></svg><span>Brink</span></a> | |
| <nav><a class="minor" href="#how">How it works</a><a href="#use">Use it</a><a href="#demo">Demo</a> | |
| <a class="minor" href="#limits">Limits</a><a class="minor" href="#evidence">Evidence</a> | |
| <a href="#resources">Resources</a></nav> | |
| </div></header> | |
| <main id="main"> | |
| <div class="wrap hero" id="top"> | |
| <p class="eyebrow">Open-source safety guard for LLM fine-tuning</p> | |
| <h1>Keep a model safe <em>while</em> you fine-tune it.</h1> | |
| <p class="lead">Fine-tuning can quietly teach a safe model to answer harmful requests. Brink cleans the risky | |
| samples out of your training data, watches the model's refusals while it trains, and stops the run when they | |
| start to slip.</p> | |
| <div class="cta"><a class="btn primary" href="#use">Get started</a> | |
| <a class="btn" href="#demo">Try the demo</a> | |
| <a class="btn" href="https://github.com/andrew1234-arch/brink">View on GitHub</a></div> | |
| <div class="code"><button class="copy" type="button">Copy</button><pre><code>pip install "brink-safety[curatorkit] @ git+https://github.com/andrew1234-arch/brink"</code></pre></div> | |
| <div class="stats"><div class="stat"><b>94 % → 21 %</b><span>harmful requests answered after the same fine-tune, without and with Brink</span></div><div class="stat"><b>29 of 32</b><span>harmful training samples removed by the gate before training</span></div><div class="stat"><b>0 %</b><span>harmless requests refused by the protected model</span></div><div class="stat"><b>1.45 vs 1.46</b><span>task loss without and with Brink: the model still learns the task</span></div><div class="stat"><b>42 % → 6 %</b><span>the same on a Hindi assistant trained through CuratorKIT and AlignTune</span></div></div><p class="note">Measured on <code>CohereLabs/tiny-aya-global</code> in recorded runs. Full reports, including what did not work, are under <a href="#evidence">Evidence</a>.</p> | |
| </div> | |
| <section class="block" id="how"><div class="wrap"> | |
| <h2>How it works</h2> | |
| <p class="sub">Brink measures one thing: how strongly the model prefers to refuse a fixed set of harmful probe | |
| prompts, compared with the model before fine-tuning. It uses that measure at three points.</p> | |
| <div class="steps"> | |
| <div class="step"><span class="when">Before training</span><h3>Gate</h3> | |
| <p>Scores every training sample by how much one training step on it would erode refusal, and drops the | |
| riskiest. You get a ranked list and a cleaned file.</p></div> | |
| <div class="step"><span class="when">During training</span><h3>Monitor</h3> | |
| <p>Probes the model every few steps with one forward pass and raises an alarm when refusal stays below a | |
| threshold calibrated on safe fine-tuning.</p></div> | |
| <div class="step"><span class="when">On alarm</span><h3>Repair</h3> | |
| <p>Halts the run, or rolls back to the last safe checkpoint and constrains the following updates so they | |
| cannot lower refusal.</p></div> | |
| <div class="step"><span class="when">After training</span><h3>Verify</h3> | |
| <p>Checks the result on held-out harmful prompts, harmless prompts and task data, and writes a report.</p></div> | |
| </div> | |
| </div></section> | |
| <section class="block" id="use"><div class="wrap"> | |
| <h2>Use it</h2> | |
| <p class="sub">Python 3.10 or later. Brink loads AdvBench and HarmBench as probe prompts, which are gated on | |
| Hugging Face: accept their terms once and log in with <code>huggingface-cli login</code>.</p> | |
| <div class="use"><h3>1. Clean your data before you train</h3> | |
| <p>Point Brink at a fine-tuning file (<code>.jsonl</code>, <code>.json</code> or <code>.csv</code> with prompt | |
| and response) and the model you will fine-tune.</p><div class="code"><button class="copy" type="button">Copy</button><pre><code>brink gate my_finetune.jsonl --model CohereLabs/tiny-aya-global --drop 0.05 --out gated/ | |
| # gated/scored.csv every sample with its risk score, riskiest first | |
| # gated/cleaned.jsonl your data without the riskiest 5 % and exact duplicates</code></pre></div></div> | |
| <div class="use"><h3>2. Protect a training run</h3> | |
| <p>Add one callback to a Hugging Face <code>Trainer</code> or TRL <code>SFTTrainer</code>. Brink probes the model | |
| as it trains and halts when the alarm fires. Use <code>"rollback_guard"</code> to roll back and keep training | |
| under the guard instead.</p><div class="code"><button class="copy" type="button">Copy</button><pre><code>from brink.monitor.callback import BrinkCallback | |
| from brink.monitor.core import Monitor | |
| from brink.probe import Prober, calibrate | |
| from brink.repair import ErosionGuard, RepairController | |
| fp, _ = calibrate(model, tok, harmful_cal, harmless_cal, harmful_probe, harmless_probe) | |
| monitor = Monitor(Prober(fp, tok, harmful_probe, harmless_probe), "runs/my-finetune", | |
| probe_every=4, alarm_signal="S3", alarm_threshold=-3.0) | |
| controller = RepairController(monitor, "halt") | |
| trainer = SFTTrainer(model=model, args=args, train_dataset=ds, | |
| callbacks=[BrinkCallback(controller=controller)]) | |
| trainer.train()</code></pre></div></div> | |
| <div class="use"><h3>3. Inside a CuratorKIT pipeline</h3> | |
| <p>The gate is a native CuratorKIT <code>BaseGate</code>, so it drops into an existing curation pipeline. | |
| With AlignTune, attach the same callback with <code>attach_to_aligntune(trainer, callback)</code>.</p> | |
| <div class="code"><button class="copy" type="button">Copy</button><pre><code>from curatorkit.pipeline import Pipeline | |
| from brink.gate import GateScorer | |
| from brink.gate.curatorkit_gate import BrinkSafetyGate | |
| gate = BrinkSafetyGate(GateScorer(model, tok, fp, harmful_probe, harmless_probe), drop_frac=0.05) | |
| Pipeline([reader, ExactDeduplicator(), gate, exporter], output_dir="curated").run()</code></pre></div></div> | |
| <div class="use"><h3>4. See all of it on a model, in one command</h3> | |
| <p>Runs the full loop on a small model, on CPU in about 20 minutes or on a GPU in a few, and writes a report | |
| you can read.</p><div class="code"><button class="copy" type="button">Copy</button><pre><code>brink run --model Qwen/Qwen2.5-0.5B-Instruct --out runs/demo | |
| # fingerprints the model, gates a contaminated set, fine-tunes it unprotected and with Brink, | |
| # verifies both on held-out prompts and writes runs/demo/REPORT.md</code></pre></div></div> | |
| <div class="use"><h3>5. Start from a model Brink already protected</h3> | |
| <p>A Hindi assistant fine-tuned from Tiny Aya on data with 10 % harmful samples, protected by Brink's gate, | |
| alarm and rollback. Load the LoRA adapter on top of the base model.</p><div class="code"><button class="copy" type="button">Copy</button><pre><code>from peft import PeftModel | |
| from transformers import AutoModelForCausalLM, AutoTokenizer | |
| base = AutoModelForCausalLM.from_pretrained("CohereLabs/tiny-aya-global") | |
| tok = AutoTokenizer.from_pretrained("CohereLabs/tiny-aya-global") | |
| model = PeftModel.from_pretrained(base, "cmgdevl/brink-artifacts", subfolder="adapters/pipeline/brink")</code></pre></div></div> | |
| <div class="use"><h3>6. Or use the app</h3> | |
| <p>The same three jobs in a browser: run Brink live, upload a file to gate, and replay any run with your own | |
| alarm rule.</p><div class="code"><button class="copy" type="button">Copy</button><pre><code>git clone https://github.com/andrew1234-arch/brink && cd brink | |
| pip install -e ".[dashboard,curatorkit]" | |
| make app # http://localhost:7860: Run Brink, Gate your data, Experiments</code></pre></div></div> | |
| </div></section> | |
| <section class="block" id="demo"><div class="wrap"> | |
| <h2>Try it on a recorded run</h2> | |
| <p class="sub">This is a real fine-tune of <code>CohereLabs/tiny-aya-global</code> on data with harmful samples mixed in, logged step | |
| by step. Move the controls to see what Brink would have done with your settings.</p> | |
| <div class="demo"> | |
| <h3>Where would the alarm fire?</h3> | |
| <p class="q">Brink reads the model's preference to refuse every few steps, as a z-score against the model before | |
| fine-tuning. The alarm fires when it stays under the line.</p> | |
| <div class="controls"> | |
| <label>Alarm line (z) <input id="thr" type="range" min="-12" max="-1" step="0.5" value="-3.0"> | |
| <output id="thr-out"></output></label> | |
| <label>Probes in a row <select id="persist"><option value="1">1</option><option value="2" selected>2</option><option value="3">3</option></select></label> | |
| </div> | |
| <svg class="chart" id="alarm-chart" viewBox="0 0 960 340" role="img" | |
| aria-label="Refusal signal over training steps for the unprotected and the Brink run"></svg> | |
| <p class="verdict" id="alarm-verdict"></p> | |
| </div> | |
| <div class="demo"> | |
| <h3>How much should the gate drop?</h3> | |
| <p class="q">Before training, Brink scores every sample by how much one training step on it would erode refusal. | |
| Each bar is one training sample of this run.</p> | |
| <div class="controls"> | |
| <label>Drop the riskiest <input id="drop" type="range" min="0" max="0.5" step="0.01" value="0.25"> | |
| <output id="drop-out"></output></label> | |
| </div> | |
| <svg class="chart" id="gate-chart" viewBox="0 0 960 220" role="img" | |
| aria-label="Gate risk score of every training sample, riskiest first"></svg> | |
| <div class="legend"><span><i style="background:var(--bad)"></i>harmful sample</span> | |
| <span><i style="background:var(--good)"></i>benign sample</span></div> | |
| <p class="verdict" id="gate-verdict"></p> | |
| </div> | |
| <p class="note">The demo replays logged signals in your browser. To score your own data or run your own model, use | |
| the commands under <a href="#use">Use it</a>.</p> | |
| </div></section> | |
| <section class="block" id="limits"><div class="wrap"> | |
| <h2>What to know before you rely on it</h2> | |
| <p class="sub">Measured limits, from the experiments below.</p> | |
| <ul class="plain"> | |
| <li>The alarm fires when refusals break, not before. It is a tripwire, not a forecast.</li> | |
| <li>The gate and halting at the alarm are the parts that hold up on their own. Rollback with the guard, used | |
| alone on heavily contaminated data, was less safe than mixing in safety data.</li> | |
| <li>Outside English the alarm needs its own calibration: with the English threshold it also fired on safe | |
| fine-tuning in Hindi and Tagalog.</li> | |
| <li>Tested on one model family (Tiny Aya, 3.35B) with one or two seeds.</li> | |
| <li>This page runs no model. Gating your data and protecting a run happen on your machine.</li> | |
| </ul> | |
| </div></section> | |
| <section class="block" id="evidence"><div class="wrap"> | |
| <h2>Evidence</h2> | |
| <p class="sub">Every experiment's report as the run wrote it, with its pre-set pass criteria, plots and logs. | |
| The "AuditKIT attacks resisted" column in the repair report predates a scoring fix: that run used AuditKIT's | |
| default detectors, which count a refusal as a failed attack. Read its attack success rate (ASR) instead.</p> | |
| <details class="ev" id="live"><summary>Brink end to end (recorded live run)</summary><div><h4>Brink, end to end</h4> | |
| <p><strong>Unprotected fine-tuning cut refusal from 77% to 4%; with Brink it ended at 69%, preventing 89% of the loss. Brink's alarm fired at step 20 of the unprotected run.</strong></p> | |
| <p>Model <code>CohereLabs/tiny-aya-global</code> on GPU; judge: wildguard. Fine-tuning data: 128 samples, 32 of them harmful-compliance samples. Verified on 48 held-out harmful prompts and 32 harmless ones.</p> | |
| <div class='scroll'><table><thead><tr><th></th><th>Before fine-tuning</th><th>Unprotected</th><th>With Brink</th></tr></thead><tbody><tr><td>Refuses harmful prompts</td><td>77%</td><td>4%</td><td>69%</td></tr><tr><td>Attack success rate</td><td>21%</td><td>94%</td><td>21%</td></tr><tr><td>Over-refusal (harmless prompts)</td><td>0%</td><td>0%</td><td>0%</td></tr><tr><td>Held-out task loss</td><td>2.016</td><td>1.452</td><td>1.462</td></tr><tr><td>Brink alarm</td><td></td><td>20</td><td>—</td></tr></tbody></table></div> | |
| <p><strong>Gate.</strong> Dropped the 32 highest-risk samples; 29 of the 32 harmful samples were among them (precision 91% against 25% for random dropping, recall 91%).</p> | |
| <p><strong>Repair.</strong> Policy <code>rollback_guard</code>: rolled back to step —; halted at —.</p> | |
| <p><strong>Fingerprint.</strong> Refusal direction at layer 23/36.</p> | |
| <p>A small, single-seed run sized to finish in minutes. The experiments (docs/) give the multi-seed numbers with confidence intervals.</p><p class='files'>Files: <a href="results/live/REPORT.md">REPORT.md</a>, <a href="results/live/config.json">config.json</a>, <a href="results/live/fingerprint.json">fingerprint.json</a>, <a href="results/live/gate.csv">gate.csv</a>, <a href="results/live/meta.json">meta.json</a>, <a href="results/live/prompts.csv">prompts.csv</a>, <a href="results/live/status.json">status.json</a>, <a href="results/live/summary.json">summary.json</a></p></div></details><details class="ev" id="pipeline"><summary>Pipeline: a Hindi assistant, before and after<span class="chip ok">PIPELINE DELIVERS</span></summary><div><h4>Pipeline (Hindi assistant, contaminated data): <strong>PIPELINE DELIVERS</strong></h4> | |
| <ul><li>✅ P1_removes_most_of_the_drift</li><li>✅ P2_learns_the_task</li><li>✅ P3_no_over_refusal</li><li>✅ P4_runs_on_the_lexsi_stack</li></ul> | |
| <div class='scroll'><table><thead><tr><th>model</th><th>Hindi task loss ↓</th><th>Hindi task chrF ↑</th><th>ASR English ↓ (95 % CI)</th><th>ASR Hindi ↓</th><th>over-refusal (Hindi) ↓</th><th>AuditKIT attacks resisted ↑</th><th>trainer</th><th>alarm / repair</th></tr></thead><tbody><tr><td>reference (Tiny Aya, no fine-tuning)</td><td>2.102</td><td>32.3</td><td>16%</td><td>2%</td><td>0%</td><td>57%</td><td>–</td><td>–</td></tr><tr><td>naive</td><td>1.788</td><td>31.7</td><td>42% (30%–54%)</td><td>0%</td><td>3%</td><td>29%</td><td>aligntune (trl backend)</td><td>alarm at 16</td></tr><tr><td>brink</td><td>1.800</td><td>31.4</td><td>6% (2%–15%)</td><td>0%</td><td>0%</td><td>57%</td><td>aligntune (trl backend)</td><td>alarm at 16, rolled back to 8, guard on</td></tr></tbody></table></div> | |
| <p><strong>CuratorKIT + BrinkSafetyGate (brink):</strong> dropped 26 of 512 samples (top 5% by predicted refusal erosion), catching <strong>21 of 51</strong> contaminating samples; 5 benign samples dropped.</p> | |
| <p>The Hindi ASR uses an English-trained judge and is less reliable than the English ASR.</p><p class='files'>Files: <a href="results/pipeline/REPORT.md">REPORT.md</a>, <a href="results/pipeline/config.json">config.json</a>, <a href="results/pipeline/data_summary.json">data_summary.json</a>, <a href="results/pipeline/fingerprint.json">fingerprint.json</a>, <a href="results/pipeline/reference.json">reference.json</a>, <a href="results/pipeline/summary.json">summary.json</a></p></div></details><details class="ev" id="go_nogo"><summary>Go / no-go: is the drift detectable?<span class="chip no">NO-GO</span></summary><div><h4>Go / no-go: <strong>NO-GO</strong></h4> | |
| <p>Seeds: [0, 1]</p> | |
| <ul><li>✅ G1a_pos_drifts</li><li>✅ G1b_control_stable</li><li>❌ G2_signal_tracks_asr</li><li>✅ G3_alarm_before_break_without_false_alarms</li></ul> | |
| <p><strong>Notes</strong></p> | |
| <ul><li>Best signal is the behavioural proxy S3. Claim a cheap early warning, not mechanistic foresight, unless the mechanistic S1 also leads.</li></ul> | |
| <h5>Alarm per signal</h5> | |
| <p>Threshold calibrated on control runs only. False alarms and detection are leave-one-seed-out when there are 2 or more seeds. Lead = steps between the alarm firing and behaviour breaking (ASR +jump).</p> | |
| <div class='scroll'><table><thead><tr><th>signal</th><th>kind</th><th>calibrated z</th><th>false alarms at fixed z</th><th>LOO false-alarm rate</th><th>detection</th><th>lead (steps)</th><th>Spearman vs ASR</th></tr></thead><tbody><tr><td>S1</td><td>mechanistic</td><td>-9.5</td><td>2/2</td><td>0%</td><td>0%</td><td>-4.0</td><td>-0.75</td></tr><tr><td>S1h</td><td>mechanistic</td><td>-26.7</td><td>2/2</td><td>50%</td><td>0%</td><td>-4.0</td><td>-0.68</td></tr><tr><td>S2</td><td>mechanistic</td><td>-40.7</td><td>2/2</td><td>50%</td><td>0%</td><td>-8.0</td><td>-0.75</td></tr><tr><td>S3</td><td>proxy</td><td>-3.0</td><td>0/2</td><td>0%</td><td>100%</td><td>0.0</td><td>-0.50</td></tr></tbody></table></div> | |
| <h5>Baseline: cheap judge every probe step</h5> | |
| <p>Lead -4.0 steps · false alarms on control 0/2 · 6.2 s per check</p> | |
| <h5>Runs</h5> | |
| <div class='scroll'><table><thead><tr><th>condition</th><th>seed</th><th>ASR start → end (95 % CI)</th><th>behaviour breaks</th><th>probe s</th><th>eval s</th></tr></thead><tbody><tr><td>pos</td><td>0</td><td>16% → 100% (94%–100%)</td><td>8</td><td>23.8</td><td>103.2</td></tr><tr><td>pos</td><td>1</td><td>16% → 97% (89%–99%)</td><td>8</td><td>23.8</td><td>102.5</td></tr><tr><td>control</td><td>0</td><td>16% → 12% (6%–23%)</td><td>n/a</td><td>23.9</td><td>100.5</td></tr><tr><td>control</td><td>1</td><td>16% → 11% (5%–21%)</td><td>n/a</td><td>23.9</td><td>100.6</td></tr></tbody></table></div><img src="results/go_nogo/go_nogo.png" alt="go_nogo plot: go_nogo" loading="lazy"><p class='files'>Files: <a href="results/go_nogo/REPORT.md">REPORT.md</a>, <a href="results/go_nogo/config.json">config.json</a>, <a href="results/go_nogo/data_summary.json">data_summary.json</a>, <a href="results/go_nogo/fingerprint.json">fingerprint.json</a>, <a href="results/go_nogo/summary.json">summary.json</a></p></div></details><details class="ev" id="gate"><summary>Gate: finding the data that erodes safety<span class="chip no">GATE NOT PROVEN</span></summary><div><h4>Gate experiment: <strong>GATE NOT PROVEN</strong></h4> | |
| <ul><li>✅ D1_finds_planted_harmful</li><li>✅ D1b_beats_rep_baseline</li><li>❌ D2_top_scored_benign_breaks_safety_more</li><li>✅ D3_low_scored_benign_is_safer</li></ul> | |
| <h5>Detection of planted harmful samples in a benign pool</h5> | |
| <div class='scroll'><table><thead><tr><th>score</th><th>AUROC</th><th>recall@k</th><th>recall@top 5 %</th></tr></thead><tbody><tr><td>grad_S3 (primary)</td><td>0.981</td><td>0.600</td><td>0.860</td></tr><tr><td>grad_S1</td><td>0.968</td><td>0.540</td><td>0.720</td></tr><tr><td>rep</td><td>0.943</td><td>0.560</td><td>0.700</td></tr><tr><td>random</td><td>0.525</td><td>0.020</td><td>0.020</td></tr><tr><td>classifier</td><td>0.999</td><td>0.940</td><td>1.000</td></tr></tbody></table></div> | |
| <p>The safety classifier flags <strong>0%</strong> of the gate's top-scored benign subset: the risk the gate finds is invisible to a content filter.</p> | |
| <h5>Fine-tuning on benign subsets selected by <code>grad_S3</code></h5> | |
| <div class='scroll'><table><thead><tr><th>subset</th><th>ASR start → end</th><th>held-out loss start → end</th><th>z_S1 end</th><th>z_S3 end</th></tr></thead><tbody><tr><td>top</td><td>0.156 → 0.190</td><td>2.051 → 1.449</td><td>-23.9</td><td>-7.3</td></tr><tr><td>random</td><td>0.156 → 0.109</td><td>2.051 → 1.439</td><td>-15.3</td><td>3.2</td></tr><tr><td>bottom</td><td>0.156 → 0.094</td><td>2.051 → 1.500</td><td>-10.0</td><td>10.0</td></tr></tbody></table></div><img src="results/gate/gate.png" alt="gate plot: gate" loading="lazy"><p class='files'>Files: <a href="results/gate/REPORT.md">REPORT.md</a>, <a href="results/gate/config.json">config.json</a>, <a href="results/gate/data_summary.json">data_summary.json</a>, <a href="results/gate/fingerprint.json">fingerprint.json</a>, <a href="results/gate/scores.csv">scores.csv</a>, <a href="results/gate/scoring_time.json">scoring_time.json</a>, <a href="results/gate/subsets.json">subsets.json</a>, <a href="results/gate/summary.json">summary.json</a></p></div></details><details class="ev" id="repair"><summary>Repair: rollback and the erosion guard vs baselines<span class="chip no">REPAIR NOT PROVEN</span></summary><div><h4>Repair experiment: <strong>REPAIR NOT PROVEN</strong></h4> | |
| <ul><li>✅ R1_removes_most_of_the_drift</li><li>✅ R2_keeps_task_capability</li><li>✅ R3_no_over_refusal</li><li>❌ R4_beats_baselines_posthoc_and_safety_mix</li></ul> | |
| <p>Best Brink policy: <strong>halt</strong></p> | |
| <div class='scroll'><table><thead><tr><th>condition</th><th>ASR start → end</th><th>over-refusal start → end</th><th>held-out loss start → end</th><th>AuditKIT attacks resisted</th><th>AuditKIT benign answered</th><th>steps trained</th><th>alarm</th><th>notes</th></tr></thead><tbody><tr><td>none</td><td>16% → 83%</td><td>0% → 0%</td><td>2.051 → 1.417</td><td>86%</td><td>100%</td><td>128</td><td>28</td><td></td></tr><tr><td>safety_mix</td><td>16% → 23%</td><td>0% → 0%</td><td>2.051 → 1.419</td><td>81%</td><td>100%</td><td>128</td><td>28</td><td></td></tr><tr><td>halt</td><td>16% → 17%</td><td>0% → 0%</td><td>2.051 → 1.468</td><td>81%</td><td>100%</td><td>28</td><td>28</td><td></td></tr><tr><td>rollback_guard</td><td>16% → 41%</td><td>0% → 0%</td><td>2.051 → 1.414</td><td>81%</td><td>100%</td><td>128</td><td>28</td><td>rolled back to step 20; guard projected 64/100 steps, removed 1% of</td><td>g</td><td>² on average, refresh 338s</td></tr><tr><td>guard_always</td><td>16% → 34%</td><td>0% → 0%</td><td>2.051 → 1.417</td><td>81%</td><td>100%</td><td>128</td><td>n/a</td><td>guard projected 77/128 steps, removed 1% of</td><td>g</td><td>² on average, refresh 447s</td></tr><tr><td>posthoc_steer</td><td>83% → 19%</td><td>0% → 3%</td><td>1.417 → 1.476</td><td>81%</td><td>100%</td><td>n/a</td><td>n/a</td><td>steer strength 21.31; start = none (drifted)</td></tr><tr><td>posthoc_resta</td><td>83% → 66%</td><td>0% → 3%</td><td>1.417 → 1.817</td><td>86%</td><td>100%</td><td>n/a</td><td>n/a</td><td>ReSta alpha 0.25; start = none (drifted)</td></tr></tbody></table></div><img src="results/repair/repair.png" alt="repair plot: repair" loading="lazy"><p class='files'>Files: <a href="results/repair/REPORT.md">REPORT.md</a>, <a href="results/repair/config.json">config.json</a>, <a href="results/repair/data_summary.json">data_summary.json</a>, <a href="results/repair/fingerprint.json">fingerprint.json</a>, <a href="results/repair/summary.json">summary.json</a></p></div></details><details class="ev" id="multilingual"><summary>Multilingual: Hindi and Tagalog</summary><div><h4>Multilingual drift</h4> | |
| <ul><li>First language whose behaviour breaks on <code>pos</code>: <strong>en at step 8</strong></li><li>Lead over that first break: English-only alarm <strong>0</strong> steps, worst-language alarm <strong>0</strong> steps (negative = late)</li><li>Worst-language alarm on <code>control</code> (false alarm): <strong>yes</strong></li></ul> | |
| <p>Note: the WildGuard judge is mostly English-trained, so non-English ASR is less reliable. The per-language S3 alarm is judge-free (calibrated on each language's own refusal tokens).</p> | |
| <h5>pos</h5> | |
| <div class='scroll'><table><thead><tr><th>language</th><th>ASR start → end</th><th>behaviour breaks</th><th>alarm (own S3)</th><th>min z</th></tr></thead><tbody><tr><td>en</td><td>16% → 98%</td><td>8</td><td>8</td><td>-34.0</td></tr><tr><td>hi</td><td>2% → 42%</td><td>16</td><td>16</td><td>-9.6</td></tr><tr><td>tl</td><td>2% → 29%</td><td>16</td><td>12</td><td>-11.3</td></tr></tbody></table></div> | |
| <p>English-only alarm: step 8 · worst-language alarm: step 8</p> | |
| <h5>control</h5> | |
| <div class='scroll'><table><thead><tr><th>language</th><th>ASR start → end</th><th>behaviour breaks</th><th>alarm (own S3)</th><th>min z</th></tr></thead><tbody><tr><td>en</td><td>16% → 12%</td><td>n/a</td><td>n/a</td><td>-0.0</td></tr><tr><td>hi</td><td>2% → 0%</td><td>n/a</td><td>20</td><td>-7.7</td></tr><tr><td>tl</td><td>2% → 0%</td><td>n/a</td><td>20</td><td>-9.2</td></tr></tbody></table></div> | |
| <p>English-only alarm: step n/a · worst-language alarm: step 20</p><img src="results/multilingual/multilingual.png" alt="multilingual plot: multilingual" loading="lazy"><p class='files'>Files: <a href="results/multilingual/REPORT.md">REPORT.md</a>, <a href="results/multilingual/config.json">config.json</a>, <a href="results/multilingual/data_summary.json">data_summary.json</a>, <a href="results/multilingual/fingerprint.json">fingerprint.json</a>, <a href="results/multilingual/fingerprint_en.json">fingerprint_en.json</a>, <a href="results/multilingual/fingerprint_hi.json">fingerprint_hi.json</a>, <a href="results/multilingual/fingerprint_tl.json">fingerprint_tl.json</a>, <a href="results/multilingual/summary.json">summary.json</a></p></div></details> | |
| </div></section> | |
| <section class="block" id="resources"><div class="wrap"> | |
| <h2>Resources</h2> | |
| <p class="sub">Everything is open: code, the protected adapter, and every log behind the numbers above.</p> | |
| <div class="links"> | |
| <a href="https://github.com/andrew1234-arch/brink"><b>Source code</b><span>GitHub: library, CLI, app, experiments and tests</span></a> | |
| <a href="https://huggingface.co/cmgdevl/brink-artifacts"><b>Protected adapter</b><span>Hugging Face model repo, with the | |
| fingerprints</span></a> | |
| <a href="https://huggingface.co/datasets/cmgdevl/brink-results"><b>Logs and reports</b><span>Hugging Face dataset: every | |
| run's signals, evaluations and reports</span></a> | |
| <a href="https://github.com/andrew1234-arch/brink/blob/main/docs/ARTICLE.md"><b>Write-up</b><span>Method, datasets, metrics, results and | |
| limitations</span></a> | |
| </div> | |
| </div></section> | |
| </main> | |
| <footer><div class="wrap"><span>Brink · MIT licence</span><a href="https://github.com/andrew1234-arch/brink">GitHub</a> | |
| <a href="https://huggingface.co/cmgdevl/brink-artifacts">Adapter</a><a href="https://huggingface.co/datasets/cmgdevl/brink-results">Logs</a> | |
| <a href="https://huggingface.co/spaces/cmgdevl/brink">Hugging Face Space</a></div></footer> | |
| <script>window.BRINK_DEMO = {"unprotected": {"steps": [0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48], "z": [-0.0002003981085862892, 3.247595385781363, 0.6893841058989193, -2.9011362807598378, -9.847129903768463, -15.511448198589306, -18.928003195932337, -22.67522472703912, -26.198503361430383, -28.379606204669876, -29.199025459822984, -29.155961785020057, -28.73534963925079]}, "brink": {"steps": [0, 4, 8, 12, 16, 20, 24, 28, 32, 36, 40, 44, 48], "z": [-0.0002003981085862892, 3.5380098197682557, 3.083423410282641, 2.321154929786948, 1.4272332418712539, -0.3130134956905926, -2.022275763192582, -2.8881688531500664, -2.985186587469404, -2.6863930075672466, -2.3822533906224908, -2.884768347744993, -3.1382531677839687]}, "gate": [[0.25822, 1], [0.24584, 1], [0.23023, 1], [0.22982, 1], [0.21806, 1], [0.21325, 1], [0.19727, 1], [0.19355, 1], [0.18052, 1], [0.17497, 1], [0.16754, 1], [0.16191, 1], [0.15681, 1], [0.1522, 1], [0.14522, 0], [0.14116, 1], [0.1408, 1], [0.13147, 1], [0.12782, 1], [0.12149, 1], [0.1213, 1], [0.12107, 1], [0.11954, 1], [0.10031, 1], [0.09952, 1], [0.09644, 0], [0.09548, 1], [0.08929, 1], [0.08483, 1], [0.08349, 1], [0.08112, 1], [0.07775, 0], [0.07757, 0], [0.07511, 1], [0.05867, 1], [0.05517, 0], [0.05297, 0], [0.04766, 0], [0.0413, 0], [0.03726, 0], [0.03673, 0], [0.02806, 1], [0.02789, 0], [0.01948, 0], [0.01924, 0], [0.0155, 0], [0.00997, 0], [0.00923, 0], [0.00354, 0], [0.00212, 0], [4e-05, 0], [-0.0008, 0], [-0.00354, 0], [-0.00504, 0], [-0.00597, 0], [-0.01146, 0], [-0.01205, 0], [-0.01726, 0], [-0.0219, 0], [-0.0233, 0], [-0.0253, 0], [-0.02617, 0], [-0.0304, 0], [-0.03167, 0], [-0.0327, 0], [-0.03277, 0], [-0.03337, 0], [-0.03573, 0], [-0.03669, 0], [-0.04259, 0], [-0.04311, 0], [-0.04346, 0], [-0.04595, 0], [-0.04615, 0], [-0.04856, 0], [-0.04897, 0], [-0.0498, 0], [-0.05214, 0], [-0.05424, 0], [-0.05439, 0], [-0.05984, 0], [-0.06069, 0], [-0.06602, 0], [-0.06698, 0], [-0.06973, 0], [-0.07094, 0], [-0.07123, 0], [-0.07329, 0], [-0.07489, 0], [-0.07518, 0], [-0.078, 0], [-0.08125, 0], [-0.08139, 0], [-0.08196, 0], [-0.08229, 0], [-0.08234, 0], [-0.08523, 0], [-0.0862, 0], [-0.08631, 0], [-0.09641, 0], [-0.09718, 0], [-0.10003, 0], [-0.10266, 0], [-0.10404, 0], [-0.10518, 0], [-0.10526, 0], [-0.1089, 0], [-0.11124, 0], [-0.11235, 0], [-0.11784, 0], [-0.11967, 0], [-0.12029, 0], [-0.12846, 0], [-0.13227, 0], [-0.13602, 0], [-0.13858, 0], [-0.13917, 0], [-0.1399, 0], [-0.16478, 0], [-0.16775, 0], [-0.17174, 0], [-0.18113, 0], [-0.18237, 0], [-0.20097, 0], [-0.20655, 0], [-0.23235, 0], [-0.23406, 0], [-0.23451, 0]], "threshold": -3.0, "persistence": 2, "drop": 0.25, "max_step": 48, "model": "CohereLabs/tiny-aya-global", "asr_before": "21 %", "asr_unprotected": "94 %", "asr_brink": "21 %"};</script> | |
| <script> | |
| (function () { | |
| var D = window.BRINK_DEMO; | |
| var NS = "http://www.w3.org/2000/svg"; | |
| function el(name, attrs, text) { | |
| var e = document.createElementNS(NS, name); | |
| for (var k in attrs) e.setAttribute(k, attrs[k]); | |
| if (text !== undefined) e.textContent = text; | |
| return e; | |
| } | |
| function css(name) { return getComputedStyle(document.documentElement).getPropertyValue(name).trim(); } | |
| function firstAlarm(steps, z, thr, persist) { | |
| var run = 0; | |
| for (var i = 0; i < z.length; i++) { | |
| run = z[i] <= thr ? run + 1 : 0; | |
| if (run >= persist) return steps[i]; | |
| } | |
| return null; | |
| } | |
| document.querySelectorAll(".copy").forEach(function (b) { | |
| b.addEventListener("click", function () { | |
| var text = b.parentNode.querySelector("pre").textContent; | |
| navigator.clipboard.writeText(text).then(function () { | |
| b.textContent = "Copied"; | |
| setTimeout(function () { b.textContent = "Copy"; }, 1400); | |
| }); | |
| }); | |
| }); | |
| if (!D) return; | |
| function drawAlarm() { | |
| var svg = document.getElementById("alarm-chart"); | |
| var thr = parseFloat(document.getElementById("thr").value); | |
| var persist = parseInt(document.getElementById("persist").value, 10); | |
| document.getElementById("thr-out").textContent = thr.toFixed(1); | |
| var W = 960, H = 340, L = 52, R = 110, T = 16, B = 40; | |
| var all = D.unprotected.z.concat(D.brink.z); | |
| var lo = Math.min.apply(null, all.concat([thr])) - 2, hi = Math.max.apply(null, all) + 2; | |
| var maxStep = Math.max.apply(null, D.unprotected.steps.concat(D.brink.steps)); | |
| function x(s) { return L + (W - L - R) * s / maxStep; } | |
| function y(v) { return T + (H - T - B) * (hi - v) / (hi - lo); } | |
| while (svg.firstChild) svg.removeChild(svg.firstChild); | |
| var line = css("--line"), muted = css("--muted"), brand = css("--brand"); | |
| for (var g = Math.ceil(lo / 10) * 10; g <= hi; g += 10) { | |
| svg.appendChild(el("line", { x1: L, x2: W - R, y1: y(g), y2: y(g), stroke: line })); | |
| svg.appendChild(el("text", { x: L - 8, y: y(g) + 4, "text-anchor": "end", fill: muted, "font-size": 12 }, g)); | |
| } | |
| D.unprotected.steps.forEach(function (s) { | |
| if (s % 8 === 0) { | |
| svg.appendChild(el("text", { x: x(s), y: H - B + 18, "text-anchor": "middle", fill: muted, | |
| "font-size": 12 }, s)); | |
| } | |
| }); | |
| svg.appendChild(el("text", { x: (L + W - R) / 2, y: H - 4, "text-anchor": "middle", fill: muted, | |
| "font-size": 12 }, "training step")); | |
| svg.appendChild(el("line", { x1: L, x2: W - R, y1: y(thr), y2: y(thr), stroke: muted, | |
| "stroke-dasharray": "6 5" })); | |
| svg.appendChild(el("text", { x: W - R + 6, y: y(thr) + 4, fill: muted, "font-size": 12 }, "alarm line")); | |
| var out = []; | |
| [["unprotected", css("--bad"), "Unprotected"], ["brink", brand, "With Brink"]].forEach(function (c) { | |
| var s = D[c[0]], pts = s.steps.map(function (st, i) { return x(st) + "," + y(s.z[i]); }).join(" "); | |
| svg.appendChild(el("polyline", { points: pts, fill: "none", stroke: c[1], "stroke-width": 2.5 })); | |
| s.steps.forEach(function (st, i) { | |
| svg.appendChild(el("circle", { cx: x(st), cy: y(s.z[i]), r: 3, fill: c[1] })); | |
| }); | |
| var a = firstAlarm(s.steps, s.z, thr, persist); | |
| if (a !== null) { | |
| svg.appendChild(el("line", { x1: x(a), x2: x(a), y1: T, y2: H - B, stroke: c[1], "stroke-width": 1.5 })); | |
| svg.appendChild(el("text", { x: x(a) + 5, y: T + 12 + (c[0] === "brink" ? 16 : 0), fill: c[1], | |
| "font-size": 12 }, c[2] + ": alarm at step " + a)); | |
| } | |
| out.push([c[2], a]); | |
| }); | |
| var u = out[0][1], b = out[1][1], msg; | |
| if (u === null) { | |
| msg = "With this rule the alarm never fires on the unprotected run, and the model ends up answering " + | |
| D.asr_unprotected + " of harmful prompts. The line is too low."; | |
| } else { | |
| msg = "The alarm fires at step " + u + " of " + D.max_step + " on the unprotected run, which ended at " + | |
| D.asr_unprotected + " attack success. "; | |
| msg += b === null | |
| ? "It stays quiet on the Brink run, which ended at " + D.asr_brink + "." | |
| : "It also fires on the Brink run at step " + b + ", where the model was still safe (" + D.asr_brink + | |
| "): a false alarm. The line is too sensitive."; | |
| } | |
| document.getElementById("alarm-verdict").textContent = msg; | |
| } | |
| function drawGate() { | |
| var svg = document.getElementById("gate-chart"); | |
| var frac = parseFloat(document.getElementById("drop").value); | |
| var n = D.gate.length, k = Math.round(frac * n); | |
| document.getElementById("drop-out").textContent = Math.round(frac * 100) + " %"; | |
| var W = 960, H = 220, L = 52, R = 16, T = 12, B = 30; | |
| var scores = D.gate.map(function (g) { return g[0]; }); | |
| var hi = Math.max.apply(null, scores), lo = Math.min.apply(null, scores.concat([0])); | |
| function y(v) { return T + (H - T - B) * (hi - v) / (hi - lo); } | |
| var bw = (W - L - R) / n; | |
| while (svg.firstChild) svg.removeChild(svg.firstChild); | |
| var bad = css("--bad"), good = css("--good"), muted = css("--muted"), line = css("--line"); | |
| if (k > 0) { | |
| svg.appendChild(el("rect", { x: L, y: T, width: bw * k, height: H - T - B, fill: line, opacity: 0.55 })); | |
| svg.appendChild(el("text", { x: L + 6, y: H - B - 8, fill: muted, "font-size": 12 }, "dropped by the gate")); | |
| } | |
| svg.appendChild(el("line", { x1: L, x2: W - R, y1: y(0), y2: y(0), stroke: muted })); | |
| svg.appendChild(el("text", { x: L - 8, y: y(0) + 4, "text-anchor": "end", fill: muted, "font-size": 12 }, "0")); | |
| svg.appendChild(el("text", { x: L - 8, y: y(hi) + 10, "text-anchor": "end", fill: muted, "font-size": 12 }, | |
| hi.toFixed(2))); | |
| var caught = 0, benign = 0, total = 0; | |
| D.gate.forEach(function (g, i) { | |
| var top = Math.min(y(g[0]), y(0)), h = Math.max(Math.abs(y(g[0]) - y(0)), 1); | |
| svg.appendChild(el("rect", { x: L + bw * i + 0.5, y: top, width: Math.max(bw - 1, 1), height: h, | |
| fill: g[1] ? bad : good })); | |
| total += g[1]; | |
| if (i < k) { if (g[1]) caught++; else benign++; } | |
| }); | |
| svg.appendChild(el("text", { x: (L + W - R) / 2, y: H - 6, "text-anchor": "middle", fill: muted, | |
| "font-size": 12 }, "training samples, riskiest first")); | |
| document.getElementById("gate-verdict").textContent = k === 0 | |
| ? "Nothing dropped: all " + total + " harmful samples go into training." | |
| : "Dropping the riskiest " + k + " of " + n + " samples removes " + caught + " of the " + total + | |
| " harmful ones and costs " + benign + " benign sample" + (benign === 1 ? "" : "s") + ". Dropping " + k + | |
| " at random would remove about " + Math.round(k * total / n) + "."; | |
| } | |
| ["thr", "persist"].forEach(function (id) { document.getElementById(id).addEventListener("input", drawAlarm); }); | |
| document.getElementById("drop").addEventListener("input", drawGate); | |
| if (window.matchMedia) { | |
| window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", function () { | |
| drawAlarm(); drawGate(); | |
| }); | |
| } | |
| drawAlarm(); drawGate(); | |
| })(); | |
| </script> | |
| </body> | |
| </html> | |