Render LaTeX (KaTeX) + format CoT into readable numbered steps
Browse files- index.html +34 -8
index.html
CHANGED
|
@@ -63,11 +63,9 @@
|
|
| 63 |
display:flex;align-items:center;gap:7px}
|
| 64 |
.q{font-weight:600;margin:10px 0 2px;white-space:pre-wrap;font-size:15.5px}
|
| 65 |
.lbl{font-size:11px;color:var(--muted);font-weight:700;text-transform:uppercase;letter-spacing:.05em;margin:18px 0 7px}
|
| 66 |
-
.prev{
|
| 67 |
-
padding:
|
| 68 |
details{margin:7px 0 0} summary{cursor:pointer;color:var(--accent);font-size:13px;font-weight:600;user-select:none}
|
| 69 |
-
pre.cot{white-space:pre-wrap;background:var(--chip);border-radius:10px;padding:13px;margin:9px 0 0;
|
| 70 |
-
max-height:380px;overflow:auto;font-size:12.5px;line-height:1.55}
|
| 71 |
/* prediction stat tiles */
|
| 72 |
.tiles{display:grid;grid-template-columns:repeat(auto-fit,minmax(172px,1fr));gap:11px}
|
| 73 |
.tile{border:1px solid var(--border);border-radius:12px;padding:11px 13px;background:var(--surface)}
|
|
@@ -89,7 +87,19 @@
|
|
| 89 |
.mem pre{white-space:pre-wrap;font-size:12.5px;line-height:1.55;margin:0;max-height:300px;overflow:auto}
|
| 90 |
.foot{color:var(--muted);font-size:12.5px;margin-top:36px;border-top:1px solid var(--border);padding-top:16px}
|
| 91 |
a{color:var(--accent)}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
</style>
|
|
|
|
|
|
|
|
|
|
| 93 |
</head>
|
| 94 |
<body><div class="wrap">
|
| 95 |
<header class="hero">
|
|
@@ -143,6 +153,14 @@ const ORDER=["full_CoT","teacher","base","instruct","base-lr5e-5","instruct-lr1e
|
|
| 143 |
function esc(s){return (s||"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">");}
|
| 144 |
function dot(s){return `<span class="dot" style="background:var(${SRC[s].cvar})"></span>`;}
|
| 145 |
function stat(err){ if(err<0.15) return {v:"--st-good",g:"β"}; if(err<0.35) return {v:"--st-warn",g:"β"}; return {v:"--st-bad",g:"β"}; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
|
| 147 |
// source legend
|
| 148 |
document.getElementById("srcleg").innerHTML =
|
|
@@ -172,7 +190,9 @@ document.getElementById("exsec").insertAdjacentHTML("beforeend"," ("+DATA.exampl
|
|
| 172 |
for(const e of DATA.examples){
|
| 173 |
const V=e.value, corr=e.correct;
|
| 174 |
const cotTok=e.reprs.full_CoT&&e.reprs.full_CoT.tok?("~"+e.reprs.full_CoT.tok+" tok"):"";
|
| 175 |
-
const pfx=e.prefix||""; const
|
|
|
|
|
|
|
| 176 |
const vpillStyle = corr? "background:color-mix(in srgb,var(--st-good) 15%,transparent);color:var(--st-good)"
|
| 177 |
: "background:color-mix(in srgb,var(--st-bad) 15%,transparent);color:var(--st-bad)";
|
| 178 |
let tiles='';
|
|
@@ -188,7 +208,7 @@ for(const e of DATA.examples){
|
|
| 188 |
let mems='';
|
| 189 |
for(const s of ORDER){ if(s==="full_CoT") continue; const r=e.reprs[s]; if(!r) continue;
|
| 190 |
mems+=`<div class="mem"><h4><span class="mh">${dot(s)}${SRC[s].label}</span>`
|
| 191 |
-
+`<span class="py">VΜ ${r.pyes.toFixed(2)} Β· ~${r.tok} tok</span></h4><
|
| 192 |
}
|
| 193 |
ex.insertAdjacentHTML("beforeend",
|
| 194 |
`<div class="card">
|
|
@@ -198,13 +218,19 @@ for(const e of DATA.examples){
|
|
| 198 |
</div>
|
| 199 |
<div class="q">${esc(e.question)}</div>
|
| 200 |
<div class="lbl">Partial reasoning trace β the prefix V is computed for (${cotTok})</div>
|
| 201 |
-
<div class="prev">${
|
| 202 |
-
<details><summary>Show the full partial trace</summary><
|
| 203 |
<div class="lbl">Value prediction VΜ β read from each representation of this prefix</div>
|
| 204 |
<div class="tiles">${tiles}</div>
|
| 205 |
<div class="lbl">Mementos β compressions of the prefix above</div>
|
| 206 |
<div class="mems">${mems}</div>
|
| 207 |
</div>`);
|
| 208 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 209 |
</script>
|
| 210 |
</body></html>
|
|
|
|
| 63 |
display:flex;align-items:center;gap:7px}
|
| 64 |
.q{font-weight:600;margin:10px 0 2px;white-space:pre-wrap;font-size:15.5px}
|
| 65 |
.lbl{font-size:11px;color:var(--muted);font-weight:700;text-transform:uppercase;letter-spacing:.05em;margin:18px 0 7px}
|
| 66 |
+
.prev{background:var(--chip);border-left:3px solid var(--accent);border-radius:0 10px 10px 0;
|
| 67 |
+
padding:11px 14px;max-height:240px;overflow:auto}
|
| 68 |
details{margin:7px 0 0} summary{cursor:pointer;color:var(--accent);font-size:13px;font-weight:600;user-select:none}
|
|
|
|
|
|
|
| 69 |
/* prediction stat tiles */
|
| 70 |
.tiles{display:grid;grid-template-columns:repeat(auto-fit,minmax(172px,1fr));gap:11px}
|
| 71 |
.tile{border:1px solid var(--border);border-radius:12px;padding:11px 13px;background:var(--surface)}
|
|
|
|
| 87 |
.mem pre{white-space:pre-wrap;font-size:12.5px;line-height:1.55;margin:0;max-height:300px;overflow:auto}
|
| 88 |
.foot{color:var(--muted);font-size:12.5px;margin-top:36px;border-top:1px solid var(--border);padding-top:16px}
|
| 89 |
a{color:var(--accent)}
|
| 90 |
+
/* readable CoT / prefix: prose steps, not a monospace blob */
|
| 91 |
+
.cotwrap{background:var(--chip);border-radius:10px;padding:14px;margin:9px 0 0;max-height:460px;overflow:auto}
|
| 92 |
+
.sc{white-space:pre-wrap;font-size:13px;line-height:1.62;overflow-wrap:anywhere}
|
| 93 |
+
.step{display:flex;gap:11px;margin:0 0 13px} .step:last-child{margin-bottom:0} .step .sc{flex:1;min-width:0}
|
| 94 |
+
.sn{flex:none;width:22px;height:22px;border-radius:50%;background:var(--track);color:var(--muted);font-size:11px;
|
| 95 |
+
font-weight:700;display:flex;align-items:center;justify-content:center;font-variant-numeric:tabular-nums;margin-top:1px}
|
| 96 |
+
.prevnote{color:var(--muted);font-size:11.5px;margin:0 0 8px}
|
| 97 |
+
.memtext{white-space:pre-wrap;font-size:12.5px;line-height:1.55;margin:0;max-height:300px;overflow:auto;overflow-wrap:anywhere}
|
| 98 |
+
.katex{font-size:1.04em} .katex-display{margin:.5em 0;overflow-x:auto;overflow-y:hidden}
|
| 99 |
</style>
|
| 100 |
+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/katex@0.16.11/dist/katex.min.css" crossorigin="anonymous">
|
| 101 |
+
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.11/dist/katex.min.js" crossorigin="anonymous"></script>
|
| 102 |
+
<script defer src="https://cdn.jsdelivr.net/npm/katex@0.16.11/dist/contrib/auto-render.min.js" crossorigin="anonymous"></script>
|
| 103 |
</head>
|
| 104 |
<body><div class="wrap">
|
| 105 |
<header class="hero">
|
|
|
|
| 153 |
function esc(s){return (s||"").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">");}
|
| 154 |
function dot(s){return `<span class="dot" style="background:var(${SRC[s].cvar})"></span>`;}
|
| 155 |
function stat(err){ if(err<0.15) return {v:"--st-good",g:"β"}; if(err<0.35) return {v:"--st-warn",g:"β"}; return {v:"--st-bad",g:"β"}; }
|
| 156 |
+
function steps(txt){ return (txt||"").split(/\n\n+/).map(s=>s.replace(/\s+$/,"")).filter(s=>s.trim().length); }
|
| 157 |
+
function fmtSteps(txt){ const p=steps(txt);
|
| 158 |
+
return p.length ? p.map((s,i)=>`<div class="step"><span class="sn">${i+1}</span><div class="sc">${esc(s)}</div></div>`).join("")
|
| 159 |
+
: `<div class="sc">${esc(txt||"")}</div>`; }
|
| 160 |
+
function renderMath(el){ if(el && window.renderMathInElement){ try{ renderMathInElement(el,{delimiters:[
|
| 161 |
+
{left:"$$",right:"$$",display:true},{left:"\\[",right:"\\]",display:true},
|
| 162 |
+
{left:"$",right:"$",display:false},{left:"\\(",right:"\\)",display:false}],
|
| 163 |
+
throwOnError:false, errorColor:"var(--ink2)", ignoredClasses:["meta","ttok","tname","py"]}); }catch(e){} } }
|
| 164 |
|
| 165 |
// source legend
|
| 166 |
document.getElementById("srcleg").innerHTML =
|
|
|
|
| 190 |
for(const e of DATA.examples){
|
| 191 |
const V=e.value, corr=e.correct;
|
| 192 |
const cotTok=e.reprs.full_CoT&&e.reprs.full_CoT.tok?("~"+e.reprs.full_CoT.tok+" tok"):"";
|
| 193 |
+
const pfx=e.prefix||""; const _st=steps(pfx);
|
| 194 |
+
const prevNote=_st.length>2?`showing the last 2 of ${_st.length} steps β expand for the full trace`:"";
|
| 195 |
+
const prevHtml=(_st.slice(-2).map(s=>`<div class="sc">${esc(s)}</div>`).join(""))||`<div class="sc">${esc(pfx)}</div>`;
|
| 196 |
const vpillStyle = corr? "background:color-mix(in srgb,var(--st-good) 15%,transparent);color:var(--st-good)"
|
| 197 |
: "background:color-mix(in srgb,var(--st-bad) 15%,transparent);color:var(--st-bad)";
|
| 198 |
let tiles='';
|
|
|
|
| 208 |
let mems='';
|
| 209 |
for(const s of ORDER){ if(s==="full_CoT") continue; const r=e.reprs[s]; if(!r) continue;
|
| 210 |
mems+=`<div class="mem"><h4><span class="mh">${dot(s)}${SRC[s].label}</span>`
|
| 211 |
+
+`<span class="py">VΜ ${r.pyes.toFixed(2)} Β· ~${r.tok} tok</span></h4><div class="memtext">${esc(r.text)}</div></div>`;
|
| 212 |
}
|
| 213 |
ex.insertAdjacentHTML("beforeend",
|
| 214 |
`<div class="card">
|
|
|
|
| 218 |
</div>
|
| 219 |
<div class="q">${esc(e.question)}</div>
|
| 220 |
<div class="lbl">Partial reasoning trace β the prefix V is computed for (${cotTok})</div>
|
| 221 |
+
<div class="prev">${prevNote?('<div class="prevnote">'+prevNote+'</div>'):''}${prevHtml}</div>
|
| 222 |
+
<details><summary>Show the full partial trace</summary><div class="cotwrap">${fmtSteps(pfx)}</div></details>
|
| 223 |
<div class="lbl">Value prediction VΜ β read from each representation of this prefix</div>
|
| 224 |
<div class="tiles">${tiles}</div>
|
| 225 |
<div class="lbl">Mementos β compressions of the prefix above</div>
|
| 226 |
<div class="mems">${mems}</div>
|
| 227 |
</div>`);
|
| 228 |
}
|
| 229 |
+
// render LaTeX after KaTeX (deferred) loads; do the heavy full-CoT lazily on first expand
|
| 230 |
+
window.addEventListener("load", ()=>{
|
| 231 |
+
document.querySelectorAll(".q,.prev,.tiles,.mems,.def,.take,.legrow").forEach(renderMath);
|
| 232 |
+
document.querySelectorAll("details").forEach(d=> d.addEventListener("toggle", ()=>{
|
| 233 |
+
if(d.open && !d._rendered){ renderMath(d.querySelector(".cotwrap")); d._rendered=1; } }));
|
| 234 |
+
});
|
| 235 |
</script>
|
| 236 |
</body></html>
|