Spaces:
Running on Zero
Running on Zero
Download workbench/tasks.js from thirteen7/Critique-then-Rerank-ZeroGPU: direct link, hf CLI and curl.
- Browser
- Download file 11.4 kB
-
https://huggingface.co/spaces/thirteen7/Critique-then-Rerank-ZeroGPU/resolve/main/workbench/tasks.js
- Command line
-
hf download hf://spaces/thirteen7/Critique-then-Rerank-ZeroGPU/workbench/tasks.js
-
curl -L -o tasks.js https://huggingface.co/spaces/thirteen7/Critique-then-Rerank-ZeroGPU/resolve/main/workbench/tasks.js
11.4 kB
| export const tasks = [ | |
| {label: ['Change state','变化状态'], protocol: [['T₁ + T₂','T₁ + T₂'], ['Changed / Unchanged','有变化 / 无变化'], ['Stage 1 warm-start','第一阶段预热']]}, | |
| {label: ['Caption verification','描述核验'], protocol: [['T₁ + T₂ + fixed caption','双图 + 固定描述'], ['Yes / No','支持 / 不支持'], ['Stage 2 verification','第二阶段事实核验']]}, | |
| {label: ['Pairwise preference','成对偏好'], protocol: [['T₁ + T₂ + A/B','双图 + A/B'], ['A / B','A / B'], ['Stage 1 auxiliary task','第一阶段辅助任务']]}, | |
| {label: ['Listwise selection','列表选句'], protocol: [['T₁ + T₂ + candidate pool','双图 + 候选池'], ['One caption','一条描述'], ['Stage 1 and Stage 2 inference','两阶段正式推理']]}, | |
| ]; | |
| const motions = new WeakMap(); | |
| export function moveCards(list, cards, update) { | |
| const animate = !matchMedia('(prefers-reduced-motion: reduce)').matches && list.getClientRects().length > 0 && typeof list.animate === 'function'; | |
| const before = animate ? cards.map(card => card.getBoundingClientRect().top) : []; | |
| cards.forEach((card, index) => { | |
| motions.get(card)?.cancel(); | |
| const reference = list.children[index]; | |
| if (reference !== card) { | |
| if (list.moveBefore) list.moveBefore(card, reference); | |
| else list.insertBefore(card, reference); | |
| } | |
| update(card, index); | |
| }); | |
| if (!animate) return; | |
| const easing = getComputedStyle(list).getPropertyValue('--rank-settle').trim() || 'ease-out'; | |
| cards.forEach((card, index) => { | |
| const distance = before[index] - card.getBoundingClientRect().top; | |
| if (Math.abs(distance) <= 1) return; | |
| const duration = Math.min(510, 300 + Math.sqrt(Math.abs(distance)) * 10); | |
| motions.set(card, card.animate([{transform:`translateY(${distance}px)`}, {transform:'none'}], {duration, easing})); | |
| }); | |
| } | |
| export function renderProbes({byId, text, evidence, pair, escape, catalog}) { | |
| let conflict = false, reversed = false, visualRank = false; | |
| const state = byId('state-probe'), verify = byId('probe'), pairwise = byId('aux-probe'), listwise = byId('list-probe'); | |
| const evidenceDeck = byId('verify-images'); | |
| const verifyCases = ['000325','000400'].map(id => catalog.task_pairs[id]); | |
| const lists = catalog.task_pairs['001639']; | |
| const heading = (tag, title) => `<p class="micro probe-kicker">${tag}</p><h3 class="probe-question">${title}</h3>`; | |
| const protocol = index => `<dl class="protocol">${[[text('Input','输入'),0],[text('Output','输出'),1],[text('Role','用途'),2]].map(([title, position]) => `<div><dt>${title}</dt><dd>${text(...tasks[index].protocol[position])}</dd></div>`).join('')}</dl>`; | |
| const metric = (title, value, note) => `<div class="probe-stat"><div><small>${title}</small><strong>${value}</strong></div><span>${note}</span></div>`; | |
| const toggles = (name, first, second) => `<div class="view-mode probe-switches" role="group" aria-label="${name}"><button type="button" data-choice="0">${first}</button><button type="button" data-choice="1">${second}</button></div>`; | |
| const press = (container, choice) => container.querySelectorAll('[data-choice]').forEach(button => button.setAttribute('aria-pressed', Boolean(Number(button.dataset.choice)) === choice)); | |
| const say = message => { byId('task-announcement').textContent = message; }; | |
| const card = (id, caption) => `<li class="probe-beam" data-card="${id}"><code></code><strong></strong><p lang="en">${escape(caption)}</p></li>`; | |
| function updateVerification(announce) { | |
| press(verify, conflict); | |
| evidenceDeck.querySelectorAll('.evidence-layer').forEach((layer, index) => { | |
| const active = index === Number(conflict); | |
| layer.dataset.active = active; | |
| layer.setAttribute('aria-hidden', !active); | |
| }); | |
| evidenceDeck.querySelector('figcaption').textContent = `LEVIR-CC · ${verifyCases[Number(conflict)].name.replace(/\.png$/u, '')}`; | |
| const display = verify.querySelector('.verify-meter'); | |
| const value = conflict ? '<0.1%' : '>99.9%'; | |
| const decision = conflict ? text('No','不支持') : text('Yes','支持'); | |
| display.dataset.conflict = conflict; | |
| display.style.setProperty('--likelihood', conflict ? '0.001' : '0.999'); | |
| display.querySelector('strong').textContent = value; | |
| display.querySelector('b').textContent = decision; | |
| if (announce) say(`${decision} · P(Yes) ${value}`); | |
| } | |
| function updatePair(announce) { | |
| const list = pairwise.querySelector('ol'); | |
| const cards = ['houses','unchanged'].map(id => list.querySelector(`[data-card="${id}"]`)); | |
| moveCards(list, reversed ? cards.reverse() : cards, (item, index) => { | |
| const preferred = item.dataset.card === 'houses'; | |
| item.classList.toggle('probe-picked', preferred); | |
| item.querySelector('code').textContent = index === 0 ? 'A' : 'B'; | |
| item.querySelector('strong').textContent = reversed ? preferred ? '91.5%' : '8.5%' : preferred ? '96.9%' : '3.1%'; | |
| }); | |
| pairwise.querySelector('[data-reverse]').setAttribute('aria-pressed', reversed); | |
| pairwise.querySelector('.order-comparison').dataset.reversed = reversed; | |
| if (announce) say(`${reversed ? 'B · 91.5%' : 'A · 96.9%'} · ${cards.find(item => item.dataset.card === 'houses').querySelector('p').textContent}`); | |
| } | |
| function updateList(announce) { | |
| press(listwise, visualRank); | |
| const list = listwise.querySelector('ol'); | |
| const key = visualRank ? 'stage2' : 'generator'; | |
| const sorted = [...lists.candidates].sort((first, second) => second[key] - first[key]); | |
| moveCards(list, sorted.map(item => list.querySelector(`[data-card="${item.beam}"]`)), (item, index) => { | |
| const position = sorted[index]; | |
| item.classList.toggle('probe-picked', index === 0); | |
| item.querySelector('code').textContent = `${index + 1} / BEAM #${String(position.beam).padStart(2, '0')}`; | |
| item.querySelector('strong').textContent = `${(position[key] * 100).toFixed(1)}%`; | |
| }); | |
| const action = listwise.querySelector('[data-apply]'); | |
| action.textContent = visualRank ? text('Restore generator ranking','恢复生成器排序') : text('Apply visual reranking','应用视觉重排'); | |
| listwise.querySelector('.list-score-type').textContent = visualRank ? text('Stage 2 probability','第二阶段选项概率') : text('Generator likelihood share','生成器似然份额'); | |
| if (announce) say(text(`Beam #${String(sorted[0].beam).padStart(2, '0')} ranks first.`, `Beam #${String(sorted[0].beam).padStart(2, '0')} 排名第一。`)); | |
| } | |
| verify.addEventListener('click', event => { | |
| const button = event.target.closest('[data-choice]'); | |
| if (!button || Boolean(Number(button.dataset.choice)) === conflict) return; | |
| conflict = !conflict; | |
| updateVerification(true); | |
| }); | |
| pairwise.addEventListener('click', event => { | |
| if (!event.target.closest('[data-reverse]')) return; | |
| reversed = !reversed; | |
| updatePair(true); | |
| }); | |
| listwise.addEventListener('click', event => { | |
| const choice = event.target.closest('[data-choice]'); | |
| const action = event.target.closest('[data-apply]'); | |
| if (!choice && !action) return; | |
| visualRank = action ? !visualRank : Boolean(Number(choice.dataset.choice)); | |
| updateList(true); | |
| }); | |
| return () => { | |
| byId('state-images').innerHTML = evidence(catalog.cases.find(item => item.name === 'test_000033.png')); | |
| state.innerHTML = `${heading(text('01 / IMAGE-ONLY DECISION','01 / 仅双图判断'), text('Did the scene physically change?','场景本身发生变化了吗?'))} | |
| <div class="state-scale"><div class="state-values"><div><span>${text('Changed','有变化')}</span><strong>7.6%</strong></div><div><span>${text('Unchanged','无变化')}</span><strong>92.4%</strong></div></div> | |
| <div class="state-axis" aria-hidden="true"><i></i><i></i></div><div class="state-tags"><span>${text('Physical change','实质变化')}</span><span>${text('Appearance-only differences','仅外观差异')}</span></div></div> | |
| ${metric(text('STAGE 1 WARM-START PROBE','第一阶段预热任务'), '90.35%', text('Balanced accuracy · 1,929 pairs','平衡准确率 · 1,929 对影像'))}${protocol(0)}`; | |
| evidenceDeck.innerHTML = `<figure class="task-evidence"><span class="micro">${text('VISUAL EVIDENCE','影像证据')}</span><div class="evidence-stack">${verifyCases.map(item => `<div class="evidence-layer">${pair(item)}</div>`).join('')}</div><figcaption class="fine"></figcaption></figure>`; | |
| verify.innerHTML = `${heading(text('02 / FIXED-TEXT IMAGE-SWAP PROBE','02 / 固定描述,替换双图'), text('Same caption. Different evidence.','同一句描述,换一组影像。'))} | |
| <blockquote lang="en" class="fixed-caption"><small lang="${text('en','zh-CN')}">${text('CAPTION REMAINS FIXED','固定描述')}</small>houses are built along the road and some brushwoods disappear</blockquote> | |
| ${toggles(text('Image evidence','影像证据'),text('Supporting pair','支持描述的影像'),text('Conflicting pair','与描述冲突的影像'))} | |
| <div class="verify-meter"><div><small>${text('VISUAL SUPPORT · P(YES)','影像支持度 · P(YES)')}</small><b></b></div><strong></strong><div class="prob-track" aria-hidden="true"><i></i></div></div> | |
| ${metric(text('VERIFICATION ACCURACY','事实核验准确率'), '90.63% → 94.92%', text('Before → after Stage 2 training · 512 queries','第二阶段训练前 → 后 · 512 次查询'))}${protocol(1)}`; | |
| updateVerification(false); | |
| byId('task-images').innerHTML = evidence(catalog.task_pairs['000109']); | |
| pairwise.innerHTML = `${heading(text('03 / ORDER-SWAP PROBE','03 / 交换选项顺序'), text('Same preference, different order.','改变顺序,偏好不变。'))} | |
| <ol class="probe-card-list" role="list">${card('houses','houses are built in an open space')}${card('unchanged','no change has occurred')}</ol> | |
| <button type="button" class="probe-action" data-reverse>${text('Reverse option order','交换 A/B 顺序')} <span aria-hidden="true">⇅</span></button> | |
| <div class="order-comparison"><div><span>${text('Original order','原顺序')}</span><strong>A · 96.9%</strong></div><div><span>${text('Reversed order','交换后')}</span><strong>B · 91.5%</strong></div></div> | |
| <p class="fine">${text('Same caption selected in both presentations.','两种顺序下都选中了同一句描述。')}</p>${metric(text('PAIRWISE ACCURACY','成对偏好准确率'), '88.36%', text('3,858 presentations','3,858 次呈现'))}${protocol(2)}`; | |
| updatePair(false); | |
| if (!lists) return; | |
| byId('list-images').innerHTML = evidence(lists); | |
| listwise.innerHTML = `${heading(text('04 / LISTWISE CANDIDATE SELECTION','04 / 列表选句'), text('From likelihood to visual evidence.','从生成似然到影像证据。'))} | |
| ${toggles(text('Ranking order','排序方式'),text('Generator ranking','生成器排序'),text('Stage 2 ranking','第二阶段排序'))} | |
| <p class="micro list-score-type"></p><ol class="probe-card-list" role="list">${lists.candidates.map(item => card(item.beam, item.caption)).join('')}</ol> | |
| <button type="button" data-apply class="probe-action"></button><p class="fine">test_001639 · ${text('3 of 15 candidates shown · Stage 2 probabilities before length calibration.','展示 15 条中的 3 条 · 第二阶段概率未加句长校准。')}</p>${protocol(3)}`; | |
| updateList(false); | |
| }; | |
| } | |