Spaces:
Running
Running
Download index.html from zyplai/stabilization-uplift: direct link, hf CLI and curl.
- Browser
- Download file 13.2 kB
-
https://huggingface.co/spaces/zyplai/stabilization-uplift/resolve/main/index.html
- Command line
-
hf download hf://spaces/zyplai/stabilization-uplift/index.html
-
curl -L -o index.html https://huggingface.co/spaces/zyplai/stabilization-uplift/resolve/main/index.html
13.2 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="utf-8"> | |
| <meta name="viewport" content="width=device-width, initial-scale=1"> | |
| <title>Stabilization Uplift</title> | |
| <style> | |
| :root { | |
| --bg: #ffffff; | |
| --surface: #f6f7f9; | |
| --border: #dfe2e7; | |
| --text: #1d2330; | |
| --muted: #5d6675; | |
| --accent: #2563eb; | |
| --good: #15803d; | |
| --neutral: #92400e; | |
| --code-bg: #f1f3f6; | |
| } | |
| @media (prefers-color-scheme: dark) { | |
| :root { | |
| --bg: #12151b; | |
| --surface: #1b1f27; | |
| --border: #2e3440; | |
| --text: #e6e9ef; | |
| --muted: #9aa3b2; | |
| --accent: #6b9bff; | |
| --good: #4ade80; | |
| --neutral: #fbbf24; | |
| --code-bg: #1f242d; | |
| } | |
| } | |
| * { box-sizing: border-box; } | |
| body { | |
| margin: 0; | |
| background: var(--bg); | |
| color: var(--text); | |
| font: 16px/1.55 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; | |
| } | |
| main { max-width: 880px; margin: 0 auto; padding: 32px 16px 64px; } | |
| h1 { font-size: 1.9rem; margin: 0 0 8px; } | |
| h2 { font-size: 1.25rem; margin: 40px 0 12px; } | |
| p { margin: 0 0 12px; } | |
| a { color: var(--accent); } | |
| .lead { color: var(--muted); } | |
| .links { display: flex; flex-wrap: wrap; gap: 8px 16px; margin: 16px 0 8px; font-size: .95rem; } | |
| .defs { margin: 16px 0 0; padding-left: 20px; } | |
| .defs li { margin-bottom: 6px; } | |
| .card { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; padding: 20px; } | |
| .models { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; } | |
| .model h3 { font-size: 1rem; margin: 0 0 10px; } | |
| .model h3 span { color: var(--muted); font-weight: normal; } | |
| label { display: block; font-size: .9rem; color: var(--muted); margin: 8px 0 4px; } | |
| input[type=number] { | |
| width: 100%; padding: 8px 10px; font: inherit; color: var(--text); | |
| background: var(--bg); border: 1px solid var(--border); border-radius: 8px; | |
| } | |
| input[type=number]:focus { outline: 2px solid var(--accent); outline-offset: 1px; } | |
| .shift { margin-top: 16px; } | |
| .shift-row { display: flex; gap: 12px; align-items: center; } | |
| .shift-row input[type=range] { flex: 1; accent-color: var(--accent); } | |
| .shift-row input[type=number] { width: 110px; } | |
| .hint { font-size: .85rem; color: var(--muted); margin-top: 4px; } | |
| .results { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; margin-top: 20px; } | |
| .metric { background: var(--bg); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; } | |
| .metric .name { font-size: .85rem; color: var(--muted); } | |
| .metric .value { font-size: 1.6rem; font-weight: 600; font-variant-numeric: tabular-nums; } | |
| .metric.su .value.pos { color: var(--good); } | |
| .metric.su .value.zero { color: var(--neutral); } | |
| .explain { margin: 16px 0 0; padding-left: 20px; } | |
| .explain li { margin-bottom: 4px; } | |
| .error { color: #dc2626; margin-top: 12px; display: none; } | |
| .scenarios { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 16px; } | |
| .scenarios button { | |
| font: inherit; font-size: .85rem; padding: 6px 10px; cursor: pointer; color: var(--text); | |
| background: var(--bg); border: 1px solid var(--border); border-radius: 999px; | |
| } | |
| .scenarios button:hover { border-color: var(--accent); } | |
| pre { | |
| background: var(--code-bg); border: 1px solid var(--border); border-radius: 8px; | |
| padding: 12px 14px; overflow-x: auto; font-size: .88rem; line-height: 1.45; | |
| } | |
| code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; } | |
| p code, li code { background: var(--code-bg); padding: 1px 5px; border-radius: 4px; font-size: .9em; } | |
| footer { margin-top: 48px; color: var(--muted); font-size: .9rem; } | |
| @media (max-width: 640px) { | |
| .models, .results { grid-template-columns: 1fr; } | |
| } | |
| </style> | |
| </head> | |
| <body> | |
| <main> | |
| <h1>Stabilization Uplift</h1> | |
| <p class="lead">Metrics for evaluating how stable a classifier stays under a sudden distribution shift, such as a macroeconomic shock.</p> | |
| <ul class="defs"> | |
| <li><strong>Stabilization Score (SS)</strong>: how much one model's ROC AUC changed between the base (pre-shock) and shock periods, relative to the severity of the shift. In [0.5, 1]; 1 means no change.</li> | |
| <li><strong>Stabilization Uplift (SU)</strong>: whether model B (e.g. trained with synthetic outliers) is more stable <em>and</em> not worse than model A (a baseline) under the shock. In [0, 1); 0 means no uplift.</li> | |
| </ul> | |
| <div class="links"> | |
| <a href="https://openreview.net/forum?id=zfTaFD0B5Z">Paper (NeurIPS 2025 GenAI in Finance Workshop)</a> | |
| <a href="https://arxiv.org/abs/2510.09294">arXiv</a> | |
| <a href="https://pypi.org/project/stabilization-uplift/">PyPI package</a> | |
| <a href="https://huggingface.co/datasets/zyplai/stabilization-uplift">Dataset</a> | |
| <a href="https://github.com/zypl-ai/stabilization_uplift">Code</a> | |
| </div> | |
| <h2>Calculator</h2> | |
| <div class="card"> | |
| <div class="models"> | |
| <div class="model"> | |
| <h3>Model A <span>(baseline)</span></h3> | |
| <label for="auc_base_A">ROC AUC on base test set</label> | |
| <input id="auc_base_A" type="number" min="0.0001" max="1" step="0.001" value="0.80"> | |
| <label for="auc_shock_A">ROC AUC on shock test set</label> | |
| <input id="auc_shock_A" type="number" min="0.0001" max="1" step="0.001" value="0.70"> | |
| </div> | |
| <div class="model"> | |
| <h3>Model B <span>(e.g. with synthetic outliers)</span></h3> | |
| <label for="auc_base_B">ROC AUC on base test set</label> | |
| <input id="auc_base_B" type="number" min="0.0001" max="1" step="0.001" value="0.80"> | |
| <label for="auc_shock_B">ROC AUC on shock test set</label> | |
| <input id="auc_shock_B" type="number" min="0.0001" max="1" step="0.001" value="0.81"> | |
| </div> | |
| </div> | |
| <div class="shift"> | |
| <label for="dist_shift">Distribution shift between base and shock data</label> | |
| <div class="shift-row"> | |
| <input id="dist_shift_range" type="range" min="0" max="1" step="0.001" value="0.2" aria-label="Distribution shift slider"> | |
| <input id="dist_shift" type="number" min="0" max="1" step="0.001" value="0.2"> | |
| </div> | |
| <div class="hint">Compute it from data with <code>stabilization_uplift.distribution_shift</code> (<code>pip install "stabilization-uplift[shift]"</code>).</div> | |
| </div> | |
| <div class="results" aria-live="polite"> | |
| <div class="metric"><div class="name">SS of model A</div><div class="value" id="ss_A">–</div></div> | |
| <div class="metric"><div class="name">SS of model B</div><div class="value" id="ss_B">–</div></div> | |
| <div class="metric su"><div class="name">SU of B over A</div><div class="value" id="su">–</div></div> | |
| </div> | |
| <div class="error" id="error"></div> | |
| <ul class="explain" id="explain"></ul> | |
| <div class="scenarios" id="scenarios"></div> | |
| </div> | |
| <h2>Use in code</h2> | |
| <p>Python package (<a href="https://pypi.org/project/stabilization-uplift/">PyPI</a>), with an end-to-end example on the <a href="https://huggingface.co/datasets/zyplai/stabilization-uplift">dataset</a> and the API reference on its page:</p> | |
| <pre><code>pip install stabilization-uplift # SS and SU | |
| pip install "stabilization-uplift[shift]" # + distribution_shift computed from data</code></pre> | |
| <pre><code>from stabilization_uplift import stabilization_score, stabilization_uplift | |
| stabilization_score(auc_base=0.80, auc_shock=0.70, dist_shift=0.2) # 0.915 | |
| stabilization_uplift(auc_base_A=0.80, auc_shock_A=0.70, | |
| auc_base_B=0.80, auc_shock_B=0.81, dist_shift=0.2) # 0.725</code></pre> | |
| <p>Hugging Face <code>evaluate</code> (this Space is also an <code>evaluate</code> module):</p> | |
| <pre><code>pip install evaluate stabilization-uplift</code></pre> | |
| <pre><code>import evaluate | |
| metric = evaluate.load("zyplai/stabilization-uplift") | |
| metric.compute(auc_base_A=[0.80], auc_shock_A=[0.70], | |
| auc_base_B=[0.80], auc_shock_B=[0.81], dist_shift=[0.2]) | |
| # {'stabilization_score_A': [0.915...], 'stabilization_score_B': [0.992...], 'stabilization_uplift': [0.725...]}</code></pre> | |
| <p>Each row is one comparison of model B with model A, so several comparisons can be computed in one call.</p> | |
| <footer> | |
| Varshavskiy et al., <em>Mitigating Model Drift in Developing Economies Using Synthetic Data and Outliers</em>, NeurIPS 2025 Workshop on Generative AI in Finance. | |
| Author: <a href="https://zypl.ai">zypl.ai</a>. MIT License. | |
| </footer> | |
| </main> | |
| <script> | |
| // Port of the stabilization-uplift Python package (stabilization_uplift/metrics.py, v0.1.2). | |
| // Keep in sync with the package; the reference implementation is the Python one. | |
| const EPSILON = 1e-5, K = 100, K_SHOCK = 1000; | |
| function sigmoidWeight(x, k) { return 1 - 1 / (1 + Math.exp(k * x)); } | |
| function symmetricAuc(auc, name) { | |
| if (!(auc > 0 && auc <= 1)) throw new Error(`${name} should be in (0, 1], got ${auc}`); | |
| return auc < 0.5 ? 1 - auc : auc; | |
| } | |
| function stabilizationScore(aucBase, aucShock, distShift) { | |
| aucBase = symmetricAuc(aucBase, "auc_base"); | |
| aucShock = symmetricAuc(aucShock, "auc_shock"); | |
| const shiftVal = Math.max(1 + Math.log(1 + distShift + EPSILON), EPSILON); | |
| return 1 - Math.abs(aucBase - aucShock) / shiftVal; | |
| } | |
| function stabilizationUplift(aucBaseA, aucShockA, aucBaseB, aucShockB, distShift) { | |
| aucBaseA = symmetricAuc(aucBaseA, "auc_base_A"); | |
| aucShockA = symmetricAuc(aucShockA, "auc_shock_A"); | |
| aucBaseB = symmetricAuc(aucBaseB, "auc_base_B"); | |
| aucShockB = symmetricAuc(aucShockB, "auc_shock_B"); | |
| let wA = sigmoidWeight(aucShockA - aucBaseA, K); | |
| let wB = sigmoidWeight(aucShockB - aucBaseB, K); | |
| const w = sigmoidWeight(aucShockB - aucShockA, K_SHOCK); | |
| const wSuperiority = sigmoidWeight((aucBaseB - aucBaseA) + (aucShockB - aucShockA), K); | |
| wB = wB * wSuperiority; | |
| wA = wA * (1 - wSuperiority); | |
| const scoreA = stabilizationScore(aucBaseA, aucShockA, distShift); | |
| const scoreB = stabilizationScore(aucBaseB, aucShockB, distShift); | |
| const uplift = w * (wB * scoreB - wA * scoreA); | |
| return uplift > 0 ? uplift : 0; | |
| } | |
| window.stabilizationScore = stabilizationScore; | |
| window.stabilizationUplift = stabilizationUplift; | |
| const SCENARIOS = [ | |
| ["B improves under the shock", [0.80, 0.70, 0.80, 0.81, 0.2]], | |
| ["B stays flat", [0.80, 0.79, 0.80, 0.80, 0.2]], | |
| ["B drops less than A", [0.80, 0.70, 0.81, 0.78, 0.2]], | |
| ["Both drop equally", [0.80, 0.70, 0.80, 0.70, 0.2]], | |
| ["B is worse than A", [0.81, 0.78, 0.80, 0.70, 0.2]], | |
| ]; | |
| const IDS = ["auc_base_A", "auc_shock_A", "auc_base_B", "auc_shock_B", "dist_shift"]; | |
| const $ = (id) => document.getElementById(id); | |
| function change(base, shock) { | |
| const d = shock - base; | |
| if (d > 0) return `rose by ${d.toFixed(3)}`; | |
| if (d < 0) return `dropped by ${(-d).toFixed(3)}`; | |
| return "did not change"; | |
| } | |
| function explain(baseA, shockA, baseB, shockB, su) { | |
| const items = [ | |
| `Under the shock, the AUC of model A ${change(baseA, shockA)} and the AUC of model B ${change(baseB, shockB)}.`, | |
| shockB > shockA | |
| ? `Under the shock, B is better than A (${shockB.toFixed(3)} vs ${shockA.toFixed(3)}).` | |
| : `Under the shock, B is not better than A (${shockB.toFixed(3)} vs ${shockA.toFixed(3)}).`, | |
| ]; | |
| if (su === 0) items.push("<strong>SU = 0: no stabilization uplift of B over A.</strong>"); | |
| else if (shockB < baseB) items.push(`<strong>SU = ${su.toFixed(3)}.</strong> B's AUC still dropped under the shock, and SU mainly rewards a model whose AUC does not decrease, so the uplift is small.`); | |
| else items.push(`<strong>SU = ${su.toFixed(3)}: B held up under the shock while beating A, a stabilization uplift.</strong>`); | |
| return items.map((t) => `<li>${t}</li>`).join(""); | |
| } | |
| function update() { | |
| const v = IDS.map((id) => parseFloat($(id).value)); | |
| const err = $("error"); | |
| try { | |
| if (v.some(Number.isNaN)) throw new Error("Fill in all values."); | |
| const ssA = stabilizationScore(v[0], v[1], v[4]); | |
| const ssB = stabilizationScore(v[2], v[3], v[4]); | |
| const su = stabilizationUplift(...v); | |
| $("ss_A").textContent = ssA.toFixed(4); | |
| $("ss_B").textContent = ssB.toFixed(4); | |
| $("su").textContent = su.toFixed(4); | |
| $("su").className = "value " + (su > 0 ? "pos" : "zero"); | |
| // The metrics treat an AUC below 0.5 as 1 - AUC; explain in the same terms | |
| const aucs = v.slice(0, 4).map((a) => Math.max(a, 1 - a)); | |
| $("explain").innerHTML = explain(...aucs, su); | |
| err.style.display = "none"; | |
| } catch (e) { | |
| ["ss_A", "ss_B", "su"].forEach((id) => ($(id).textContent = "–")); | |
| $("explain").innerHTML = ""; | |
| err.textContent = e.message; | |
| err.style.display = "block"; | |
| } | |
| } | |
| IDS.forEach((id) => $(id).addEventListener("input", () => { | |
| if (id === "dist_shift") $("dist_shift_range").value = $(id).value; | |
| update(); | |
| })); | |
| $("dist_shift_range").addEventListener("input", (e) => { $("dist_shift").value = e.target.value; update(); }); | |
| SCENARIOS.forEach(([label, values]) => { | |
| const b = document.createElement("button"); | |
| b.type = "button"; | |
| b.textContent = label; | |
| b.addEventListener("click", () => { | |
| IDS.forEach((id, i) => ($(id).value = values[i])); | |
| $("dist_shift_range").value = values[4]; | |
| update(); | |
| }); | |
| $("scenarios").appendChild(b); | |
| }); | |
| update(); | |
| </script> | |
| </body> | |
| </html> | |